src/ZF/Bin.thy
author wenzelm
Wed, 27 Mar 2013 16:38:25 +0100
changeset 51553 63327f679cff
parent 48891 c0eafbd55de3
child 58022 464c1815fde9
permissions -rw-r--r--
more ambitious Goal.skip_proofs: covers Goal.prove forms as well, and do not insist in quick_and_dirty (for the sake of Isabelle/jEdit);
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
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    16
header{*Arithmetic on Binary Integers*}
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
45703
c7a13ce60161 renamed inner syntax categories "num" to "num_token" and "xnum" to "xnum_token";
wenzelm
parents: 35123
diff changeset
   104
  "_Int"    :: "xnum_token => i"        ("_")
35112
ff6f60e6ab85 numeral syntax: clarify parse trees vs. actual terms;
wenzelm
parents: 32960
diff changeset
   105
48891
c0eafbd55de3 prefer ML_file over old uses;
wenzelm
parents: 46953
diff changeset
   106
ML_file "Tools/numeral_syntax.ML"
35123
e286d5df187a modernized structures;
wenzelm
parents: 35112
diff changeset
   107
setup Numeral_Syntax.setup
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   108
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   109
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   110
declare bin.intros [simp,TC]
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   111
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   112
lemma NCons_Pls_0: "NCons(Pls,0) = Pls"
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   113
by simp
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   114
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   115
lemma NCons_Pls_1: "NCons(Pls,1) = Pls BIT 1"
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   116
by simp
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   117
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   118
lemma NCons_Min_0: "NCons(Min,0) = Min BIT 0"
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   119
by simp
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   120
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   121
lemma NCons_Min_1: "NCons(Min,1) = Min"
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   122
by simp
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   123
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   124
lemma NCons_BIT: "NCons(w BIT x,b) = w BIT x BIT b"
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   125
by (simp add: bin.case_eqns)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   126
46820
c656222c4dc1 mathematical symbols instead of ASCII
paulson
parents: 45703
diff changeset
   127
lemmas NCons_simps [simp] =
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   128
    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
   129
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   130
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   131
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   132
(** Type checking **)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   133
46953
2b6e55924af3 replacing ":" by "\<in>"
paulson
parents: 46821
diff changeset
   134
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
   135
apply (induct_tac "w")
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   136
apply (simp_all add: bool_into_nat)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   137
done
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   138
46953
2b6e55924af3 replacing ":" by "\<in>"
paulson
parents: 46821
diff changeset
   139
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
   140
by (induct_tac "w", auto)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   141
46953
2b6e55924af3 replacing ":" by "\<in>"
paulson
parents: 46821
diff changeset
   142
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
   143
by (induct_tac "w", auto)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   144
46953
2b6e55924af3 replacing ":" by "\<in>"
paulson
parents: 46821
diff changeset
   145
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
   146
by (induct_tac "w", auto)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   147
46953
2b6e55924af3 replacing ":" by "\<in>"
paulson
parents: 46821
diff changeset
   148
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
   149
by (induct_tac "w", auto)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   150
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   151
(*This proof is complicated by the mutual recursion*)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   152
lemma bin_add_type [rule_format,TC]:
46953
2b6e55924af3 replacing ":" by "\<in>"
paulson
parents: 46821
diff changeset
   153
     "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
   154
apply (unfold bin_add_def)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   155
apply (induct_tac "v")
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   156
apply (rule_tac [3] ballI)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   157
apply (rename_tac [3] "w'")
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   158
apply (induct_tac [3] "w'")
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   159
apply (simp_all add: NCons_type)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   160
done
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   161
46953
2b6e55924af3 replacing ":" by "\<in>"
paulson
parents: 46821
diff changeset
   162
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
   163
by (induct_tac "v", auto)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   164
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   165
46820
c656222c4dc1 mathematical symbols instead of ASCII
paulson
parents: 45703
diff changeset
   166
subsubsection{*The Carry and Borrow Functions,
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   167
            @{term bin_succ} and @{term bin_pred}*}
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   168
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   169
(*NCons preserves the integer value of its argument*)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   170
lemma integ_of_NCons [simp]:
46953
2b6e55924af3 replacing ":" by "\<in>"
paulson
parents: 46821
diff changeset
   171
     "[| 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
   172
