src/ZF/Bin.thy
author wenzelm
Mon, 24 Oct 2016 11:42:39 +0200
changeset 64367 a424f2737646
parent 61798 27f3c10b0b50
child 68233 5e0e9376b2b0
permissions -rw-r--r--
updated for release;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
     1
(*  Title:      ZF/Bin.thy
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
     2
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
     3
    Copyright   1994  University of Cambridge
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
     4
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
     5
   The sign Pls stands for an infinite string of leading 0's.
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
     6
   The sign Min stands for an infinite string of leading 1's.
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
     7
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
     8
A number can have multiple representations, namely leading 0's with sign
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
     9
Pls and leading 1's with sign Min.  See twos-compl.ML/int_of_binary for
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    10
the numerical interpretation.
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    11
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    12
The representation expects that (m mod 2) is 0 or 1, even if m is negative;
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    13
For instance, ~5 div 2 = ~3 and ~5 mod 2 = 1; thus ~5 = (~3)*2 + 1
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    14
*)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    15
60770
240563fbf41d isabelle update_cartouches;
wenzelm
parents: 59748
diff changeset
    16
section\<open>Arithmetic on Binary Integers\<close>
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    17
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    18
theory Bin
26056
6a0801279f4c Made theory names in ZF disjoint from HOL theory names to allow loading both developments
krauss
parents: 24893
diff changeset
    19
imports Int_ZF Datatype_ZF
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    20
begin
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    21
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    22
consts  bin :: i
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    23
datatype
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    24
  "bin" = Pls
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    25
        | Min
46953
2b6e55924af3 replacing ":" by "\<in>"
paulson
parents: 46821
diff changeset
    26
        | Bit ("w \<in> bin", "b \<in> bool")     (infixl "BIT" 90)
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    27
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    28
consts
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    29
  integ_of  :: "i=>i"
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    30
  NCons     :: "[i,i]=>i"
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    31
  bin_succ  :: "i=>i"
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    32
  bin_pred  :: "i=>i"
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    33
  bin_minus :: "i=>i"
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    34
  bin_adder :: "i=>i"
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    35
  bin_mult  :: "[i,i]=>i"
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    36
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    37
primrec
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    38
  integ_of_Pls:  "integ_of (Pls)     = $# 0"
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    39
  integ_of_Min:  "integ_of (Min)     = $-($#1)"
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    40
  integ_of_BIT:  "integ_of (w BIT b) = $#b $+ integ_of(w) $+ integ_of(w)"
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    41
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    42
    (** recall that cond(1,b,c)=b and cond(0,b,c)=0 **)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    43
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    44
primrec (*NCons adds a bit, suppressing leading 0s and 1s*)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    45
  NCons_Pls: "NCons (Pls,b)     = cond(b,Pls BIT b,Pls)"
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    46
  NCons_Min: "NCons (Min,b)     = cond(b,Min,Min BIT b)"
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    47
  NCons_BIT: "NCons (w BIT c,b) = w BIT c BIT b"
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    48
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    49
primrec (*successor.  If a BIT, can change a 0 to a 1 without recursion.*)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    50
  bin_succ_Pls:  "bin_succ (Pls)     = Pls BIT 1"
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    51
  bin_succ_Min:  "bin_succ (Min)     = Pls"
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    52
  bin_succ_BIT:  "bin_succ (w BIT b) = cond(b, bin_succ(w) BIT 0, NCons(w,1))"
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    53
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    54
primrec (*predecessor*)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    55
  bin_pred_Pls:  "bin_pred (Pls)     = Min"
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    56
  bin_pred_Min:  "bin_pred (Min)     = Min BIT 0"
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    57
  bin_pred_BIT:  "bin_pred (w BIT b) = cond(b, NCons(w,0), bin_pred(w) BIT 1)"
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    58
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    59
primrec (*unary negation*)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    60
  bin_minus_Pls:
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    61
    "bin_minus (Pls)       = Pls"
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    62
  bin_minus_Min:
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    63
    "bin_minus (Min)       = Pls BIT 1"
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    64
  bin_minus_BIT:
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    65
    "bin_minus (w BIT b) = cond(b, bin_pred(NCons(bin_minus(w),0)),
32960
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 26190
diff changeset
    66
                                bin_minus(w) BIT 0)"
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    67
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    68
primrec (*sum*)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    69
  bin_adder_Pls:
46820
c656222c4dc1 mathematical symbols instead of ASCII
paulson
parents: 45703
diff changeset
    70
    "bin_adder (Pls)     = (\<lambda>w\<in>bin. w)"
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    71
  bin_adder_Min:
46820
c656222c4dc1 mathematical symbols instead of ASCII
paulson
parents: 45703
diff changeset
    72
    "bin_adder (Min)     = (\<lambda>w\<in>bin. bin_pred(w))"
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    73
  bin_adder_BIT:
46820
c656222c4dc1 mathematical symbols instead of ASCII
paulson
parents: 45703
diff changeset
    74
    "bin_adder (v BIT x) =