apply (erule bin.cases)
46820
c656222c4dc1 mathematical symbols instead of ASCII
paulson
parents: 45703
diff changeset
   173
apply (auto elim!: boolE)
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   174
done
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   175
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   176
lemma integ_of_succ [simp]:
46953
2b6e55924af3 replacing ":" by "\<in>"
paulson
parents: 46821
diff changeset
   177
     "w \<in> bin ==> integ_of(bin_succ(w)) = $#1 $+ integ_of(w)"
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   178
apply (erule bin.induct)
46820
c656222c4dc1 mathematical symbols instead of ASCII
paulson
parents: 45703
diff changeset
   179
apply (auto simp add: zadd_ac elim!: boolE)
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   180
done
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   181
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   182
lemma integ_of_pred [simp]:
46953
2b6e55924af3 replacing ":" by "\<in>"
paulson
parents: 46821
diff changeset
   183
     "w \<in> bin ==> integ_of(bin_pred(w)) = $- ($#1) $+ integ_of(w)"
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   184
apply (erule bin.induct)
46820
c656222c4dc1 mathematical symbols instead of ASCII
paulson
parents: 45703
diff changeset
   185
apply (auto simp add: zadd_ac elim!: boolE)
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   186
done
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   187
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   188
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   189
subsubsection{*@{term bin_minus}: Unary Negation of Binary Integers*}
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   190
46953
2b6e55924af3 replacing ":" by "\<in>"
paulson
parents: 46821
diff changeset
   191
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
   192
apply (erule bin.induct)
46820
c656222c4dc1 mathematical symbols instead of ASCII
paulson
parents: 45703
diff changeset
   193
apply (auto simp add: zadd_ac zminus_zadd_distrib  elim!: boolE)
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   194
done
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   195
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   196
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   197
subsubsection{*@{term bin_add}: Binary Addition*}
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   198
46953
2b6e55924af3 replacing ":" by "\<in>"
paulson
parents: 46821
diff changeset
   199
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
   200
by (unfold bin_add_def, simp)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   201
46953
2b6e55924af3 replacing ":" by "\<in>"
paulson
parents: 46821
diff changeset
   202
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
   203
apply (unfold bin_add_def)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   204
apply (erule bin.induct, auto)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   205
done
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   206
46953
2b6e55924af3 replacing ":" by "\<in>"
paulson
parents: 46821
diff changeset
   207
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
   208
by (unfold bin_add_def, simp)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   209
46953
2b6e55924af3 replacing ":" by "\<in>"
paulson
parents: 46821
diff changeset
   210
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
   211
apply (unfold bin_add_def)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   212
apply (erule bin.induct, auto)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   213
done
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   214
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   215
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
   216
by (unfold bin_add_def, simp)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   217
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   218
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
   219
by (unfold bin_add_def, simp)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   220
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   221
lemma bin_add_BIT_BIT [simp]:
46953
2b6e55924af3 replacing ":" by "\<in>"
paulson
parents: 46821
diff changeset
   222
     "[| w \<in> bin;  y \<in> bool |]
46820
c656222c4dc1 mathematical symbols instead of ASCII
paulson
parents: 45703
diff changeset
   223
      ==> bin_add(v BIT x, w BIT y) =
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   224
          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
   225
by (unfold bin_add_def, simp)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   226
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   227
lemma integ_of_add [rule_format]:
46953
2b6e55924af3 replacing ":" by "\<in>"
paulson
parents: 46821
diff changeset
   228
     "v \<in> bin ==>
46820
c656222c4dc1 mathematical symbols instead of ASCII
paulson
parents: 45703
diff changeset
   229
          \<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
   230
apply (erule bin.induct, simp, simp)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   231
apply (rule ballI)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   232
apply (induct_tac "wa")
46820
c656222c4dc1 mathematical symbols instead of ASCII
paulson
parents: 45703
diff changeset
   233
apply (auto simp add: zadd_ac elim!: boolE)
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   234
done
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   235
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   236
(*Subtraction*)
46820
c656222c4dc1 mathematical symbols instead of ASCII
paulson
parents: 45703
diff changeset
   237
lemma diff_integ_of_eq:
46953
2b6e55924af3 replacing ":" by "\<in>"
paulson
parents: 46821
diff changeset
   238
     "[| v \<in> bin;  w \<in> bin |]
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   239
      ==> 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
   240
apply (unfold zdiff_def)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   241
apply (simp add: integ_of_add integ_of_minus)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   242
done
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   243
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   244
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   245
subsubsection{*@{term bin_mult}: Binary Multiplication*}
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   246
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   247
lemma integ_of_mult:
46953
2b6e55924af3 replacing ":" by "\<in>"
paulson
parents: 46821
diff changeset
   248
     "[| v \<in> bin;  w \<in> bin |]
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   249
      ==> integ_of(bin_mult(v,w)) = integ_of(v) $* integ_of(w)"
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   250
apply (induct_tac "v", simp)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   251
apply (simp add: integ_of_minus)
46820
c656222c4dc1 mathematical symbols instead of ASCII
paulson
parents: 45703
diff changeset
   252
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
   253
done
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   254
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   255
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   256
subsection{*Computations*}
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   257
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   258
(** extra rules for bin_succ, bin_pred **)
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 bin_succ_1: "bin_succ(w BIT 1) = bin_succ(w) BIT 0"
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   261
by simp
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   262
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   263
lemma bin_succ_0: "bin_succ(w BIT 0) = NCons(w,1)"
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   264
by simp
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   265
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   266
lemma bin_pred_1: "bin_pred(w BIT 1) = NCons(w,0)"
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   267
by simp
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   268
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   269
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
   270
by simp
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   271
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   272
(** extra rules for bin_minus **)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   273
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   274
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
   275
by simp
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   276
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   277
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
   278
by simp
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   279
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   280
(** extra rules for bin_add **)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   281
46953
2b6e55924af3 replacing ":" by "\<in>"
paulson
parents: 46821
diff changeset
   282
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
   283
                     NCons(bin_add(v, bin_succ(w)), 0)"
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   284
by simp
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   285
46953
2b6e55924af3 replacing ":" by "\<in>"
paulson
parents: 46821
diff changeset
   286
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
   287
                     NCons(bin_add(v,w), 1)"
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
46953
2b6e55924af3 replacing ":" by "\<in>"
paulson
parents: 46821
diff changeset
   290
lemma bin_add_BIT_0: "[| w \<in> bin;  y \<in> bool |]
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   291
      ==> 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
   292
by simp
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   293
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   294
(** extra rules for bin_mult **)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   295
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   296
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
   297
by simp
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   298
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   299
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
   300
by simp
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   301
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   302
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   303
(** Simplification rules with integer constants **)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   304
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   305
lemma int_of_0: "$#0 = #0"
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   306
by simp
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   307
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   308
lemma int_of_succ: "$# succ(n) = #1 $+ $#n"
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   309
by (simp add: int_of_add [symmetric] natify_succ)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   310
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   311
lemma zminus_0 [simp]: "$- #0 = #0"
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   312
by simp
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   313
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   314
lemma zadd_0_intify [simp]: "#0 $+ z = intify(z)"
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   315
by simp
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   316
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   317
lemma zadd_0_right_intify [simp]: "z $+ #0 = intify(z)"
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   318
by simp
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   319
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   320
lemma zmult_1_intify [simp]: "#1 $* z = intify(z)"
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   321
by simp
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   322
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   323
lemma zmult_1_right_intify [simp]: "z $* #1 = intify(z)"
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   324
by (subst zmult_commute, simp)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   325
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   326
lemma zmult_0 [simp]: "#0 $* z = #0"
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   327
by simp
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   328
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   329
lemma zmult_0_right [simp]: "z $* #0 = #0"
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   330
by (subst zmult_commute, simp)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   331
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   332
lemma zmult_minus1 [simp]: "#-1 $* z = $-z"
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   333
by (simp add: zcompare_rls)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   334
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   335
lemma zmult_minus1_right [simp]: "z $* #-1 = $-z"
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   336
apply (subst zmult_commute)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   337
apply (rule zmult_minus1)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   338
done
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   339
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   340
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   341
subsection{*Simplification Rules for Comparison of Binary Numbers*}
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   342
text{*Thanks to Norbert Voelker*}
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   343
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   344
(** Equals (=) **)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   345
46820
c656222c4dc1 mathematical symbols instead of ASCII
paulson
parents: 45703
diff changeset
   346