c656222c4dc1 mathematical symbols instead of ASCII
paulson
parents: 45703
diff changeset
    75
       (\<lambda>w\<in>bin.
c656222c4dc1 mathematical symbols instead of ASCII
paulson
parents: 45703
diff changeset
    76
         bin_case (v BIT x, bin_pred(v BIT x),
c656222c4dc1 mathematical symbols instead of ASCII
paulson
parents: 45703
diff changeset
    77
                   %w y. NCons(bin_adder (v) ` cond(x and y, bin_succ(w), w),
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    78
                               x xor y),
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    79
                   w))"
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    80
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    81
(*The bin_case above replaces the following mutually recursive function:
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    82
primrec
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    83
  "adding (v,x,Pls)     = v BIT x"
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    84
  "adding (v,x,Min)     = bin_pred(v BIT x)"
46820
c656222c4dc1 mathematical symbols instead of ASCII
paulson
parents: 45703
diff changeset
    85
  "adding (v,x,w BIT y) = NCons(bin_adder (v, cond(x and y, bin_succ(w), w)),
32960
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 26190
diff changeset
    86
                                x xor y)"
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    87
*)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    88
24893
b8ef7afe3a6b modernized specifications;
wenzelm
parents: 23146
diff changeset
    89
definition
b8ef7afe3a6b modernized specifications;
wenzelm
parents: 23146
diff changeset
    90
  bin_add   :: "[i,i]=>i"  where
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    91
    "bin_add(v,w) == bin_adder(v)`w"
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    92
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    93
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    94
primrec
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    95
  bin_mult_Pls:
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    96
    "bin_mult (Pls,w)     = Pls"
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    97
  bin_mult_Min:
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    98
    "bin_mult (Min,w)     = bin_minus(w)"
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    99
  bin_mult_BIT:
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   100
    "bin_mult (v BIT b,w) = cond(b, bin_add(NCons(bin_mult(v,w),0),w),
32960
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 26190
diff changeset
   101
                                 NCons(bin_mult(v,w),0))"
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   102
35112
ff6f60e6ab85 numeral syntax: clarify parse trees vs. actual terms;
wenzelm
parents: 32960
diff changeset
   103
syntax
58421
37cbbd8eb460 discontinued old "xnum" token category;
wenzelm
parents: 58022
diff changeset
   104
  "_Int0" :: i  ("#()0")
37cbbd8eb460 discontinued old "xnum" token category;
wenzelm
parents: 58022
diff changeset
   105
  "_Int1" :: i  ("#()1")
37cbbd8eb460 discontinued old "xnum" token category;
wenzelm
parents: 58022
diff changeset
   106
  "_Int2" :: i  ("#()2")
37cbbd8eb460 discontinued old "xnum" token category;
wenzelm
parents: 58022
diff changeset
   107
  "_Neg_Int1" :: i  ("#-()1")
37cbbd8eb460 discontinued old "xnum" token category;
wenzelm
parents: 58022
diff changeset
   108
  "_Neg_Int2" :: i  ("#-()2")
37cbbd8eb460 discontinued old "xnum" token category;
wenzelm
parents: 58022
diff changeset
   109
translations
37cbbd8eb460 discontinued old "xnum" token category;
wenzelm
parents: 58022
diff changeset
   110
  "#0" \<rightleftharpoons> "CONST integ_of(CONST Pls)"
37cbbd8eb460 discontinued old "xnum" token category;
wenzelm
parents: 58022
diff changeset
   111
  "#1" \<rightleftharpoons> "CONST integ_of(CONST Pls BIT 1)"
37cbbd8eb460 discontinued old "xnum" token category;
wenzelm
parents: 58022
diff changeset
   112
  "#2" \<rightleftharpoons> "CONST integ_of(CONST Pls BIT 1 BIT 0)"
37cbbd8eb460 discontinued old "xnum" token category;
wenzelm
parents: 58022
diff changeset
   113
  "#-1" \<rightleftharpoons> "CONST integ_of(CONST Min)"
37cbbd8eb460 discontinued old "xnum" token category;
wenzelm
parents: 58022
diff changeset
   114
  "#-2" \<rightleftharpoons> "CONST integ_of(CONST Min BIT 0)"
37cbbd8eb460 discontinued old "xnum" token category;
wenzelm
parents: 58022
diff changeset
   115
37cbbd8eb460 discontinued old "xnum" token category;
wenzelm
parents: 58022
diff changeset
   116
syntax
37cbbd8eb460 discontinued old "xnum" token category;
wenzelm
parents: 58022
diff changeset
   117
  "_Int" :: "num_token => i"  ("#_" 1000)
37cbbd8eb460 discontinued old "xnum" token category;
wenzelm
parents: 58022
diff changeset
   118
  "_Neg_Int" :: "num_token => i"  ("#-_" 1000)
35112
ff6f60e6ab85 numeral syntax: clarify parse trees vs. actual terms;
wenzelm
parents: 32960
diff changeset
   119
48891
c0eafbd55de3 prefer ML_file over old uses;
wenzelm
parents: 46953
diff changeset
   120
ML_file "Tools/numeral_syntax.ML"
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   121
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   122
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   123
declare bin.intros [simp,TC]
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   124
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   125
lemma NCons_Pls_0: "NCons(Pls,0) = Pls"
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   126
by simp
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   127
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   128
lemma NCons_Pls_1: "NCons(Pls,1) = Pls BIT 1"
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   129
by simp
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   130
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   131
lemma NCons_Min_0: "NCons(Min,0) = Min BIT 0"
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   132
by simp
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   133
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   134
lemma NCons_Min_1: "NCons(Min,1) = Min"
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   135
by simp
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   136
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   137
lemma NCons_BIT: "NCons(w BIT x,b) = w BIT x BIT b"
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   138
by (simp add: bin.case_eqns)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   139
46820
c656222c4dc1 mathematical symbols instead of ASCII
paulson
parents: 45703
diff changeset
   140
lemmas NCons_simps [simp] =
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   141
    NCons_Pls_0 NCons_Pls_1 NCons_Min_0 NCons_Min_1 NCons_BIT
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   142
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   143
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   144
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   145
(** Type checking **)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   146
46953
2b6e55924af3 replacing ":" by "\<in>"
paulson
parents: 46821
diff changeset
   147
lemma integ_of_type [TC]: "w \<in> bin ==> integ_of(w) \<in> int"
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   148
apply (induct_tac "w")
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   149
apply (simp_all add: bool_into_nat)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   150
done
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   151
46953
2b6e55924af3 replacing ":" by "\<in>"
paulson
parents: 46821
diff changeset
   152
lemma NCons_type [TC]: "[| w \<in> bin; b \<in> bool |] ==> NCons(w,b) \<in> bin"
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   153
by (induct_tac "w", auto)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   154
46953
2b6e55924af3 replacing ":" by "\<in>"
paulson
parents: 46821
diff changeset
   155
lemma bin_succ_type [TC]: "w \<in> bin ==> bin_succ(w) \<in> bin"
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   156
by (induct_tac "w", auto)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   157
46953
2b6e55924af3 replacing ":" by "\<in>"
paulson
parents: 46821
diff changeset
   158
lemma bin_pred_type [TC]: "w \<in> bin ==> bin_pred(w) \<in> bin"
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   159
by (induct_tac "w", auto)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   160
46953
2b6e55924af3 replacing ":" by "\<in>"
paulson
parents: 46821
diff changeset
   161
lemma bin_minus_type [TC]: "w \<in> bin ==> bin_minus(w) \<in> bin"
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   162
by (induct_tac "w", auto)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   163
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   164
(*This proof is complicated by the mutual recursion*)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   165
lemma bin_add_type [rule_format,TC]:
46953
2b6e55924af3 replacing ":" by "\<in>"
paulson
parents: 46821
diff changeset
   166
     "v \<in> bin ==> \<forall>w\<in>bin. bin_add(v,w) \<in> bin"
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   167
apply (unfold bin_add_def)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   168
apply (induct_tac "v")
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   169
apply (rule_tac [3] ballI)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   170
apply (rename_tac [3] "w'")
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   171
apply (induct_tac [3] "w'")
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   172
apply (simp_all add: NCons_type)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   173
done
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   174
46953
2b6e55924af3 replacing ":" by "\<in>"
paulson
parents: 46821
diff changeset
   175
lemma bin_mult_type [TC]: "[| v \<in> bin; w \<in> bin |] ==> bin_mult(v,w) \<in> bin"
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   176
by (induct_tac "v", auto)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   177
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   178
60770
240563fbf41d isabelle update_cartouches;
wenzelm
parents: 59748
diff changeset
   179
subsubsection\<open>The Carry and Borrow Functions,
240563fbf41d isabelle update_cartouches;
wenzelm
parents: 59748
diff changeset
   180
            @{term bin_succ} and @{term bin_pred}\<close>
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   181
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   182
(*NCons preserves the integer value of its argument*)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   183
lemma integ_of_NCons [simp]:
46953
2b6e55924af3 replacing ":" by "\<in>"
paulson
parents: 46821
diff changeset
   184
     "[| w \<in> bin; b \<in> bool |] ==> integ_of(NCons(w,b)) = integ_of(w BIT b)"
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   185
apply (erule bin.cases)
46820
c656222c4dc1 mathematical symbols instead of ASCII
paulson
parents: 45703
diff changeset
   186
apply (auto elim!: boolE)
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   187
done
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   188
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   189
lemma integ_of_succ [simp]:
46953
2b6e55924af3 replacing ":" by "\<in>"
paulson
parents: 46821
diff changeset
   190
     "w \<in> bin ==> integ_of(bin_succ(w)) = $#1 $+ integ_of(w)"
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   191
apply (erule bin.induct)
46820
c656222c4dc1 mathematical symbols instead of ASCII
paulson
parents: 45703
diff changeset
   192
apply (auto simp add: zadd_ac elim!: boolE)
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   193
done
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   194
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   195
lemma integ_of_pred [simp]:
46953
2b6e55924af3 replacing ":" by "\<in>"
paulson
parents: 46821
diff changeset
   196
     "w \<in> bin ==> integ_of(bin_pred(w)) = $- ($#1) $+ integ_of(w)"
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   197
apply (erule bin.induct)
46820
c656222c4dc1 mathematical symbols instead of ASCII
paulson
parents: 45703
diff changeset
   198
apply (auto simp add: zadd_ac elim!: boolE)
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   199
done
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   200
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   201
60770
240563fbf41d isabelle update_cartouches;
wenzelm
parents: 59748
diff changeset
   202
subsubsection\<open>@{term bin_minus}: Unary Negation of Binary Integers\<close>
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   203
46953
2b6e55924af3 replacing ":" by "\<in>"
paulson
parents: 46821
diff changeset
   204
lemma integ_of_minus: "w \<in> bin ==> integ_of(bin_minus(w)) = $- integ_of(w)"
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   205
apply (erule bin.induct)
46820
c656222c4dc1 mathematical symbols instead of ASCII
paulson
parents: 45703
diff changeset
   206
apply (auto simp add: zadd_ac zminus_zadd_distrib  elim!: boolE)
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   207
done
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   208
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   209
60770
240563fbf41d isabelle update_cartouches;
wenzelm
parents: 59748
diff changeset
   210
subsubsection\<open>@{term bin_add}: Binary Addition\<close>
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   211
46953
2b6e55924af3 replacing ":" by "\<in>"
paulson
parents: 46821
diff changeset
   212
lemma bin_add_Pls [simp]: "w \<in> bin ==> bin_add(Pls,w) = w"
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   213
by (unfold bin_add_def, simp)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   214
46953
2b6e55924af3 replacing ":" by "\<in>"
paulson
parents: 46821
diff changeset
   215
lemma bin_add_Pls_right: "w \<in> bin ==> bin_add(w,Pls) = w"
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   216
apply (unfold bin_add_def)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   217
apply (erule bin.induct, auto)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   218
done
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   219
46953
2b6e55924af3 replacing ":" by "\<in>"
paulson
parents: 46821
diff changeset
   220
lemma bin_add_Min [simp]: "w \<in> bin ==> bin_add(Min,w) = bin_pred(w)"
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   221
by (unfold bin_add_def, simp)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   222
46953
2b6e55924af3 replacing ":" by "\<in>"
paulson
parents: 46821
diff changeset
   223
lemma bin_add_Min_right: "w \<in> bin ==> bin_add(w,Min) = bin_pred(w)"
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   224
apply (unfold bin_add_def)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   225
apply (erule bin.induct, auto)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   226
done
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   227
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   228
lemma bin_add_BIT_Pls [simp]: "bin_add(v BIT x,Pls) = v BIT x"
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   229
by (unfold bin_add_def, simp)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   230
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   231
lemma bin_add_BIT_Min [simp]: "bin_add(v BIT x,Min) = bin_pred(v BIT x)"
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   232
by (unfold bin_add_def, simp)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   233
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   234
lemma bin_add_BIT_BIT [simp]:
46953
2b6e55924af3 replacing ":" by "\<in>"
paulson
parents: 46821
diff changeset
   235
     "[| w \<in> bin;  y \<in> bool |]
46820
c656222c4dc1 mathematical symbols instead of ASCII
paulson
parents: 45703
diff changeset
   236
      ==> bin_add(v BIT x, w BIT y) =
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   237
          NCons(bin_add(v, cond(x and y, bin_succ(w), w)), x xor y)"
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   238
by (unfold bin_add_def, simp)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   239
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   240
lemma integ_of_add [rule_format]:
46953
2b6e55924af3 replacing ":" by "\<in>"
paulson
parents: 46821
diff changeset
   241
     "v \<in> bin ==>
46820
c656222c4dc1 mathematical symbols instead of ASCII
paulson
parents: 45703
diff changeset
   242
          \<forall>w\<in>bin. integ_of(bin_add(v,w)) = integ_of(v) $+ integ_of(w)"
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   243
apply (erule bin.induct, simp, simp)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   244
apply (rule ballI)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   245
apply (induct_tac "wa")
46820
c656222c4dc1 mathematical symbols instead of ASCII
paulson
parents: 45703
diff changeset
   246
apply (auto simp add: zadd_ac elim!: boolE)
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   247
done
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   248
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   249
(*Subtraction*)
46820
c656222c4dc1 mathematical symbols instead of ASCII
paulson
parents: 45703
diff changeset
   250
lemma diff_integ_of_eq:
46953
2b6e55924af3 replacing ":" by "\<in>"
paulson
parents: 46821
diff changeset
   251
     "[| v \<in> bin;  w \<in> bin |]
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   252
      ==> integ_of(v) $- integ_of(w) = integ_of(bin_add (v, bin_minus(w)))"
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   253
apply (unfold zdiff_def)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   254
apply (simp add: integ_of_add integ_of_minus)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   255
done
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   256
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   257
60770
240563fbf41d isabelle update_cartouches;
wenzelm
parents: 59748
diff changeset
   258
subsubsection\<open>@{term bin_mult}: Binary Multiplication\<close>
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   259
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   260
lemma integ_of_mult:
46953
2b6e55924af3 replacing ":" by "\<in>"
paulson
parents: 46821
diff changeset
   261
     "[| v \<in> bin;  w \<in> bin |]
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   262
      ==> integ_of(bin_mult(v,w)) = integ_of(v) $* integ_of(w)"
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   263
apply (induct_tac "v", simp)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   264
apply (simp add: integ_of_minus)
46820
c656222c4dc1 mathematical symbols instead of ASCII
paulson
parents: 45703
diff changeset
   265
apply (auto simp add: zadd_ac integ_of_add zadd_zmult_distrib  elim!: boolE)
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   266
done
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   267
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   268
60770
240563fbf41d isabelle update_cartouches;
wenzelm
parents: 59748
diff changeset
   269
subsection\<open>Computations\<close>
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   270
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   271
(** extra rules for bin_succ, bin_pred **)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   272
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   273
lemma bin_succ_1: "bin_succ(w BIT 1) = bin_succ(w) BIT 0"
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   274
by simp
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   275
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   276
lemma bin_succ_0: "bin_succ(w BIT 0) = NCons(w,1)"
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   277
by simp
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   278
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   279
lemma bin_pred_1: "bin_pred(w BIT 1) = NCons(w,0)"
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   280
by simp
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   281
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   282
lemma bin_pred_0: "bin_pred(w BIT 0) = bin_pred(w) BIT 1"
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   283
by simp
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   284
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   285
(** extra rules for bin_minus **)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   286
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   287
lemma bin_minus_1: "bin_minus(w BIT 1) = bin_pred(NCons(bin_minus(w), 0))"
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   288
by simp
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   289
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   290
lemma bin_minus_0: "bin_minus(w BIT 0) = bin_minus(w) BIT 0"
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   291
by simp
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   292
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   293
(** extra rules for bin_add **)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   294
46953
2b6e55924af3 replacing ":" by "\<in>"
paulson
parents: 46821
diff changeset
   295
lemma bin_add_BIT_11: "w \<in> bin ==> bin_add(v BIT 1, w BIT 1) =
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   296
                     NCons(bin_add(v, bin_succ(w)), 0)"
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   297
by simp
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   298
46953
2b6e55924af3 replacing ":" by "\<in>"
paulson
parents: 46821
diff changeset
   299
lemma bin_add_BIT_10: "w \<in> bin ==> bin_add(v BIT 1, w BIT 0) =
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   300
                     NCons(bin_add(v,w), 1)"
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   301
by simp
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   302
46953
2b6e55924af3 replacing ":" by "\<in>"
paulson
parents: 46821
diff changeset
   303
lemma bin_add_BIT_0: "[| w \<in> bin;  y \<in> bool |]
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   304
      ==> bin_add(v BIT 0, w BIT y) = NCons(bin_add(v,w), y)"
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   305
by simp
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   306
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   307
(** extra rules for bin_mult **)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   308
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   309
lemma bin_mult_1: "bin_mult(v BIT 1, w) = bin_add(NCons(bin_mult(v,w),0), w)"
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   310
by simp
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   311
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   312
lemma bin_mult_0: "bin_mult(v BIT 0, w) = NCons(bin_mult(v,w),0)"
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   313
by simp
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   314
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   315
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   316
(** Simplification rules with integer constants **)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   317
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   318
lemma int_of_0: "$#0 = #0"
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   319
by simp
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   320
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   321
lemma int_of_succ: "$# succ(n) = #1 $+ $#n"
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   322
by (simp add: int_of_add [symmetric] natify_succ)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   323
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   324
lemma zminus_0 [simp]: "$- #0 = #0"
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   325
by simp
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   326
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   327
lemma zadd_0_intify [simp]: "#0 $+ z = intify(z)"
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   328
by simp
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   329
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   330
lemma zadd_0_right_intify [simp]: "z $+ #0 = intify(z)"
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   331
by simp
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   332
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   333
lemma zmult_1_intify [simp]: "#1 $* z = intify(z)"
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   334
by simp
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   335
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   336
lemma zmult_1_right_intify [simp]: "z $* #1 = intify(z)"
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   337
by (subst zmult_commute, simp)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   338
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   339
lemma zmult_0 [simp]: "#0 $* z = #0"
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   340
by simp
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   341
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   342
lemma zmult_0_right [simp]: "z $* #0 = #0"
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   343
by (subst zmult_commute, simp)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   344
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   345
lemma zmult_minus1 [simp]: "#-1 $* z = $-z"
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   346
by (simp add: zcompare_rls)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   347
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   348
lemma zmult_minus1_right [simp]: "z $* #-1 = $-z"
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   349
apply (subst zmult_commute)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   350
apply (rule zmult_minus1)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   351
done
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   352
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   353
60770
240563fbf41d isabelle update_cartouches;
wenzelm
parents: 59748
diff changeset
   354
subsection\<open>Simplification Rules for Comparison of Binary Numbers\<close>
240563fbf41d isabelle update_cartouches;
wenzelm
parents: 59748
diff changeset
   355
text\<open>Thanks to Norbert Voelker\<close>
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   356
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   357
(** Equals (=) **)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   358
46820
c656222c4dc1 mathematical symbols instead of ASCII
paulson
parents: 45703
diff changeset
   359
lemma eq_integ_of_eq:
46953
2b6e55924af3 replacing ":" by "\<in>"
paulson
parents: 46821
diff changeset
   360
     "[| v \<in> bin;  w \<in> bin |]
46821
ff6b0c1087f2 Using mathematical notation for <-> and cardinal arithmetic
paulson
parents: 46820
diff changeset
   361
      ==> ((integ_of(v)) = integ_of(w)) \<longleftrightarrow>
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   362
          iszero (integ_of (bin_add (v, bin_minus(w))))"
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   363
apply (unfold iszero_def)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   364
apply (simp add: zcompare_rls integ_of_add integ_of_minus)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   365
done
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   366
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   367
lemma iszero_integ_of_Pls: "iszero (integ_of(Pls))"
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   368
by (unfold iszero_def, simp)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   369
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   370
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   371
lemma nonzero_integ_of_Min: "~ iszero (integ_of(Min))"
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   372
apply (unfold iszero_def)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   373
apply (simp add: zminus_equation)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   374
done
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   375
46820
c656222c4dc1 mathematical symbols instead of ASCII
paulson
parents: 45703
diff changeset
   376
lemma iszero_integ_of_BIT:
46953
2b6e55924af3 replacing ":" by "\<in>"
paulson
parents: 46821
diff changeset
   377
     "[| w \<in> bin; x \<in> bool |]
46821
ff6b0c1087f2 Using mathematical notation for <-> and cardinal arithmetic
paulson
parents: 46820
diff changeset
   378
      ==> iszero (integ_of (w BIT x)) \<longleftrightarrow> (x=0 & iszero (integ_of(w)))"
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   379
apply (unfold iszero_def, simp)
46820
c656222c4dc1 mathematical symbols instead of ASCII
paulson
parents: 45703
diff changeset
   380
apply (subgoal_tac "integ_of (w) \<in> int")
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   381
apply typecheck
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   382
apply (drule int_cases)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   383
apply (safe elim!: boolE)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   384
apply (simp_all (asm_lr) add: zcompare_rls zminus_zadd_distrib [symmetric]
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   385
                     int_of_add [symmetric])
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   386
done
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   387
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   388
lemma iszero_integ_of_0:
46953
2b6e55924af3 replacing ":" by "\<in>"
paulson
parents: 46821
diff changeset
   389
     "w \<in> bin ==> iszero (integ_of (w BIT 0)) \<longleftrightarrow> iszero (integ_of(w))"
46820
c656222c4dc1 mathematical symbols instead of ASCII
paulson
parents: 45703
diff changeset
   390
by (simp only: iszero_integ_of_BIT, blast)
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   391
46953
2b6e55924af3 replacing ":" by "\<in>"
paulson
parents: 46821
diff changeset
   392
lemma iszero_integ_of_1: "w \<in> bin ==> ~ iszero (integ_of (w BIT 1))"
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   393
by (simp only: iszero_integ_of_BIT, blast)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   394
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   395
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   396
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   397
(** Less-than (<) **)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   398
46820
c656222c4dc1 mathematical symbols instead of ASCII
paulson
parents: 45703
diff changeset
   399
lemma less_integ_of_eq_neg:
46953
2b6e55924af3 replacing ":" by "\<in>"
paulson
parents: 46821
diff changeset
   400
     "[| v \<in> bin;  w \<in> bin |]
46820
c656222c4dc1 mathematical symbols instead of ASCII
paulson
parents: 45703
diff changeset
   401
      ==> integ_of(v) $< integ_of(w)
46821
ff6b0c1087f2 Using mathematical notation for <-> and cardinal arithmetic
paulson
parents: 46820
diff changeset
   402
          \<longleftrightarrow> znegative (integ_of (bin_add (v, bin_minus(w))))"
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   403
apply (unfold zless_def zdiff_def)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   404
apply (simp add: integ_of_minus integ_of_add)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   405
done
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   406
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   407
lemma not_neg_integ_of_Pls: "~ znegative (integ_of(Pls))"
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   408
by simp
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   409
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   410
lemma neg_integ_of_Min: "znegative (integ_of(Min))"
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   411
by simp
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   412
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   413
lemma neg_integ_of_BIT:
46953
2b6e55924af3 replacing ":" by "\<in>"
paulson
parents: 46821
diff changeset
   414
     "[| w \<in> bin; x \<in> bool |]
46821
ff6b0c1087f2 Using mathematical notation for <-> and cardinal arithmetic
paulson
parents: 46820
diff changeset
   415
      ==> znegative (integ_of (w BIT x)) \<longleftrightarrow> znegative (integ_of(w))"
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   416
apply simp
46820
c656222c4dc1 mathematical symbols instead of ASCII
paulson
parents: 45703
diff changeset
   417
apply (subgoal_tac "integ_of (w) \<in> int")
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   418
apply typecheck
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   419
apply (drule int_cases)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   420
apply (auto elim!: boolE simp add: int_of_add [symmetric]  zcompare_rls)
46820
c656222c4dc1 mathematical symbols instead of ASCII
paulson
parents: 45703
diff changeset
   421
apply (simp_all add: zminus_zadd_distrib [symmetric] zdiff_def
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   422
                     int_of_add [symmetric])
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   423
apply (subgoal_tac "$#1 $- $# succ (succ (n #+ n)) = $- $# succ (n #+ n) ")
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   424
 apply (simp add: zdiff_def)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   425
apply (simp add: equation_zminus int_of_diff [symmetric])
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   426
done
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   427
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   428
(** Less-than-or-equals (<=) **)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   429
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   430
lemma le_integ_of_eq_not_less:
61395
4f8c2c4a0a8c tuned syntax -- more symbols;
wenzelm
parents: 61337
diff changeset
   431
     "(integ_of(x) $\<le> (integ_of(w))) \<longleftrightarrow> ~ (integ_of(w) $< (integ_of(x)))"
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   432
by (simp add: not_zless_iff_zle [THEN iff_sym])
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   433
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   434
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   435
(*Delete the original rewrites, with their clumsy conditional expressions*)
46820
c656222c4dc1 mathematical symbols instead of ASCII
paulson
parents: 45703
diff changeset
   436
declare bin_succ_BIT [simp del]
c656222c4dc1 mathematical symbols instead of ASCII
paulson
parents: 45703
diff changeset
   437
        bin_pred_BIT [simp del]
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   438
        bin_minus_BIT [simp del]
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   439
        NCons_Pls [simp del]
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   440
        NCons_Min [simp del]
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   441
        bin_adder_BIT [simp del]
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   442
        bin_mult_BIT [simp del]
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   443
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   444
(*Hide the binary representation of integer constants*)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   445
declare integ_of_Pls [simp del] integ_of_Min [simp del] integ_of_BIT [simp del]
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   446
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   447
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   448
lemmas bin_arith_extra_simps =
46820
c656222c4dc1 mathematical symbols instead of ASCII
paulson
parents: 45703
diff changeset
   449
     integ_of_add [symmetric]
c656222c4dc1 mathematical symbols instead of ASCII
paulson
parents: 45703
diff changeset
   450
     integ_of_minus [symmetric]
c656222c4dc1 mathematical symbols instead of ASCII
paulson
parents: 45703
diff changeset
   451
     integ_of_mult [symmetric]
c656222c4dc1 mathematical symbols instead of ASCII
paulson
parents: 45703
diff changeset
   452
     bin_succ_1 bin_succ_0
c656222c4dc1 mathematical symbols instead of ASCII
paulson
parents: 45703
diff changeset
   453
     bin_pred_1 bin_pred_0
c656222c4dc1 mathematical symbols instead of ASCII
paulson
parents: 45703
diff changeset
   454
     bin_minus_1 bin_minus_0
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   455
     bin_add_Pls_right bin_add_Min_right
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   456
     bin_add_BIT_0 bin_add_BIT_10 bin_add_BIT_11
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   457
     diff_integ_of_eq
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   458
     bin_mult_1 bin_mult_0 NCons_simps
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   459
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   460
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   461
(*For making a minimal simpset, one must include these default simprules
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   462
  of thy.  Also include simp_thms, or at least (~False)=True*)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   463
lemmas bin_arith_simps =
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   464
     bin_pred_Pls bin_pred_Min
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   465
     bin_succ_Pls bin_succ_Min
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   466
     bin_add_Pls bin_add_Min
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   467
     bin_minus_Pls bin_minus_Min
46820
c656222c4dc1 mathematical symbols instead of ASCII
paulson
parents: 45703
diff changeset
   468
     bin_mult_Pls bin_mult_Min
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   469
     bin_arith_extra_simps
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   470
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   471
(*Simplification of relational operations*)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   472
lemmas bin_rel_simps =
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   473
     eq_integ_of_eq iszero_integ_of_Pls nonzero_integ_of_Min
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   474
     iszero_integ_of_0 iszero_integ_of_1
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   475
     less_integ_of_eq_neg
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   476
     not_neg_integ_of_Pls neg_integ_of_Min neg_integ_of_BIT
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   477
     le_integ_of_eq_not_less
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   478
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   479
declare bin_arith_simps [simp]
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   480
declare bin_rel_simps [simp]
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   481
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   482
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   483
(** Simplification of arithmetic when nested to the right **)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   484
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   485
lemma add_integ_of_left [simp]:
46953
2b6e55924af3 replacing ":" by "\<in>"
paulson
parents: 46821
diff changeset
   486
     "[| v \<in> bin;  w \<in> bin |]
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   487
      ==> integ_of(v) $+ (integ_of(w) $+ z) = (integ_of(bin_add(v,w)) $+ z)"
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   488
by (simp add: zadd_assoc [symmetric])
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   489
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   490
lemma mult_integ_of_left [simp]:
46953
2b6e55924af3 replacing ":" by "\<in>"
paulson
parents: 46821
diff changeset
   491
     "[| v \<in> bin;  w \<in> bin |]
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   492
      ==> integ_of(v) $* (integ_of(w) $* z) = (integ_of(bin_mult(v,w)) $* z)"
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   493
by (simp add: zmult_assoc [symmetric])
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   494
46820
c656222c4dc1 mathematical symbols instead of ASCII
paulson
parents: 45703
diff changeset
   495
lemma add_integ_of_diff1 [simp]:
46953
2b6e55924af3 replacing ":" by "\<in>"
paulson
parents: 46821
diff changeset
   496
    "[| v \<in> bin;  w \<in> bin |]
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   497
      ==> integ_of(v) $+ (integ_of(w) $- c) = integ_of(bin_add(v,w)) $- (c)"
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   498
apply (unfold zdiff_def)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   499
apply (rule add_integ_of_left, auto)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   500
done
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   501
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   502
lemma add_integ_of_diff2 [simp]:
46953
2b6e55924af3 replacing ":" by "\<in>"
paulson
parents: 46821
diff changeset
   503
     "[| v \<in> bin;  w \<in> bin |]
46820
c656222c4dc1 mathematical symbols instead of ASCII
paulson
parents: 45703
diff changeset
   504
      ==> integ_of(v) $+ (c $- integ_of(w)) =
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   505
          integ_of (bin_add (v, bin_minus(w))) $+ (c)"
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   506
apply (subst diff_integ_of_eq [symmetric])
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   507
apply (simp_all add: zdiff_def zadd_ac)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   508
done
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   509
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   510
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   511
(** More for integer constants **)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   512
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   513
declare int_of_0 [simp] int_of_succ [simp]
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   514
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   515
lemma zdiff0 [simp]: "#0 $- x = $-x"
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   516
by (simp add: zdiff_def)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   517
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   518
lemma zdiff0_right [simp]: "x $- #0 = intify(x)"
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   519
by (simp add: zdiff_def)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   520
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   521
lemma zdiff_self [simp]: "x $- x = #0"
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   522
by (simp add: zdiff_def)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   523
46953
2b6e55924af3 replacing ":" by "\<in>"
paulson
parents: 46821
diff changeset
   524
lemma znegative_iff_zless_0: "k \<in> int ==> znegative(k) \<longleftrightarrow> k $< #0"
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   525
by (simp add: zless_def)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   526
46953
2b6e55924af3 replacing ":" by "\<in>"
paulson
parents: 46821
diff changeset
   527
lemma zero_zless_imp_znegative_zminus: "[|#0 $< k; k \<in> int|] ==> znegative($-k)"
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   528
by (simp add: zless_def)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   529
61395
4f8c2c4a0a8c tuned syntax -- more symbols;
wenzelm
parents: 61337
diff changeset
   530
lemma zero_zle_int_of [simp]: "#0 $\<le> $# n"
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   531
by (simp add: not_zless_iff_zle [THEN iff_sym] znegative_iff_zless_0 [THEN iff_sym])
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   532
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   533
lemma nat_of_0 [simp]: "nat_of(#0) = 0"
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   534
by (simp only: natify_0 int_of_0 [symmetric] nat_of_int_of)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   535
61395
4f8c2c4a0a8c tuned syntax -- more symbols;
wenzelm
parents: 61337
diff changeset
   536
lemma nat_le_int0_lemma: "[| z $\<le> $#0; z \<in> int |] ==> nat_of(z) = 0"
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   537
by (auto simp add: znegative_iff_zless_0 [THEN iff_sym] zle_def zneg_nat_of)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   538
61395
4f8c2c4a0a8c tuned syntax -- more symbols;
wenzelm
parents: 61337
diff changeset
   539
lemma nat_le_int0: "z $\<le> $#0 ==> nat_of(z) = 0"
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   540
apply (subgoal_tac "nat_of (intify (z)) = 0")
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   541
apply (rule_tac [2] nat_le_int0_lemma, auto)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   542
done
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   543
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   544
lemma int_of_eq_0_imp_natify_eq_0: "$# n = #0 ==> natify(n) = 0"
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   545
by (rule not_znegative_imp_zero, auto)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   546
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   547
lemma nat_of_zminus_int_of: "nat_of($- $# n) = 0"
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   548
by (simp add: nat_of_def int_of_def raw_nat_of zminus image_intrel_int)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   549
61395
4f8c2c4a0a8c tuned syntax -- more symbols;
wenzelm
parents: 61337
diff changeset
   550
lemma int_of_nat_of: "#0 $\<le> z ==> $# nat_of(z) = intify(z)"
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   551
apply (rule not_zneg_nat_of_intify)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   552
apply (simp add: znegative_iff_zless_0 not_zless_iff_zle)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   553
done
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   554
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   555
declare int_of_nat_of [simp] nat_of_zminus_int_of [simp]
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   556
61395
4f8c2c4a0a8c tuned syntax -- more symbols;
wenzelm
parents: 61337
diff changeset
   557
lemma int_of_nat_of_if: "$# nat_of(z) = (if #0 $\<le> z then intify(z) else #0)"
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   558
by (simp add: int_of_nat_of znegative_iff_zless_0 not_zle_iff_zless)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   559
46953
2b6e55924af3 replacing ":" by "\<in>"
paulson
parents: 46821
diff changeset
   560
lemma zless_nat_iff_int_zless: "[| m \<in> nat; z \<in> int |] ==> (m < nat_of(z)) \<longleftrightarrow> ($#m $< z)"
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   561
apply (case_tac "znegative (z) ")
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   562
apply (erule_tac [2] not_zneg_nat_of [THEN subst])
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   563
apply (auto dest: zless_trans dest!: zero_zle_int_of [THEN zle_zless_trans]
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   564
            simp add: znegative_iff_zless_0)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   565
done
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   566
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   567
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   568
(** nat_of and zless **)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   569
46820
c656222c4dc1 mathematical symbols instead of ASCII
paulson
parents: 45703
diff changeset
   570
(*An alternative condition is  @{term"$#0 \<subseteq> w"}  *)
46821
ff6b0c1087f2 Using mathematical notation for <-> and cardinal arithmetic
paulson
parents: 46820
diff changeset
   571
lemma zless_nat_conj_lemma: "$#0 $< z ==> (nat_of(w) < nat_of(z)) \<longleftrightarrow> (w $< z)"
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   572
apply (rule iff_trans)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   573
apply (rule zless_int_of [THEN iff_sym])
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   574
apply (auto simp add: int_of_nat_of_if simp del: zless_int_of)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   575
apply (auto elim: zless_asym simp add: not_zle_iff_zless)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   576
apply (blast intro: zless_zle_trans)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   577
done
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   578
46821
ff6b0c1087f2 Using mathematical notation for <-> and cardinal arithmetic
paulson
parents: 46820
diff changeset
   579
lemma zless_nat_conj: "(nat_of(w) < nat_of(z)) \<longleftrightarrow> ($#0 $< z & w $< z)"
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   580
apply (case_tac "$#0 $< z")
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   581
apply (auto simp add: zless_nat_conj_lemma nat_le_int0 not_zless_iff_zle)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   582
done
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   583
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   584
(*This simprule cannot be added unless we can find a way to make eq_integ_of_eq
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   585
  unconditional!
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   586
  [The condition "True" is a hack to prevent looping.
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   587
    Conditional rewrite rules are tried after unconditional ones, so a rule
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   588
    like eq_nat_number_of will be tried first to eliminate #mm=#nn.]
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   589
  lemma integ_of_reorient [simp]:
46821
ff6b0c1087f2 Using mathematical notation for <-> and cardinal arithmetic
paulson
parents: 46820
diff changeset
   590
       "True ==> (integ_of(w) = x) \<longleftrightarrow> (x = integ_of(w))"
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   591
  by auto
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   592
*)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   593
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   594
lemma integ_of_minus_reorient [simp]:
46821
ff6b0c1087f2 Using mathematical notation for <-> and cardinal arithmetic
paulson
parents: 46820
diff changeset
   595
     "(integ_of(w) = $- x) \<longleftrightarrow> ($- x = integ_of(w))"
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   596
by auto
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   597
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   598
lemma integ_of_add_reorient [simp]:
46821
ff6b0c1087f2 Using mathematical notation for <-> and cardinal arithmetic
paulson
parents: 46820
diff changeset
   599
     "(integ_of(w) = x $+ y) \<longleftrightarrow> (x $+ y = integ_of(w))"
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   600
by auto
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   601
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   602
lemma integ_of_diff_reorient [simp]:
46821
ff6b0c1087f2 Using mathematical notation for <-> and cardinal arithmetic
paulson
parents: 46820
diff changeset
   603
     "(integ_of(w) = x $- y) \<longleftrightarrow> (x $- y = integ_of(w))"
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   604
by auto
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   605
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   606
lemma integ_of_mult_reorient [simp]:
46821
ff6b0c1087f2 Using mathematical notation for <-> and cardinal arithmetic
paulson
parents: 46820
diff changeset
   607
     "(integ_of(w) = x $* y) \<longleftrightarrow> (x $* y = integ_of(w))"
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   608
by auto
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   609
58022
464c1815fde9 integrated appendix theory into main theory;
haftmann
parents: 48891
diff changeset
   610
(** To simplify inequalities involving integer negation and literals,
464c1815fde9 integrated appendix theory into main theory;
haftmann
parents: 48891
diff changeset
   611
    such as -x = #3
464c1815fde9 integrated appendix theory into main theory;
haftmann
parents: 48891
diff changeset
   612
**)
464c1815fde9 integrated appendix theory into main theory;
haftmann
parents: 48891
diff changeset
   613
464c1815fde9 integrated appendix theory into main theory;
haftmann
parents: 48891
diff changeset
   614
lemmas [simp] =
464c1815fde9 integrated appendix theory into main theory;
haftmann
parents: 48891
diff changeset
   615
  zminus_equation [where y = "integ_of(w)"]
464c1815fde9 integrated appendix theory into main theory;
haftmann
parents: 48891
diff changeset
   616
  equation_zminus [where x = "integ_of(w)"]
464c1815fde9 integrated appendix theory into main theory;
haftmann
parents: 48891
diff changeset
   617
  for w
464c1815fde9 integrated appendix theory into main theory;
haftmann
parents: 48891
diff changeset
   618
464c1815fde9 integrated appendix theory into main theory;
haftmann
parents: 48891
diff changeset
   619
lemmas [iff] =
464c1815fde9 integrated appendix theory into main theory;
haftmann
parents: 48891
diff changeset
   620
  zminus_zless [where y = "integ_of(w)"]
464c1815fde9 integrated appendix theory into main theory;
haftmann
parents: 48891
diff changeset
   621
  zless_zminus [where x = "integ_of(w)"]
464c1815fde9 integrated appendix theory into main theory;
haftmann
parents: 48891
diff changeset
   622
  for w
464c1815fde9 integrated appendix theory into main theory;
haftmann
parents: 48891
diff changeset
   623
464c1815fde9 integrated appendix theory into main theory;
haftmann
parents: 48891
diff changeset
   624
lemmas [iff] =
464c1815fde9 integrated appendix theory into main theory;
haftmann
parents: 48891
diff changeset
   625
  zminus_zle [where y = "integ_of(w)"]
464c1815fde9 integrated appendix theory into main theory;
haftmann
parents: 48891
diff changeset
   626
  zle_zminus [where x = "integ_of(w)"]
464c1815fde9 integrated appendix theory into main theory;
haftmann
parents: 48891
diff changeset
   627
  for w
464c1815fde9 integrated appendix theory into main theory;
haftmann
parents: 48891
diff changeset
   628
464c1815fde9 integrated appendix theory into main theory;
haftmann
parents: 48891
diff changeset
   629
lemmas [simp] =
464c1815fde9 integrated appendix theory into main theory;
haftmann
parents: 48891
diff changeset
   630
  Let_def [where s = "integ_of(w)"] for w
464c1815fde9 integrated appendix theory into main theory;
haftmann
parents: 48891
diff changeset
   631
464c1815fde9 integrated appendix theory into main theory;
haftmann
parents: 48891
diff changeset
   632
464c1815fde9 integrated appendix theory into main theory;
haftmann
parents: 48891
diff changeset
   633
(*** Simprocs for numeric literals ***)
464c1815fde9 integrated appendix theory into main theory;
haftmann
parents: 48891
diff changeset
   634
464c1815fde9 integrated appendix theory into main theory;
haftmann
parents: 48891
diff changeset
   635
(** Combining of literal coefficients in sums of products **)
464c1815fde9 integrated appendix theory into main theory;
haftmann
parents: 48891
diff changeset
   636
464c1815fde9 integrated appendix theory into main theory;
haftmann
parents: 48891
diff changeset
   637
lemma zless_iff_zdiff_zless_0: "(x $< y) \<longleftrightarrow> (x$-y $< #0)"
464c1815fde9 integrated appendix theory into main theory;
haftmann
parents: 48891
diff changeset
   638
  by (simp add: zcompare_rls)
464c1815fde9 integrated appendix theory into main theory;
haftmann
parents: 48891
diff changeset
   639
464c1815fde9 integrated appendix theory into main theory;
haftmann
parents: 48891
diff changeset
   640
lemma eq_iff_zdiff_eq_0: "[| x \<in> int; y \<in> int |] ==> (x = y) \<longleftrightarrow> (x$-y = #0)"
464c1815fde9 integrated appendix theory into main theory;
haftmann
parents: 48891
diff changeset
   641
  by (simp add: zcompare_rls)
464c1815fde9 integrated appendix theory into main theory;
haftmann
parents: 48891
diff changeset
   642
61395
4f8c2c4a0a8c tuned syntax -- more symbols;
wenzelm
parents: 61337
diff changeset
   643
lemma zle_iff_zdiff_zle_0: "(x $\<le> y) \<longleftrightarrow> (x$-y $\<le> #0)"
58022
464c1815fde9 integrated appendix theory into main theory;
haftmann
parents: 48891
diff changeset
   644
  by (simp add: zcompare_rls)
464c1815fde9 integrated appendix theory into main theory;
haftmann
parents: 48891
diff changeset
   645
464c1815fde9 integrated appendix theory into main theory;
haftmann
parents: 48891
diff changeset
   646
464c1815fde9 integrated appendix theory into main theory;
haftmann
parents: 48891
diff changeset
   647
(** For combine_numerals **)
464c1815fde9 integrated appendix theory into main theory;
haftmann
parents: 48891
diff changeset
   648
464c1815fde9 integrated appendix theory into main theory;
haftmann
parents: 48891
diff changeset
   649
lemma left_zadd_zmult_distrib: "i$*u $+ (j$*u $+ k) = (i$+j)$*u $+ k"
464c1815fde9 integrated appendix theory into main theory;
haftmann
parents: 48891
diff changeset
   650
  by (simp add: zadd_zmult_distrib zadd_ac)
464c1815fde9 integrated appendix theory into main theory;
haftmann
parents: 48891
diff changeset
   651
464c1815fde9 integrated appendix theory into main theory;
haftmann
parents: 48891
diff changeset
   652
464c1815fde9 integrated appendix theory into main theory;
haftmann
parents: 48891
diff changeset
   653
(** For cancel_numerals **)
464c1815fde9 integrated appendix theory into main theory;
haftmann
parents: 48891
diff changeset
   654
464c1815fde9 integrated appendix theory into main theory;
haftmann
parents: 48891
diff changeset
   655
lemmas rel_iff_rel_0_rls =
464c1815fde9 integrated appendix theory into main theory;
haftmann
parents: 48891
diff changeset
   656
  zless_iff_zdiff_zless_0 [where y = "u $+ v"]
464c1815fde9 integrated appendix theory into main theory;
haftmann
parents: 48891
diff changeset
   657
  eq_iff_zdiff_eq_0 [where y = "u $+ v"]
464c1815fde9 integrated appendix theory into main theory;
haftmann
parents: 48891
diff changeset
   658
  zle_iff_zdiff_zle_0 [where y = "u $+ v"]
464c1815fde9 integrated appendix theory into main theory;
haftmann
parents: 48891
diff changeset
   659
  zless_iff_zdiff_zless_0 [where y = n]
464c1815fde9 integrated appendix theory into main theory;
haftmann
parents: 48891
diff changeset
   660
  eq_iff_zdiff_eq_0 [where y = n]
464c1815fde9 integrated appendix theory into main theory;
haftmann
parents: 48891
diff changeset
   661
  zle_iff_zdiff_zle_0 [where y = n]
464c1815fde9 integrated appendix theory into main theory;
haftmann
parents: 48891
diff changeset
   662
  for u v (* FIXME n (!?) *)
464c1815fde9 integrated appendix theory into main theory;
haftmann
parents: 48891
diff changeset
   663
464c1815fde9 integrated appendix theory into main theory;
haftmann
parents: 48891
diff changeset
   664
lemma eq_add_iff1: "(i$*u $+ m = j$*u $+ n) \<longleftrightarrow> ((i$-j)$*u $+ m = intify(n))"
464c1815fde9 integrated appendix theory into main theory;
haftmann
parents: 48891
diff changeset
   665
  apply (simp add: zdiff_def zadd_zmult_distrib)
464c1815fde9 integrated appendix theory into main theory;
haftmann
parents: 48891
diff changeset
   666
  apply (simp add: zcompare_rls)
464c1815fde9 integrated appendix theory into main theory;
haftmann
parents: 48891
diff changeset
   667
  apply (simp add: zadd_ac)
464c1815fde9 integrated appendix theory into main theory;
haftmann
parents: 48891
diff changeset
   668
  done
464c1815fde9 integrated appendix theory into main theory;
haftmann
parents: 48891
diff changeset
   669
464c1815fde9 integrated appendix theory into main theory;
haftmann
parents: 48891
diff changeset
   670
lemma eq_add_iff2: "(i$*u $+ m = j$*u $+ n) \<longleftrightarrow> (intify(m) = (j$-i)$*u $+ n)"
464c1815fde9 integrated appendix theory into main theory;
haftmann
parents: 48891
diff changeset
   671
  apply (simp add: zdiff_def zadd_zmult_distrib)
464c1815fde9 integrated appendix theory into main theory;
haftmann
parents: 48891
diff changeset
   672
  apply (simp add: zcompare_rls)
464c1815fde9 integrated appendix theory into main theory;
haftmann
parents: 48891
diff changeset
   673
  apply (simp add: zadd_ac)
464c1815fde9 integrated appendix theory into main theory;
haftmann
parents: 48891
diff changeset
   674
  done
464c1815fde9 integrated appendix theory into main theory;
haftmann
parents: 48891
diff changeset
   675
464c1815fde9 integrated appendix theory into main theory;
haftmann
parents: 48891
diff changeset
   676
lemma less_add_iff1: "(i$*u $+ m $< j$*u $+ n) \<longleftrightarrow> ((i$-j)$*u $+ m $< n)"
464c1815fde9 integrated appendix theory into main theory;
haftmann
parents: 48891
diff changeset
   677
  apply (simp add: zdiff_def zadd_zmult_distrib zadd_ac rel_iff_rel_0_rls)
464c1815fde9 integrated appendix theory into main theory;
haftmann
parents: 48891
diff changeset
   678
  done
464c1815fde9 integrated appendix theory into main theory;
haftmann
parents: 48891
diff changeset
   679
464c1815fde9 integrated appendix theory into main theory;
haftmann
parents: 48891
diff changeset
   680
lemma less_add_iff2: "(i$*u $+ m $< j$*u $+ n) \<longleftrightarrow> (m $< (j$-i)$*u $+ n)"
464c1815fde9 integrated appendix theory into main theory;
haftmann
parents: 48891
diff changeset
   681
  apply (simp add: zdiff_def zadd_zmult_distrib zadd_ac rel_iff_rel_0_rls)
464c1815fde9 integrated appendix theory into main theory;
haftmann
parents: 48891
diff changeset
   682
  done
464c1815fde9 integrated appendix theory into main theory;
haftmann
parents: 48891
diff changeset
   683
61395
4f8c2c4a0a8c tuned syntax -- more symbols;
wenzelm
parents: 61337
diff changeset
   684
lemma le_add_iff1: "(i$*u $+ m $\<le> j$*u $+ n) \<longleftrightarrow> ((i$-j)$*u $+ m $\<le> n)"
58022
464c1815fde9 integrated appendix theory into main theory;
haftmann
parents: 48891
diff changeset
   685
  apply (simp add: zdiff_def zadd_zmult_distrib)
464c1815fde9 integrated appendix theory into main theory;
haftmann
parents: 48891
diff changeset
   686
  apply (simp add: zcompare_rls)
464c1815fde9 integrated appendix theory into main theory;
haftmann
parents: 48891
diff changeset
   687
  apply (simp add: zadd_ac)
464c1815fde9 integrated appendix theory into main theory;
haftmann
parents: 48891
diff changeset
   688
  done
464c1815fde9 integrated appendix theory into main theory;
haftmann
parents: 48891
diff changeset
   689
61395
4f8c2c4a0a8c tuned syntax -- more symbols;
wenzelm
parents: 61337
diff changeset
   690
lemma le_add_iff2: "(i$*u $+ m $\<le> j$*u $+ n) \<longleftrightarrow> (m $\<le> (j$-i)$*u $+ n)"
58022
464c1815fde9 integrated appendix theory into main theory;
haftmann
parents: 48891
diff changeset
   691
  apply (simp add: zdiff_def zadd_zmult_distrib)
464c1815fde9 integrated appendix theory into main theory;
haftmann
parents: 48891
diff changeset
   692
  apply (simp add: zcompare_rls)
464c1815fde9 integrated appendix theory into main theory;
haftmann
parents: 48891
diff changeset
   693
  apply (simp add: zadd_ac)
464c1815fde9 integrated appendix theory into main theory;
haftmann
parents: 48891
diff changeset
   694
  done
464c1815fde9 integrated appendix theory into main theory;
haftmann
parents: 48891
diff changeset
   695
464c1815fde9 integrated appendix theory into main theory;
haftmann
parents: 48891
diff changeset
   696
ML_file "int_arith.ML"
464c1815fde9 integrated appendix theory into main theory;
haftmann
parents: 48891
diff changeset
   697
60770
240563fbf41d isabelle update_cartouches;
wenzelm
parents: 59748
diff changeset
   698
subsection \<open>examples:\<close>
59748
a1c35e6fe735 slightly more formal historic examples;
wenzelm
parents: 58871
diff changeset
   699
61798
27f3c10b0b50 isabelle update_cartouches -c -t;
wenzelm
parents: 61395
diff changeset
   700
text \<open>\<open>combine_numerals_prod\<close> (products of separate literals)\<close>
59748
a1c35e6fe735 slightly more formal historic examples;
wenzelm
parents: 58871
diff changeset
   701
lemma "#5 $* x $* #3 = y" apply simp oops
a1c35e6fe735 slightly more formal historic examples;
wenzelm
parents: 58871
diff changeset
   702
61337
4645502c3c64 fewer aliases for toplevel theorem statements;
wenzelm
parents: 60770
diff changeset
   703
schematic_goal "y2 $+ ?x42 = y $+ y2" apply simp oops
59748
a1c35e6fe735 slightly more formal historic examples;
wenzelm
parents: 58871
diff changeset
   704
a1c35e6fe735 slightly more formal historic examples;
wenzelm
parents: 58871
diff changeset
   705
lemma "oo : int ==> l $+ (l $+ #2) $+ oo = oo" apply simp oops
a1c35e6fe735 slightly more formal historic examples;
wenzelm
parents: 58871
diff changeset
   706
a1c35e6fe735 slightly more formal historic examples;
wenzelm
parents: 58871
diff changeset
   707
lemma "#9$*x $+ y = x$*#23 $+ z" apply simp oops
a1c35e6fe735 slightly more formal historic examples;
wenzelm
parents: 58871
diff changeset
   708
lemma "y $+ x = x $+ z" apply simp oops
a1c35e6fe735 slightly more formal historic examples;
wenzelm
parents: 58871
diff changeset
   709
a1c35e6fe735 slightly more formal historic examples;
wenzelm
parents: 58871
diff changeset
   710
lemma "x : int ==> x $+ y $+ z = x $+ z" apply simp oops
a1c35e6fe735 slightly more formal historic examples;
wenzelm
parents: 58871
diff changeset
   711
lemma "x : int ==> y $+ (z $+ x) = z $+ x" apply simp oops
a1c35e6fe735 slightly more formal historic examples;
wenzelm
parents: 58871
diff changeset
   712
lemma "z : int ==> x $+ y $+ z = (z $+ y) $+ (x $+ w)" apply simp oops
a1c35e6fe735 slightly more formal historic examples;
wenzelm
parents: 58871
diff changeset
   713
lemma "z : int ==> x$*y $+ z = (z $+ y) $+ (y$*x $+ w)" apply simp oops
a1c35e6fe735 slightly more formal historic examples;
wenzelm
parents: 58871
diff changeset
   714
61395
4f8c2c4a0a8c tuned syntax -- more symbols;
wenzelm
parents: 61337
diff changeset
   715
lemma "#-3 $* x $+ y $\<le> x $* #2 $+ z" apply simp oops
4f8c2c4a0a8c tuned syntax -- more symbols;
wenzelm
parents: 61337
diff changeset
   716
lemma "y $+ x $\<le> x $+ z" apply simp oops
4f8c2c4a0a8c tuned syntax -- more symbols;
wenzelm
parents: 61337
diff changeset
   717
lemma "x $+ y $+ z $\<le> x $+ z" apply simp oops
59748
a1c35e6fe735 slightly more formal historic examples;
wenzelm
parents: 58871
diff changeset
   718
a1c35e6fe735 slightly more formal historic examples;
wenzelm
parents: 58871
diff changeset
   719
lemma "y $+ (z $+ x) $< z $+ x" apply simp oops
a1c35e6fe735 slightly more formal historic examples;
wenzelm
parents: 58871
diff changeset
   720
lemma "x $+ y $+ z $< (z $+ y) $+ (x $+ w)" apply simp oops
a1c35e6fe735 slightly more formal historic examples;
wenzelm
parents: 58871
diff changeset
   721
lemma "x$*y $+ z $< (z $+ y) $+ (y$*x $+ w)" apply simp oops
a1c35e6fe735 slightly more formal historic examples;
wenzelm
parents: 58871
diff changeset
   722
a1c35e6fe735 slightly more formal historic examples;
wenzelm
parents: 58871
diff changeset
   723
lemma "l $+ #2 $+ #2 $+ #2 $+ (l $+ #2) $+ (oo $+ #2) = uu" apply simp oops
a1c35e6fe735 slightly more formal historic examples;
wenzelm
parents: 58871
diff changeset
   724
lemma "u : int ==> #2 $* u = u" apply simp oops
a1c35e6fe735 slightly more formal historic examples;
wenzelm
parents: 58871
diff changeset
   725
lemma "(i $+ j $+ #12 $+ k) $- #15 = y" apply simp oops
a1c35e6fe735 slightly more formal historic examples;
wenzelm
parents: 58871
diff changeset
   726
lemma "(i $+ j $+ #12 $+ k) $- #5 = y" apply simp oops
a1c35e6fe735 slightly more formal historic examples;
wenzelm
parents: 58871
diff changeset
   727
a1c35e6fe735 slightly more formal historic examples;
wenzelm
parents: 58871
diff changeset
   728
lemma "y $- b $< b" apply simp oops
a1c35e6fe735 slightly more formal historic examples;
wenzelm
parents: 58871
diff changeset
   729
lemma "y $- (#3 $* b $+ c) $< b $- #2 $* c" apply simp oops
a1c35e6fe735 slightly more formal historic examples;
wenzelm
parents: 58871
diff changeset
   730
a1c35e6fe735 slightly more formal historic examples;
wenzelm
parents: 58871
diff changeset
   731
lemma "(#2 $* x $- (u $* v) $+ y) $- v $* #3 $* u = w" apply simp oops
a1c35e6fe735 slightly more formal historic examples;
wenzelm
parents: 58871
diff changeset
   732
lemma "(#2 $* x $* u $* v $+ (u $* v) $* #4 $+ y) $- v $* u $* #4 = w" apply simp oops
a1c35e6fe735 slightly more formal historic examples;
wenzelm
parents: 58871
diff changeset
   733
lemma "(#2 $* x $* u $* v $+ (u $* v) $* #4 $+ y) $- v $* u = w" apply simp oops
a1c35e6fe735 slightly more formal historic examples;
wenzelm
parents: 58871
diff changeset
   734
lemma "u $* v $- (x $* u $* v $+ (u $* v) $* #4 $+ y) = w" apply simp oops
a1c35e6fe735 slightly more formal historic examples;
wenzelm
parents: 58871
diff changeset
   735
a1c35e6fe735 slightly more formal historic examples;
wenzelm
parents: 58871
diff changeset
   736
lemma "(i $+ j $+ #12 $+ k) = u $+ #15 $+ y" apply simp oops
a1c35e6fe735 slightly more formal historic examples;
wenzelm
parents: 58871
diff changeset
   737
lemma "(i $+ j $* #2 $+ #12 $+ k) = j $+ #5 $+ y" apply simp oops
a1c35e6fe735 slightly more formal historic examples;
wenzelm
parents: 58871
diff changeset
   738
a1c35e6fe735 slightly more formal historic examples;
wenzelm
parents: 58871
diff changeset
   739
lemma "#2 $* y $+ #3 $* z $+ #6 $* w $+ #2 $* y $+ #3 $* z $+ #2 $* u = #2 $* y' $+ #3 $* z' $+ #6 $* w' $+ #2 $* y' $+ #3 $* z' $+ u $+ vv" apply simp oops
a1c35e6fe735 slightly more formal historic examples;
wenzelm
parents: 58871
diff changeset
   740
a1c35e6fe735 slightly more formal historic examples;
wenzelm
parents: 58871
diff changeset
   741
lemma "a $+ $-(b$+c) $+ b = d" apply simp oops
a1c35e6fe735 slightly more formal historic examples;
wenzelm
parents: 58871
diff changeset
   742
lemma "a $+ $-(b$+c) $- b = d" apply simp oops
a1c35e6fe735 slightly more formal historic examples;
wenzelm
parents: 58871
diff changeset
   743
60770
240563fbf41d isabelle update_cartouches;
wenzelm
parents: 59748
diff changeset
   744
text \<open>negative numerals\<close>
59748
a1c35e6fe735 slightly more formal historic examples;
wenzelm
parents: 58871
diff changeset
   745
lemma "(i $+ j $+ #-2 $+ k) $- (u $+ #5 $+ y) = zz" apply simp oops
a1c35e6fe735 slightly more formal historic examples;
wenzelm
parents: 58871
diff changeset
   746
lemma "(i $+ j $+ #-3 $+ k) $< u $+ #5 $+ y" apply simp oops
a1c35e6fe735 slightly more formal historic examples;
wenzelm
parents: 58871
diff changeset
   747
lemma "(i $+ j $+ #3 $+ k) $< u $+ #-6 $+ y" apply simp oops
a1c35e6fe735 slightly more formal historic examples;
wenzelm
parents: 58871
diff changeset
   748
lemma "(i $+ j $+ #-12 $+ k) $- #15 = y" apply simp oops
a1c35e6fe735 slightly more formal historic examples;
wenzelm
parents: 58871
diff changeset
   749
lemma "(i $+ j $+ #12 $+ k) $- #-15 = y" apply simp oops
a1c35e6fe735 slightly more formal historic examples;
wenzelm
parents: 58871
diff changeset
   750
lemma "(i $+ j $+ #-12 $+ k) $- #-15 = y" apply simp oops
a1c35e6fe735 slightly more formal historic examples;
wenzelm
parents: 58871
diff changeset
   751
60770
240563fbf41d isabelle update_cartouches;
wenzelm
parents: 59748
diff changeset
   752
text \<open>Multiplying separated numerals\<close>
59748
a1c35e6fe735 slightly more formal historic examples;
wenzelm
parents: 58871
diff changeset
   753
lemma "#6 $* ($# x $* #2) =  uu" apply simp oops
a1c35e6fe735 slightly more formal historic examples;
wenzelm
parents: 58871
diff changeset
   754
lemma "#4 $* ($# x $* $# x) $* (#2 $* $# x) =  uu" apply simp oops
a1c35e6fe735 slightly more formal historic examples;
wenzelm
parents: 58871
diff changeset
   755
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   756
end