lemma eq_integ_of_eq:
46953
2b6e55924af3 replacing ":" by "\<in>"
paulson
parents: 46821
diff changeset
   347
     "[| v \<in> bin;  w \<in> bin |]
46821
ff6b0c1087f2 Using mathematical notation for <-> and cardinal arithmetic
paulson
parents: 46820
diff changeset
   348
      ==> ((integ_of(v)) = integ_of(w)) \<longleftrightarrow>
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   349
          iszero (integ_of (bin_add (v, bin_minus(w))))"
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   350
apply (unfold iszero_def)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   351
apply (simp add: zcompare_rls integ_of_add integ_of_minus)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   352
done
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   353
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   354
lemma iszero_integ_of_Pls: "iszero (integ_of(Pls))"
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   355
by (unfold iszero_def, simp)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   356
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   357
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   358
lemma nonzero_integ_of_Min: "~ iszero (integ_of(Min))"
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   359
apply (unfold iszero_def)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   360
apply (simp add: zminus_equation)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   361
done
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   362
46820
c656222c4dc1 mathematical symbols instead of ASCII
paulson
parents: 45703
diff changeset
   363
lemma iszero_integ_of_BIT:
46953
2b6e55924af3 replacing ":" by "\<in>"
paulson
parents: 46821
diff changeset
   364
     "[| w \<in> bin; x \<in> bool |]
46821
ff6b0c1087f2 Using mathematical notation for <-> and cardinal arithmetic
paulson
parents: 46820
diff changeset
   365
      ==> 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
   366
apply (unfold iszero_def, simp)
46820
c656222c4dc1 mathematical symbols instead of ASCII
paulson
parents: 45703
diff changeset
   367
apply (subgoal_tac "integ_of (w) \<in> int")
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   368
apply typecheck
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   369
apply (drule int_cases)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   370
apply (safe elim!: boolE)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   371
apply (simp_all (asm_lr) add: zcompare_rls zminus_zadd_distrib [symmetric]
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   372
                     int_of_add [symmetric])
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   373
done
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   374
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   375
lemma iszero_integ_of_0:
46953
2b6e55924af3 replacing ":" by "\<in>"
paulson
parents: 46821
diff changeset
   376
     "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
   377
by (simp only: iszero_integ_of_BIT, blast)
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   378
46953
2b6e55924af3 replacing ":" by "\<in>"
paulson
parents: 46821
diff changeset
   379
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
   380
by (simp only: iszero_integ_of_BIT, blast)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   381
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   382
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   383
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   384
(** Less-than (<) **)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   385
46820
c656222c4dc1 mathematical symbols instead of ASCII
paulson
parents: 45703
diff changeset
   386
lemma less_integ_of_eq_neg:
46953
2b6e55924af3 replacing ":" by "\<in>"
paulson
parents: 46821
diff changeset
   387
     "[| v \<in> bin;  w \<in> bin |]
46820
c656222c4dc1 mathematical symbols instead of ASCII
paulson
parents: 45703
diff changeset
   388
      ==> integ_of(v) $< integ_of(w)
46821
ff6b0c1087f2 Using mathematical notation for <-> and cardinal arithmetic
paulson
parents: 46820
diff changeset
   389
          \<longleftrightarrow> znegative (integ_of (bin_add (v, bin_minus(w))))"
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   390
apply (unfold zless_def zdiff_def)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   391
apply (simp add: integ_of_minus integ_of_add)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   392
done
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   393
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   394
lemma not_neg_integ_of_Pls: "~ znegative (integ_of(Pls))"
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   395
by simp
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   396
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   397
lemma neg_integ_of_Min: "znegative (integ_of(Min))"
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   398
by simp
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   399
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   400
lemma neg_integ_of_BIT:
46953
2b6e55924af3 replacing ":" by "\<in>"
paulson
parents: 46821
diff changeset
   401
     "[| w \<in> bin; x \<in> bool |]
46821
ff6b0c1087f2 Using mathematical notation for <-> and cardinal arithmetic
paulson
parents: 46820
diff changeset
   402
      ==> znegative (integ_of (w BIT x)) \<longleftrightarrow> znegative (integ_of(w))"
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   403
apply simp
46820
c656222c4dc1 mathematical symbols instead of ASCII
paulson
parents: 45703
diff changeset
   404
apply (subgoal_tac "integ_of (w) \<in> int")
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   405
apply typecheck
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   406
apply (drule int_cases)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   407
apply (auto elim!: boolE simp add: int_of_add [symmetric]  zcompare_rls)
46820
c656222c4dc1 mathematical symbols instead of ASCII
paulson
parents: 45703
diff changeset
   408
apply (simp_all add: zminus_zadd_distrib [symmetric] zdiff_def
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   409
                     int_of_add [symmetric])
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   410
apply (subgoal_tac "$#1 $- $# succ (succ (n #+ n)) = $- $# succ (n #+ n) ")
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   411
 apply (simp add: zdiff_def)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   412
apply (simp add: equation_zminus int_of_diff [symmetric])
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   413
done
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   414
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   415
(** Less-than-or-equals (<=) **)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   416
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   417
lemma le_integ_of_eq_not_less:
46821
ff6b0c1087f2 Using mathematical notation for <-> and cardinal arithmetic
paulson
parents: 46820
diff changeset
   418
     "(integ_of(x) $<= (integ_of(w))) \<longleftrightarrow> ~ (integ_of(w) $< (integ_of(x)))"
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   419
by (simp add: not_zless_iff_zle [THEN iff_sym])
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   420
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   421
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   422
(*Delete the original rewrites, with their clumsy conditional expressions*)
46820
c656222c4dc1 mathematical symbols instead of ASCII
paulson
parents: 45703
diff changeset
   423
declare bin_succ_BIT [simp del]
c656222c4dc1 mathematical symbols instead of ASCII
paulson
parents: 45703
diff changeset
   424
        bin_pred_BIT [simp del]
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   425
        bin_minus_BIT [simp del]
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   426
        NCons_Pls [simp del]
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   427
        NCons_Min [simp del]
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   428
        bin_adder_BIT [simp del]
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   429
        bin_mult_BIT [simp del]
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   430
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   431
(*Hide the binary representation of integer constants*)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   432
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
   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
lemmas bin_arith_extra_simps =
46820
c656222c4dc1 mathematical symbols instead of ASCII
paulson
parents: 45703
diff changeset
   436
     integ_of_add [symmetric]
c656222c4dc1 mathematical symbols instead of ASCII
paulson
parents: 45703
diff changeset
   437
     integ_of_minus [symmetric]
c656222c4dc1 mathematical symbols instead of ASCII
paulson
parents: 45703
diff changeset
   438
     integ_of_mult [symmetric]
c656222c4dc1 mathematical symbols instead of ASCII
paulson
parents: 45703
diff changeset
   439
     bin_succ_1 bin_succ_0
c656222c4dc1 mathematical symbols instead of ASCII
paulson
parents: 45703
diff changeset
   440
     bin_pred_1 bin_pred_0
c656222c4dc1 mathematical symbols instead of ASCII
paulson
parents: 45703
diff changeset
   441
     bin_minus_1 bin_minus_0
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   442
     bin_add_Pls_right bin_add_Min_right
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   443
     bin_add_BIT_0 bin_add_BIT_10 bin_add_BIT_11
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   444
     diff_integ_of_eq
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   445
     bin_mult_1 bin_mult_0 NCons_simps
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
(*For making a minimal simpset, one must include these default simprules
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   449
  of thy.  Also include simp_thms, or at least (~False)=True*)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   450
lemmas bin_arith_simps =
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   451
     bin_pred_Pls bin_pred_Min
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   452
     bin_succ_Pls bin_succ_Min
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   453
     bin_add_Pls bin_add_Min
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   454
     bin_minus_Pls bin_minus_Min
46820
c656222c4dc1 mathematical symbols instead of ASCII
paulson
parents: 45703
diff changeset
   455
     bin_mult_Pls bin_mult_Min
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   456
     bin_arith_extra_simps
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   457
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   458
(*Simplification of relational operations*)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   459
lemmas bin_rel_simps =
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   460
     eq_integ_of_eq iszero_integ_of_Pls nonzero_integ_of_Min
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   461
     iszero_integ_of_0 iszero_integ_of_1
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   462
     less_integ_of_eq_neg
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   463
     not_neg_integ_of_Pls neg_integ_of_Min neg_integ_of_BIT
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   464
     le_integ_of_eq_not_less
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   465
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   466
declare bin_arith_simps [simp]
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   467
declare bin_rel_simps [simp]
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   468
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   469
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   470
(** Simplification of arithmetic when nested to the right **)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   471
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   472
lemma add_integ_of_left [simp]:
46953
2b6e55924af3 replacing ":" by "\<in>"
paulson
parents: 46821
diff changeset
   473
     "[| v \<in> bin;  w \<in> bin |]
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   474
      ==> 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
   475
by (simp add: zadd_assoc [symmetric])
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   476
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   477
lemma mult_integ_of_left [simp]:
46953
2b6e55924af3 replacing ":" by "\<in>"
paulson
parents: 46821
diff changeset
   478
     "[| v \<in> bin;  w \<in> bin |]
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   479
      ==> 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
   480
by (simp add: zmult_assoc [symmetric])
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   481
46820
c656222c4dc1 mathematical symbols instead of ASCII
paulson
parents: 45703
diff changeset
   482
lemma add_integ_of_diff1 [simp]:
46953
2b6e55924af3 replacing ":" by "\<in>"
paulson
parents: 46821
diff changeset
   483
    "[| v \<in> bin;  w \<in> bin |]
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   484
      ==> 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
   485
apply (unfold zdiff_def)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   486
apply (rule add_integ_of_left, auto)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   487
done
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   488
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   489
lemma add_integ_of_diff2 [simp]:
46953
2b6e55924af3 replacing ":" by "\<in>"
paulson
parents: 46821
diff changeset
   490
     "[| v \<in> bin;  w \<in> bin |]
46820
c656222c4dc1 mathematical symbols instead of ASCII
paulson
parents: 45703
diff changeset
   491
      ==> integ_of(v) $+ (c $- integ_of(w)) =
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   492
          integ_of (bin_add (v, bin_minus(w))) $+ (c)"
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   493
apply (subst diff_integ_of_eq [symmetric])
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   494
apply (simp_all add: zdiff_def zadd_ac)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   495
done
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   496
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   497
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   498
(** More for integer constants **)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   499
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   500
declare int_of_0 [simp] int_of_succ [simp]
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 zdiff0 [simp]: "#0 $- x = $-x"
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   503
by (simp add: zdiff_def)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   504
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   505
lemma zdiff0_right [simp]: "x $- #0 = intify(x)"
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   506
by (simp add: zdiff_def)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   507
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   508
lemma zdiff_self [simp]: "x $- x = #0"
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   509
by (simp add: zdiff_def)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   510
46953
2b6e55924af3 replacing ":" by "\<in>"
paulson
parents: 46821
diff changeset
   511
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
   512
by (simp add: zless_def)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   513
46953
2b6e55924af3 replacing ":" by "\<in>"
paulson
parents: 46821
diff changeset
   514
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
   515
by (simp add: zless_def)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   516
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   517
lemma zero_zle_int_of [simp]: "#0 $<= $# n"
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   518
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
   519
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   520
lemma nat_of_0 [simp]: "nat_of(#0) = 0"
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   521
by (simp only: natify_0 int_of_0 [symmetric] nat_of_int_of)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   522
46953
2b6e55924af3 replacing ":" by "\<in>"
paulson
parents: 46821
diff changeset
   523
lemma nat_le_int0_lemma: "[| z $<= $#0; z \<in> int |] ==> nat_of(z) = 0"
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   524
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
   525
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   526
lemma nat_le_int0: "z $<= $#0 ==> nat_of(z) = 0"
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   527
apply (subgoal_tac "nat_of (intify (z)) = 0")
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   528
apply (rule_tac [2] nat_le_int0_lemma, auto)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   529
done
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   530
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   531
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
   532
by (rule not_znegative_imp_zero, auto)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   533
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   534
lemma nat_of_zminus_int_of: "nat_of($- $# n) = 0"
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   535
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
   536
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   537
lemma int_of_nat_of: "#0 $<= z ==> $# nat_of(z) = intify(z)"
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   538
apply (rule not_zneg_nat_of_intify)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   539
apply (simp add: znegative_iff_zless_0 not_zless_iff_zle)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   540
done
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   541
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   542
declare int_of_nat_of [simp] nat_of_zminus_int_of [simp]
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_nat_of_if: "$# nat_of(z) = (if #0 $<= z then intify(z) else #0)"
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   545
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
   546
46953
2b6e55924af3 replacing ":" by "\<in>"
paulson
parents: 46821
diff changeset
   547
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
   548
apply (case_tac "znegative (z) ")
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   549
apply (erule_tac [2] not_zneg_nat_of [THEN subst])
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   550
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
   551
            simp add: znegative_iff_zless_0)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   552
done
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   553
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   554
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   555
(** nat_of and zless **)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   556
46820
c656222c4dc1 mathematical symbols instead of ASCII
paulson
parents: 45703
diff changeset
   557
(*An alternative condition is  @{term"$#0 \<subseteq> w"}  *)
46821
ff6b0c1087f2 Using mathematical notation for <-> and cardinal arithmetic
paulson
parents: 46820
diff changeset
   558
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
   559
apply (rule iff_trans)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   560
apply (rule zless_int_of [THEN iff_sym])
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   561
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
   562
apply (auto elim: zless_asym simp add: not_zle_iff_zless)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   563
apply (blast intro: zless_zle_trans)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   564
done
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   565
46821
ff6b0c1087f2 Using mathematical notation for <-> and cardinal arithmetic
paulson
parents: 46820
diff changeset
   566
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
   567
apply (case_tac "$#0 $< z")
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   568
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
   569
done
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   570
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   571
(*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
   572
  unconditional!
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   573
  [The condition "True" is a hack to prevent looping.
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   574
    Conditional rewrite rules are tried after unconditional ones, so a rule
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   575
    like eq_nat_number_of will be tried first to eliminate #mm=#nn.]
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   576
  lemma integ_of_reorient [simp]:
46821
ff6b0c1087f2 Using mathematical notation for <-> and cardinal arithmetic
paulson
parents: 46820
diff changeset
   577
       "True ==> (integ_of(w) = x) \<longleftrightarrow> (x = integ_of(w))"
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   578
  by auto
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   579
*)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   580
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   581
lemma integ_of_minus_reorient [simp]:
46821
ff6b0c1087f2 Using mathematical notation for <-> and cardinal arithmetic
paulson
parents: 46820
diff changeset
   582
     "(integ_of(w) = $- x) \<longleftrightarrow> ($- x = integ_of(w))"
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   583
by auto
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   584
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   585
lemma integ_of_add_reorient [simp]:
46821
ff6b0c1087f2 Using mathematical notation for <-> and cardinal arithmetic
paulson
parents: 46820
diff changeset
   586
     "(integ_of(w) = x $+ y) \<longleftrightarrow> (x $+ y = integ_of(w))"
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   587
by auto
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   588
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   589
lemma integ_of_diff_reorient [simp]:
46821
ff6b0c1087f2 Using mathematical notation for <-> and cardinal arithmetic
paulson
parents: 46820
diff changeset
   590
     "(integ_of(w) = x $- y) \<longleftrightarrow> (x $- y = 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
lemma integ_of_mult_reorient [simp]:
46821
ff6b0c1087f2 Using mathematical notation for <-> and cardinal arithmetic
paulson
parents: 46820
diff changeset
   594
     "(integ_of(w) = x $* y) \<longleftrightarrow> (x $* y = integ_of(w))"
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   595
by auto
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   596
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   597
end