src/HOL/Integ/NatBin.thy
author paulson
Tue, 10 Feb 2004 12:02:11 +0100
changeset 14378 69c4d5997669
parent 14365 3d4df8c166ae
child 14387 e96d5c42c4b0
permissions -rw-r--r--
generic of_nat and of_int functions, and generalization of iszero and neg
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
7032
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
     1
(*  Title:      HOL/NatBin.thy
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
     2
    ID:         $Id$
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
     3
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
     4
    Copyright   1999  University of Cambridge
12838
wenzelm
parents: 12440
diff changeset
     5
*)
7032
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
     6
12838
wenzelm
parents: 12440
diff changeset
     7
header {* Binary arithmetic for the natural numbers *}
7032
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
     8
14353
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
     9
theory NatBin = IntDiv:
7032
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
    10
12838
wenzelm
parents: 12440
diff changeset
    11
text {*
14273
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
    12
  Arithmetic for naturals is reduced to that for the non-negative integers.
12838
wenzelm
parents: 12440
diff changeset
    13
*}
wenzelm
parents: 12440
diff changeset
    14
wenzelm
parents: 12440
diff changeset
    15
instance nat :: number ..
wenzelm
parents: 12440
diff changeset
    16
wenzelm
parents: 12440
diff changeset
    17
defs (overloaded)
14273
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
    18
  nat_number_of_def:
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
    19
     "(number_of::bin => nat) v == nat ((number_of :: bin => int) v)"
12838
wenzelm
parents: 12440
diff changeset
    20
14272
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
    21
14353
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
    22
subsection{*Function @{term nat}: Coercion from Type @{typ int} to @{typ nat}*}
14272
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
    23
14273
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
    24
declare nat_0 [simp] nat_1 [simp]
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
    25
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
    26
lemma nat_number_of [simp]: "nat (number_of w) = number_of w"
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
    27
by (simp add: nat_number_of_def)
14272
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
    28
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
    29
lemma numeral_0_eq_0: "Numeral0 = (0::nat)"
14273
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
    30
by (simp add: nat_number_of_def)
14272
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
    31
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
    32
lemma numeral_1_eq_1: "Numeral1 = (1::nat)"
14273
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
    33
by (simp add: nat_1 nat_number_of_def)
14272
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
    34
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
    35
lemma numeral_1_eq_Suc_0: "Numeral1 = Suc 0"
14273
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
    36
by (simp add: numeral_1_eq_1)
14272
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
    37
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
    38
lemma numeral_2_eq_2: "2 = Suc (Suc 0)"
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
    39
apply (unfold nat_number_of_def)
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
    40
apply (rule nat_2)
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
    41
done
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
    42
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
    43
14273
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
    44
text{*Distributive laws for type @{text nat}.  The others are in theory
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
    45
   @{text IntArith}, but these require div and mod to be defined for type
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
    46
   "int".  They also need some of the lemmas proved above.*}
14272
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
    47
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
    48
lemma nat_div_distrib: "(0::int) <= z ==> nat (z div z') = nat z div nat z'"
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
    49
apply (case_tac "0 <= z'")
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
    50
apply (auto simp add: div_nonneg_neg_le0 DIVISION_BY_ZERO_DIV)
14273
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
    51
apply (case_tac "z' = 0", simp add: DIVISION_BY_ZERO)
14272
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
    52
apply (auto elim!: nonneg_eq_int)
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
    53
apply (rename_tac m m')
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
    54
apply (subgoal_tac "0 <= int m div int m'")
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
    55
 prefer 2 apply (simp add: numeral_0_eq_0 pos_imp_zdiv_nonneg_iff) 
14273
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
    56
apply (rule inj_int [THEN injD], simp)
14272
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
    57
apply (rule_tac r = "int (m mod m') " in quorem_div)
14273
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
    58
 prefer 2 apply force
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
    59
apply (simp add: nat_less_iff [symmetric] quorem_def numeral_0_eq_0 zadd_int 
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
    60
                 zmult_int)
14272
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
    61
done
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
    62
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
    63
(*Fails if z'<0: the LHS collapses to (nat z) but the RHS doesn't*)
14273
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
    64
lemma nat_mod_distrib:
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
    65
     "[| (0::int) <= z;  0 <= z' |] ==> nat (z mod z') = nat z mod nat z'"
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
    66
apply (case_tac "z' = 0", simp add: DIVISION_BY_ZERO)
14272
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
    67
apply (auto elim!: nonneg_eq_int)
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
    68
apply (rename_tac m m')
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
    69
apply (subgoal_tac "0 <= int m mod int m'")
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
    70
 prefer 2 apply (simp add: nat_less_iff numeral_0_eq_0 pos_mod_sign) 
14273
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
    71
apply (rule inj_int [THEN injD], simp)
14272
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
    72
apply (rule_tac q = "int (m div m') " in quorem_mod)
14273
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
    73
 prefer 2 apply force
14272
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
    74
apply (simp add: nat_less_iff [symmetric] quorem_def numeral_0_eq_0 zadd_int zmult_int)
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
    75
done
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
    76
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
    77
14353
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
    78
subsection{*Function @{term int}: Coercion from Type @{typ nat} to @{typ int}*}
14272
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
    79
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
    80
(*"neg" is used in rewrite rules for binary comparisons*)
14273
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
    81
lemma int_nat_number_of:
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
    82
     "int (number_of v :: nat) =  
14378
69c4d5997669 generic of_nat and of_int functions, and generalization of iszero
paulson
parents: 14365
diff changeset
    83
         (if neg (number_of v :: int) then 0  
14272
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
    84
          else (number_of v :: int))"
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
    85
by (simp del: nat_number_of
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
    86
	 add: neg_nat nat_number_of_def not_neg_nat add_assoc)
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
    87
declare int_nat_number_of [simp]
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
    88
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
    89
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
    90
(** Successor **)
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
    91
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
    92
lemma Suc_nat_eq_nat_zadd1: "(0::int) <= z ==> Suc (nat z) = nat (1 + z)"
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
    93
apply (rule sym)
14273
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
    94
apply (simp add: nat_eq_iff int_Suc)
14272
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
    95
done
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
    96
14273
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
    97
lemma Suc_nat_number_of_add:
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
    98
     "Suc (number_of v + n) =  
14378
69c4d5997669 generic of_nat and of_int functions, and generalization of iszero
paulson
parents: 14365
diff changeset
    99
        (if neg (number_of v :: int) then 1+n else number_of (bin_succ v) + n)" 
14272
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   100
by (simp del: nat_number_of 
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   101
         add: nat_number_of_def neg_nat
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   102
              Suc_nat_eq_nat_zadd1 number_of_succ) 
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   103
14273
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   104
lemma Suc_nat_number_of:
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   105
     "Suc (number_of v) =  
14378
69c4d5997669 generic of_nat and of_int functions, and generalization of iszero
paulson
parents: 14365
diff changeset
   106
        (if neg (number_of v :: int) then 1 else number_of (bin_succ v))"
14273
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   107
apply (cut_tac n = 0 in Suc_nat_number_of_add)
14272
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   108
apply (simp cong del: if_weak_cong)
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   109
done
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   110
declare Suc_nat_number_of [simp]
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   111
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   112
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   113
(** Addition **)
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   114
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   115
(*"neg" is used in rewrite rules for binary comparisons*)
14273
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   116
lemma add_nat_number_of:
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   117
     "(number_of v :: nat) + number_of v' =  
14378
69c4d5997669 generic of_nat and of_int functions, and generalization of iszero
paulson
parents: 14365
diff changeset
   118
         (if neg (number_of v :: int) then number_of v'  
69c4d5997669 generic of_nat and of_int functions, and generalization of iszero
paulson
parents: 14365
diff changeset
   119
          else if neg (number_of v' :: int) then number_of v  
14272
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   120
          else number_of (bin_add v v'))"
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   121
by (force dest!: neg_nat
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   122
          simp del: nat_number_of
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   123
          simp add: nat_number_of_def nat_add_distrib [symmetric]) 
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   124
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   125
declare add_nat_number_of [simp]
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   126
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   127
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   128
(** Subtraction **)
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   129
14273
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   130
lemma diff_nat_eq_if:
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   131
     "nat z - nat z' =  
14272
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   132
        (if neg z' then nat z   
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   133
         else let d = z-z' in     
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   134
              if neg d then 0 else nat d)"
14273
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   135
apply (simp add: Let_def nat_diff_distrib [symmetric] neg_eq_less_0 not_neg_eq_ge_0)
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   136
apply (simp add: diff_is_0_eq nat_le_eq_zle)
14272
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   137
done
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   138
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   139
lemma diff_nat_number_of: 
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   140
     "(number_of v :: nat) - number_of v' =  
14378
69c4d5997669 generic of_nat and of_int functions, and generalization of iszero
paulson
parents: 14365
diff changeset
   141
        (if neg (number_of v' :: int) then number_of v  
14272
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   142
         else let d = number_of (bin_add v (bin_minus v')) in     
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   143
              if neg d then 0 else nat d)"
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   144
by (simp del: nat_number_of add: diff_nat_eq_if nat_number_of_def) 
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   145
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   146
declare diff_nat_number_of [simp]
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   147
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   148
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   149
(** Multiplication **)
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   150
14273
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   151
lemma mult_nat_number_of:
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   152
     "(number_of v :: nat) * number_of v' =  
14378
69c4d5997669 generic of_nat and of_int functions, and generalization of iszero
paulson
parents: 14365
diff changeset
   153
       (if neg (number_of v :: int) then 0 else number_of (bin_mult v v'))"
14272
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   154
by (force dest!: neg_nat
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   155
          simp del: nat_number_of
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   156
          simp add: nat_number_of_def nat_mult_distrib [symmetric]) 
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   157
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   158
declare mult_nat_number_of [simp]
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   159
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   160
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   161
(** Quotient **)
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   162
14273
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   163
lemma div_nat_number_of:
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   164
     "(number_of v :: nat)  div  number_of v' =  
14378
69c4d5997669 generic of_nat and of_int functions, and generalization of iszero
paulson
parents: 14365
diff changeset
   165
          (if neg (number_of v :: int) then 0  
14272
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   166
           else nat (number_of v div number_of v'))"
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   167
by (force dest!: neg_nat
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   168
          simp del: nat_number_of
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   169
          simp add: nat_number_of_def nat_div_distrib [symmetric]) 
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   170
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   171
declare div_nat_number_of [simp]
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   172
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   173
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   174
(** Remainder **)
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   175
14273
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   176
lemma mod_nat_number_of:
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   177
     "(number_of v :: nat)  mod  number_of v' =  
14378
69c4d5997669 generic of_nat and of_int functions, and generalization of iszero
paulson
parents: 14365
diff changeset
   178
        (if neg (number_of v :: int) then 0  
69c4d5997669 generic of_nat and of_int functions, and generalization of iszero
paulson
parents: 14365
diff changeset
   179
         else if neg (number_of v' :: int) then number_of v  
14272
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   180
         else nat (number_of v mod number_of v'))"
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   181
by (force dest!: neg_nat
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   182
          simp del: nat_number_of
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   183
          simp add: nat_number_of_def nat_mod_distrib [symmetric]) 
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   184
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   185
declare mod_nat_number_of [simp]
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   186
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   187
ML
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   188
{*
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   189
val nat_number_of_def = thm"nat_number_of_def";
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   190
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   191
val nat_number_of = thm"nat_number_of";
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   192
val numeral_0_eq_0 = thm"numeral_0_eq_0";
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   193
val numeral_1_eq_1 = thm"numeral_1_eq_1";
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   194
val numeral_1_eq_Suc_0 = thm"numeral_1_eq_Suc_0";
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   195
val numeral_2_eq_2 = thm"numeral_2_eq_2";
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   196
val nat_div_distrib = thm"nat_div_distrib";
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   197
val nat_mod_distrib = thm"nat_mod_distrib";
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   198
val int_nat_number_of = thm"int_nat_number_of";
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   199
val Suc_nat_eq_nat_zadd1 = thm"Suc_nat_eq_nat_zadd1";
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   200
val Suc_nat_number_of_add = thm"Suc_nat_number_of_add";
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   201
val Suc_nat_number_of = thm"Suc_nat_number_of";
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   202
val add_nat_number_of = thm"add_nat_number_of";
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   203
val diff_nat_eq_if = thm"diff_nat_eq_if";
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   204
val diff_nat_number_of = thm"diff_nat_number_of";
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   205
val mult_nat_number_of = thm"mult_nat_number_of";
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   206
val div_nat_number_of = thm"div_nat_number_of";
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   207
val mod_nat_number_of = thm"mod_nat_number_of";
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   208
*}
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   209
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   210
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   211
ML
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   212
{*
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   213
structure NatAbstractNumeralsData =
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   214
  struct
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   215
  val dest_eq		= HOLogic.dest_eq o HOLogic.dest_Trueprop o concl_of
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   216
  val is_numeral	= Bin_Simprocs.is_numeral
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   217
  val numeral_0_eq_0    = numeral_0_eq_0
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   218
  val numeral_1_eq_1    = numeral_1_eq_Suc_0
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   219
  val prove_conv        = Bin_Simprocs.prove_conv_nohyps_novars
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   220
  fun norm_tac simps	= ALLGOALS (simp_tac (HOL_ss addsimps simps))
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   221
  val simplify_meta_eq  = Bin_Simprocs.simplify_meta_eq 
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   222
  end;
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   223
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   224
structure NatAbstractNumerals = AbstractNumeralsFun (NatAbstractNumeralsData);
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   225
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   226
val nat_eval_numerals = 
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   227
  map Bin_Simprocs.prep_simproc
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   228
   [("nat_div_eval_numerals", ["(Suc 0) div m"], NatAbstractNumerals.proc div_nat_number_of),
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   229
    ("nat_mod_eval_numerals", ["(Suc 0) mod m"], NatAbstractNumerals.proc mod_nat_number_of)];
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   230
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   231
Addsimprocs nat_eval_numerals;
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   232
*}
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   233
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   234
(*** Comparisons ***)
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   235
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   236
(** Equals (=) **)
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   237
14273
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   238
lemma eq_nat_nat_iff:
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   239
     "[| (0::int) <= z;  0 <= z' |] ==> (nat z = nat z') = (z=z')"
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   240
by (auto elim!: nonneg_eq_int)
14272
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   241
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   242
(*"neg" is used in rewrite rules for binary comparisons*)
14273
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   243
lemma eq_nat_number_of:
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   244
     "((number_of v :: nat) = number_of v') =  
14378
69c4d5997669 generic of_nat and of_int functions, and generalization of iszero
paulson
parents: 14365
diff changeset
   245
      (if neg (number_of v :: int) then (iszero (number_of v' :: int) | neg (number_of v' :: int))  
69c4d5997669 generic of_nat and of_int functions, and generalization of iszero
paulson
parents: 14365
diff changeset
   246
       else if neg (number_of v' :: int) then iszero (number_of v :: int)  
69c4d5997669 generic of_nat and of_int functions, and generalization of iszero
paulson
parents: 14365
diff changeset
   247
       else iszero (number_of (bin_add v (bin_minus v')) :: int))"
14272
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   248
apply (simp only: simp_thms neg_nat not_neg_eq_ge_0 nat_number_of_def
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   249
                  eq_nat_nat_iff eq_number_of_eq nat_0 iszero_def
14273
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   250
            split add: split_if cong add: imp_cong)
14272
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   251
apply (simp only: nat_eq_iff nat_eq_iff2)
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   252
apply (simp add: not_neg_eq_ge_0 [symmetric])
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   253
done
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   254
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   255
declare eq_nat_number_of [simp]
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   256
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   257
(** Less-than (<) **)
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   258
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   259
(*"neg" is used in rewrite rules for binary comparisons*)
14273
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   260
lemma less_nat_number_of:
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   261
     "((number_of v :: nat) < number_of v') =  
14378
69c4d5997669 generic of_nat and of_int functions, and generalization of iszero
paulson
parents: 14365
diff changeset
   262
         (if neg (number_of v :: int) then neg (number_of (bin_minus v') :: int)  
69c4d5997669 generic of_nat and of_int functions, and generalization of iszero
paulson
parents: 14365
diff changeset
   263
          else neg (number_of (bin_add v (bin_minus v')) :: int))"
14272
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   264
apply (simp only: simp_thms neg_nat not_neg_eq_ge_0 nat_number_of_def
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   265
                nat_less_eq_zless less_number_of_eq_neg zless_nat_eq_int_zless
14273
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   266
            cong add: imp_cong, simp) 
14272
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   267
done
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   268
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   269
declare less_nat_number_of [simp]
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   270
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   271
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   272
(*Maps #n to n for n = 0, 1, 2*)
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   273
lemmas numerals = numeral_0_eq_0 numeral_1_eq_1 numeral_2_eq_2
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   274
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   275
14353
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   276
subsection{*General Theorems About Powers Involving Binary Numerals*}
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   277
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   278
text{*We cannot refer to the number @{term 2} in @{text Ring_and_Field.thy}.
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   279
We cannot prove general results about the numeral @{term "-1"}, so we have to
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   280
use @{term "- 1"} instead.*}
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   281
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   282
lemma power2_eq_square: "(a::'a::{semiring,ringpower})\<twosuperior> = a * a"
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   283
  by (simp add: numeral_2_eq_2 Power.power_Suc)
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   284
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   285
lemma [simp]: "(0::'a::{semiring,ringpower})\<twosuperior> = 0"
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   286
  by (simp add: power2_eq_square)
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   287
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   288
lemma [simp]: "(1::'a::{semiring,ringpower})\<twosuperior> = 1"
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   289
  by (simp add: power2_eq_square)
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   290
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   291
text{*Squares of literal numerals will be evaluated.*}
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   292
declare power2_eq_square [of "number_of w", standard, simp]
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   293
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   294
lemma zero_le_power2 [simp]: "0 \<le> (a\<twosuperior>::'a::{ordered_ring,ringpower})"
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   295
  by (simp add: power2_eq_square zero_le_square)
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   296
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   297
lemma zero_less_power2 [simp]:
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   298
     "(0 < a\<twosuperior>) = (a \<noteq> (0::'a::{ordered_ring,ringpower}))"
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   299
  by (force simp add: power2_eq_square zero_less_mult_iff linorder_neq_iff)
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   300
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   301
lemma zero_eq_power2 [simp]:
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   302
     "(a\<twosuperior> = 0) = (a = (0::'a::{ordered_ring,ringpower}))"
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   303
  by (force simp add: power2_eq_square mult_eq_0_iff)
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   304
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   305
lemma abs_power2 [simp]:
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   306
     "abs(a\<twosuperior>) = (a\<twosuperior>::'a::{ordered_ring,ringpower})"
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   307
  by (simp add: power2_eq_square abs_mult abs_mult_self)
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   308
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   309
lemma power2_abs [simp]:
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   310
     "(abs a)\<twosuperior> = (a\<twosuperior>::'a::{ordered_ring,ringpower})"
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   311
  by (simp add: power2_eq_square abs_mult_self)
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   312
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   313
lemma power2_minus [simp]:
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   314
     "(- a)\<twosuperior> = (a\<twosuperior>::'a::{ring,ringpower})"
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   315
  by (simp add: power2_eq_square)
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   316
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   317
lemma power_minus1_even: "(- 1) ^ (2*n) = (1::'a::{ring,ringpower})"
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   318
apply (induct_tac "n")
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   319
apply (auto simp add: power_Suc power_add)
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   320
done
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   321
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   322
lemma power_minus_even [simp]:
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   323
     "(-a) ^ (2*n) = (a::'a::{ring,ringpower}) ^ (2*n)"
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   324
by (simp add: power_minus1_even power_minus [of a]) 
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   325
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   326
lemma zero_le_even_power:
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   327
     "0 \<le> (a::'a::{ordered_ring,ringpower}) ^ (2*n)"
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   328
proof (induct "n")
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   329
  case 0
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   330
    show ?case by (simp add: zero_le_one)
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   331
next
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   332
  case (Suc n)
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   333
    have "a ^ (2 * Suc n) = (a*a) * a ^ (2*n)" 
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   334
      by (simp add: mult_ac power_add power2_eq_square)
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   335
    thus ?case
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   336
      by (simp add: prems zero_le_square zero_le_mult_iff)
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   337
qed
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   338
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   339
lemma odd_power_less_zero:
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   340
     "(a::'a::{ordered_ring,ringpower}) < 0 ==> a ^ Suc(2*n) < 0"
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   341
proof (induct "n")
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   342
  case 0
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   343
    show ?case by (simp add: Power.power_Suc)
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   344
next
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   345
  case (Suc n)
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   346
    have "a ^ Suc (2 * Suc n) = (a*a) * a ^ Suc(2*n)" 
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   347
      by (simp add: mult_ac power_add power2_eq_square Power.power_Suc)
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   348
    thus ?case
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   349
      by (simp add: prems mult_less_0_iff mult_neg)
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   350
qed
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   351
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   352
lemma odd_0_le_power_imp_0_le:
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   353
     "0 \<le> a  ^ Suc(2*n) ==> 0 \<le> (a::'a::{ordered_ring,ringpower})"
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   354
apply (insert odd_power_less_zero [of a n]) 
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   355
apply (force simp add: linorder_not_less [symmetric]) 
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   356
done
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   357
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   358
14272
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   359
(** Nat **)
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   360
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   361
lemma Suc_pred': "0 < n ==> n = Suc(n - 1)"
14273
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   362
by (simp add: numerals)
14272
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   363
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   364
(*Expresses a natural number constant as the Suc of another one.
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   365
  NOT suitable for rewriting because n recurs in the condition.*)
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   366
lemmas expand_Suc = Suc_pred' [of "number_of v", standard]
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   367
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   368
(** Arith **)
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   369
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   370
lemma Suc_eq_add_numeral_1: "Suc n = n + 1"
14273
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   371
by (simp add: numerals)
14272
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   372
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   373
(* These two can be useful when m = number_of... *)
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   374
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   375
lemma add_eq_if: "(m::nat) + n = (if m=0 then n else Suc ((m - 1) + n))"
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   376
apply (case_tac "m")
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   377
apply (simp_all add: numerals)
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   378
done
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   379
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   380
lemma mult_eq_if: "(m::nat) * n = (if m=0 then 0 else n + ((m - 1) * n))"
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   381
apply (case_tac "m")
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   382
apply (simp_all add: numerals)
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   383
done
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   384
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   385
lemma power_eq_if: "(p ^ m :: nat) = (if m=0 then 1 else p * (p ^ (m - 1)))"
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   386
apply (case_tac "m")
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   387
apply (simp_all add: numerals)
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   388
done
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   389
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   390
lemma diff_less': "[| 0<n; 0<m |] ==> m - n < (m::nat)"
14273
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   391
by (simp add: diff_less numerals)
14272
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   392
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   393
declare diff_less' [of "number_of v", standard, simp]
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   394
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   395
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   396
(*** Comparisons involving (0::nat) ***)
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   397
14273
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   398
lemma eq_number_of_0:
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   399
     "(number_of v = (0::nat)) =  
14378
69c4d5997669 generic of_nat and of_int functions, and generalization of iszero
paulson
parents: 14365
diff changeset
   400
      (if neg (number_of v :: int) then True else iszero (number_of v :: int))"
14273
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   401
apply (simp add: numeral_0_eq_0 [symmetric] iszero_0)
14272
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   402
done
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   403
14273
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   404
lemma eq_0_number_of:
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   405
     "((0::nat) = number_of v) =  
14378
69c4d5997669 generic of_nat and of_int functions, and generalization of iszero
paulson
parents: 14365
diff changeset
   406
      (if neg (number_of v :: int) then True else iszero (number_of v :: int))"
14272
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   407
apply (rule trans [OF eq_sym_conv eq_number_of_0])
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   408
done
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   409
14273
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   410
lemma less_0_number_of:
14378
69c4d5997669 generic of_nat and of_int functions, and generalization of iszero
paulson
parents: 14365
diff changeset
   411
     "((0::nat) < number_of v) = neg (number_of (bin_minus v) :: int)"
14273
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   412
by (simp add: numeral_0_eq_0 [symmetric])
14272
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   413
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   414
(*Simplification already handles n<0, n<=0 and 0<=n.*)
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   415
declare eq_number_of_0 [simp] eq_0_number_of [simp] less_0_number_of [simp]
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   416
14378
69c4d5997669 generic of_nat and of_int functions, and generalization of iszero
paulson
parents: 14365
diff changeset
   417
lemma neg_imp_number_of_eq_0: "neg (number_of v :: int) ==> number_of v = (0::nat)"
14273
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   418
by (simp add: numeral_0_eq_0 [symmetric] iszero_0)
14272
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   419
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   420
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   421
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   422
(*** Comparisons involving Suc ***)
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   423
14273
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   424
lemma eq_number_of_Suc [simp]:
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   425
     "(number_of v = Suc n) =  
14272
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   426
        (let pv = number_of (bin_pred v) in  
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   427
         if neg pv then False else nat pv = n)"
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   428
apply (simp only: simp_thms Let_def neg_eq_less_0 linorder_not_less 
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   429
                  number_of_pred nat_number_of_def 
14273
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   430
            split add: split_if)
14272
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   431
apply (rule_tac x = "number_of v" in spec)
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   432
apply (auto simp add: nat_eq_iff)
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   433
done
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   434
14273
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   435
lemma Suc_eq_number_of [simp]:
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   436
     "(Suc n = number_of v) =  
14272
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   437
        (let pv = number_of (bin_pred v) in  
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   438
         if neg pv then False else nat pv = n)"
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   439
apply (rule trans [OF eq_sym_conv eq_number_of_Suc])
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   440
done
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   441
14273
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   442
lemma less_number_of_Suc [simp]:
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   443
     "(number_of v < Suc n) =  
14272
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   444
        (let pv = number_of (bin_pred v) in  
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   445
         if neg pv then True else nat pv < n)"
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   446
apply (simp only: simp_thms Let_def neg_eq_less_0 linorder_not_less 
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   447
                  number_of_pred nat_number_of_def  
14273
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   448
            split add: split_if)
14272
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   449
apply (rule_tac x = "number_of v" in spec)
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   450
apply (auto simp add: nat_less_iff)
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   451
done
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   452
14273
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   453
lemma less_Suc_number_of [simp]:
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   454
     "(Suc n < number_of v) =  
14272
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   455
        (let pv = number_of (bin_pred v) in  
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   456
         if neg pv then False else n < nat pv)"
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   457
apply (simp only: simp_thms Let_def neg_eq_less_0 linorder_not_less 
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   458
                  number_of_pred nat_number_of_def
14273
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   459
            split add: split_if)
14272
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   460
apply (rule_tac x = "number_of v" in spec)
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   461
apply (auto simp add: zless_nat_eq_int_zless)
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   462
done
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   463
14273
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   464
lemma le_number_of_Suc [simp]:
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   465
     "(number_of v <= Suc n) =  
14272
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   466
        (let pv = number_of (bin_pred v) in  
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   467
         if neg pv then True else nat pv <= n)"
14273
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   468
apply (simp add: Let_def less_Suc_number_of linorder_not_less [symmetric])
14272
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   469
done
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   470
14273
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   471
lemma le_Suc_number_of [simp]:
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   472
     "(Suc n <= number_of v) =  
14272
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   473
        (let pv = number_of (bin_pred v) in  
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   474
         if neg pv then False else n <= nat pv)"
14273
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   475
apply (simp add: Let_def less_number_of_Suc linorder_not_less [symmetric])
14272
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   476
done
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   477
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   478
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   479
(* Push int(.) inwards: *)
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   480
declare zadd_int [symmetric, simp]
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   481
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   482
lemma lemma1: "(m+m = n+n) = (m = (n::int))"
14273
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   483
by auto
14272
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   484
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   485
lemma lemma2: "m+m ~= (1::int) + (n + n)"
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   486
apply auto
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   487
apply (drule_tac f = "%x. x mod 2" in arg_cong)
14273
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   488
apply (simp add: zmod_zadd1_eq)
14272
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   489
done
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   490
14273
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   491
lemma eq_number_of_BIT_BIT:
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   492
     "((number_of (v BIT x) ::int) = number_of (w BIT y)) =  
14272
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   493
      (x=y & (((number_of v) ::int) = number_of w))"
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   494
by (simp only: simp_thms number_of_BIT lemma1 lemma2 eq_commute
14288
d149e3cbdb39 Moving some theorems from Real/RealArith0.ML
paulson
parents: 14273
diff changeset
   495
               Ring_and_Field.add_left_cancel add_assoc Ring_and_Field.add_0
14273
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   496
            split add: split_if cong: imp_cong) 
14272
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   497
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   498
14273
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   499
lemma eq_number_of_BIT_Pls:
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   500
     "((number_of (v BIT x) ::int) = number_of bin.Pls) =  
14272
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   501
      (x=False & (((number_of v) ::int) = number_of bin.Pls))"
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   502
apply (simp only: simp_thms  add: number_of_BIT number_of_Pls eq_commute
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   503
            split add: split_if cong: imp_cong)
14273
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   504
apply (rule_tac x = "number_of v" in spec, safe)
14272
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   505
apply (simp_all (no_asm_use))
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   506
apply (drule_tac f = "%x. x mod 2" in arg_cong)
14273
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   507
apply (simp add: zmod_zadd1_eq)
14272
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   508
done
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   509
14273
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   510
lemma eq_number_of_BIT_Min:
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   511
     "((number_of (v BIT x) ::int) = number_of bin.Min) =  
14272
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   512
      (x=True & (((number_of v) ::int) = number_of bin.Min))"
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   513
apply (simp only: simp_thms  add: number_of_BIT number_of_Min eq_commute
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   514
            split add: split_if cong: imp_cong)
14273
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   515
apply (rule_tac x = "number_of v" in spec, auto)
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   516
apply (drule_tac f = "%x. x mod 2" in arg_cong, auto)
14272
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   517
done
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   518
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   519
lemma eq_number_of_Pls_Min: "(number_of bin.Pls ::int) ~= number_of bin.Min"
14273
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   520
by auto
14272
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   521
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   522
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   523
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   524
(*** Literal arithmetic involving powers, type nat ***)
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   525
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   526
lemma nat_power_eq: "(0::int) <= z ==> nat (z^n) = nat z ^ n"
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   527
apply (induct_tac "n")
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   528
apply (simp_all (no_asm_simp) add: nat_mult_distrib)
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   529
done
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   530
14273
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   531
lemma power_nat_number_of:
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   532
     "(number_of v :: nat) ^ n =  
14378
69c4d5997669 generic of_nat and of_int functions, and generalization of iszero
paulson
parents: 14365
diff changeset
   533
       (if neg (number_of v :: int) then 0^n else nat ((number_of v :: int) ^ n))"
14272
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   534
by (simp only: simp_thms neg_nat not_neg_eq_ge_0 nat_number_of_def nat_power_eq
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   535
         split add: split_if cong: imp_cong)
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   536
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   537
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   538
declare power_nat_number_of [of _ "number_of w", standard, simp]
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   539
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   540
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   541
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   542
(*** Literal arithmetic involving powers, type int ***)
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   543
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   544
lemma zpower_even: "(z::int) ^ (2*a) = (z^a)^2"
14273
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   545
by (simp add: zpower_zpower mult_commute)
14272
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   546
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   547
lemma zpower_odd: "(z::int) ^ (2*a + 1) = z * (z^a)^2"
14273
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   548
by (simp add: zpower_even zpower_zadd_distrib)
14272
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   549
14273
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   550
lemma zpower_number_of_even:
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   551
     "(z::int) ^ number_of (w BIT False) =  
14272
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   552
      (let w = z ^ (number_of w) in  w*w)"
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   553
apply (simp del: nat_number_of  add: nat_number_of_def number_of_BIT Let_def)
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   554
apply (simp only: number_of_add) 
14273
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   555
apply (rule_tac x = "number_of w" in spec, clarify)
14272
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   556
apply (case_tac " (0::int) <= x")
14353
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   557
apply (auto simp add: nat_mult_distrib zpower_even power2_eq_square)
14272
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   558
done
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   559
14273
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   560
lemma zpower_number_of_odd:
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   561
     "(z::int) ^ number_of (w BIT True) =  
14272
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   562
          (if (0::int) <= number_of w                    
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   563
           then (let w = z ^ (number_of w) in  z*w*w)    
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   564
           else 1)"
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   565
apply (simp del: nat_number_of  add: nat_number_of_def number_of_BIT Let_def)
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   566
apply (simp only: number_of_add int_numeral_1_eq_1 not_neg_eq_ge_0 neg_eq_less_0) 
14273
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   567
apply (rule_tac x = "number_of w" in spec, clarify)
14353
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   568
apply (auto simp add: nat_add_distrib nat_mult_distrib zpower_even power2_eq_square neg_nat)
14272
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   569
done
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   570
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   571
declare zpower_number_of_even [of "number_of v", standard, simp]
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   572
declare zpower_number_of_odd  [of "number_of v", standard, simp]
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   573
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   574
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   575
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   576
ML
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   577
{*
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   578
val numerals = thms"numerals";
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   579
val numeral_ss = simpset() addsimps numerals;
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   580
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   581
val nat_bin_arith_setup =
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   582
 [Fast_Arith.map_data 
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   583
   (fn {add_mono_thms, mult_mono_thms, inj_thms, lessD, simpset} =>
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   584
     {add_mono_thms = add_mono_thms, mult_mono_thms = mult_mono_thms,
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   585
      inj_thms = inj_thms,
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   586
      lessD = lessD,
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   587
      simpset = simpset addsimps [Suc_nat_number_of, int_nat_number_of,
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   588
                                  not_neg_number_of_Pls,
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   589
                                  neg_number_of_Min,neg_number_of_BIT]})]
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   590
*}
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   591
12838
wenzelm
parents: 12440
diff changeset
   592
setup nat_bin_arith_setup
wenzelm
parents: 12440
diff changeset
   593
13189
81ed5c6de890 Now arith can deal with div/mod arbitrary nat numerals.
nipkow
parents: 13154
diff changeset
   594
(* Enable arith to deal with div/mod k where k is a numeral: *)
81ed5c6de890 Now arith can deal with div/mod arbitrary nat numerals.
nipkow
parents: 13154
diff changeset
   595
declare split_div[of _ _ "number_of k", standard, arith_split]
81ed5c6de890 Now arith can deal with div/mod arbitrary nat numerals.
nipkow
parents: 13154
diff changeset
   596
declare split_mod[of _ _ "number_of k", standard, arith_split]
13154
f1097ea60ba4 Set up arith to deal with div 2 and mod 2.
nipkow
parents: 13043
diff changeset
   597
13491
ddf6ae639f21 *** empty log message ***
nipkow
parents: 13189
diff changeset
   598
lemma nat_number_of_Pls: "number_of bin.Pls = (0::nat)"
12838
wenzelm
parents: 12440
diff changeset
   599
  by (simp add: number_of_Pls nat_number_of_def)
wenzelm
parents: 12440
diff changeset
   600
13491
ddf6ae639f21 *** empty log message ***
nipkow
parents: 13189
diff changeset
   601
lemma nat_number_of_Min: "number_of bin.Min = (0::nat)"
12838
wenzelm
parents: 12440
diff changeset
   602
  apply (simp only: number_of_Min nat_number_of_def nat_zminus_int)
wenzelm
parents: 12440
diff changeset
   603
  apply (simp add: neg_nat)
wenzelm
parents: 12440
diff changeset
   604
  done
7032
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   605
12838
wenzelm
parents: 12440
diff changeset
   606
lemma nat_number_of_BIT_True:
wenzelm
parents: 12440
diff changeset
   607
  "number_of (w BIT True) =
14378
69c4d5997669 generic of_nat and of_int functions, and generalization of iszero
paulson
parents: 14365
diff changeset
   608
    (if neg (number_of w :: int) then 0
12838
wenzelm
parents: 12440
diff changeset
   609
     else let n = number_of w in Suc (n + n))"
wenzelm
parents: 12440
diff changeset
   610
  apply (simp only: nat_number_of_def Let_def split: split_if)
wenzelm
parents: 12440
diff changeset
   611
  apply (intro conjI impI)
wenzelm
parents: 12440
diff changeset
   612
   apply (simp add: neg_nat neg_number_of_BIT)
wenzelm
parents: 12440
diff changeset
   613
  apply (rule int_int_eq [THEN iffD1])
wenzelm
parents: 12440
diff changeset
   614
  apply (simp only: not_neg_nat neg_number_of_BIT int_Suc zadd_int [symmetric] simp_thms)
wenzelm
parents: 12440
diff changeset
   615
  apply (simp only: number_of_BIT if_True zadd_assoc)
wenzelm
parents: 12440
diff changeset
   616
  done
7032
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   617
12838
wenzelm
parents: 12440
diff changeset
   618
lemma nat_number_of_BIT_False:
wenzelm
parents: 12440
diff changeset
   619
    "number_of (w BIT False) = (let n::nat = number_of w in n + n)"
wenzelm
parents: 12440
diff changeset
   620
  apply (simp only: nat_number_of_def Let_def)
14378
69c4d5997669 generic of_nat and of_int functions, and generalization of iszero
paulson
parents: 14365
diff changeset
   621
  apply (cases "neg (number_of w :: int)")
12838
wenzelm
parents: 12440
diff changeset
   622
   apply (simp add: neg_nat neg_number_of_BIT)
wenzelm
parents: 12440
diff changeset
   623
  apply (rule int_int_eq [THEN iffD1])
wenzelm
parents: 12440
diff changeset
   624
  apply (simp only: not_neg_nat neg_number_of_BIT int_Suc zadd_int [symmetric] simp_thms)
wenzelm
parents: 12440
diff changeset
   625
  apply (simp only: number_of_BIT if_False zadd_0 zadd_assoc)
wenzelm
parents: 12440
diff changeset
   626
  done
wenzelm
parents: 12440
diff changeset
   627
13043
ad1828b479b7 renamed nat_number_of to nat_number (avoid clash with separate theorem);
wenzelm
parents: 12933
diff changeset
   628
lemmas nat_number =
12838
wenzelm
parents: 12440
diff changeset
   629
  nat_number_of_Pls nat_number_of_Min
wenzelm
parents: 12440
diff changeset
   630
  nat_number_of_BIT_True nat_number_of_BIT_False
wenzelm
parents: 12440
diff changeset
   631
wenzelm
parents: 12440
diff changeset
   632
lemma Let_Suc [simp]: "Let (Suc n) f == f (Suc n)"
wenzelm
parents: 12440
diff changeset
   633
  by (simp add: Let_def)
10574
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents: 9509
diff changeset
   634
12440
fb5851b71a82 Added code generator setup.
berghofe
parents: 11468
diff changeset
   635
14273
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   636
subsection {*Lemmas for the Combination and Cancellation Simprocs*}
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   637
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   638
lemma nat_number_of_add_left:
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   639
     "number_of v + (number_of v' + (k::nat)) =  
14378
69c4d5997669 generic of_nat and of_int functions, and generalization of iszero
paulson
parents: 14365
diff changeset
   640
         (if neg (number_of v :: int) then number_of v' + k  
69c4d5997669 generic of_nat and of_int functions, and generalization of iszero
paulson
parents: 14365
diff changeset
   641
          else if neg (number_of v' :: int) then number_of v + k  
14273
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   642
          else number_of (bin_add v v') + k)"
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   643
apply simp
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   644
done
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   645
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   646
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   647
(** For combine_numerals **)
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   648
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   649
lemma left_add_mult_distrib: "i*u + (j*u + k) = (i+j)*u + (k::nat)"
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   650
by (simp add: add_mult_distrib)
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   651
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   652
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   653
(** For cancel_numerals **)
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   654
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   655
lemma nat_diff_add_eq1:
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   656
     "j <= (i::nat) ==> ((i*u + m) - (j*u + n)) = (((i-j)*u + m) - n)"
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   657
by (simp split add: nat_diff_split add: add_mult_distrib)
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   658
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   659
lemma nat_diff_add_eq2:
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   660
     "i <= (j::nat) ==> ((i*u + m) - (j*u + n)) = (m - ((j-i)*u + n))"
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   661
by (simp split add: nat_diff_split add: add_mult_distrib)
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   662
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   663
lemma nat_eq_add_iff1:
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   664
     "j <= (i::nat) ==> (i*u + m = j*u + n) = ((i-j)*u + m = n)"
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   665
by (auto split add: nat_diff_split simp add: add_mult_distrib)
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   666
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   667
lemma nat_eq_add_iff2:
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   668
     "i <= (j::nat) ==> (i*u + m = j*u + n) = (m = (j-i)*u + n)"
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   669
by (auto split add: nat_diff_split simp add: add_mult_distrib)
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   670
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   671
lemma nat_less_add_iff1:
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   672
     "j <= (i::nat) ==> (i*u + m < j*u + n) = ((i-j)*u + m < n)"
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   673
by (auto split add: nat_diff_split simp add: add_mult_distrib)
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   674
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   675
lemma nat_less_add_iff2:
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   676
     "i <= (j::nat) ==> (i*u + m < j*u + n) = (m < (j-i)*u + n)"
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   677
by (auto split add: nat_diff_split simp add: add_mult_distrib)
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   678
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   679
lemma nat_le_add_iff1:
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   680
     "j <= (i::nat) ==> (i*u + m <= j*u + n) = ((i-j)*u + m <= n)"
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   681
by (auto split add: nat_diff_split simp add: add_mult_distrib)
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   682
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   683
lemma nat_le_add_iff2:
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   684
     "i <= (j::nat) ==> (i*u + m <= j*u + n) = (m <= (j-i)*u + n)"
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   685
by (auto split add: nat_diff_split simp add: add_mult_distrib)
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   686
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   687
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   688
(** For cancel_numeral_factors **)
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   689
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   690
lemma nat_mult_le_cancel1: "(0::nat) < k ==> (k*m <= k*n) = (m<=n)"
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   691
by auto
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   692
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   693
lemma nat_mult_less_cancel1: "(0::nat) < k ==> (k*m < k*n) = (m<n)"
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   694
by auto
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   695
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   696
lemma nat_mult_eq_cancel1: "(0::nat) < k ==> (k*m = k*n) = (m=n)"
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   697
by auto
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   698
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   699
lemma nat_mult_div_cancel1: "(0::nat) < k ==> (k*m) div (k*n) = (m div n)"
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   700
by auto
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   701
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   702
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   703
(** For cancel_factor **)
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   704
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   705
lemma nat_mult_le_cancel_disj: "(k*m <= k*n) = ((0::nat) < k --> m<=n)"
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   706
by auto
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   707
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   708
lemma nat_mult_less_cancel_disj: "(k*m < k*n) = ((0::nat) < k & m<n)"
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   709
by auto
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   710
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   711
lemma nat_mult_eq_cancel_disj: "(k*m = k*n) = (k = (0::nat) | m=n)"
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   712
by auto
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   713
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   714
lemma nat_mult_div_cancel_disj:
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   715
     "(k*m) div (k*n) = (if k = (0::nat) then 0 else m div n)"
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   716
by (simp add: nat_mult_div_cancel1)
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   717
14353
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   718
14273
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   719
ML
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   720
{*
14353
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   721
val eq_nat_nat_iff = thm"eq_nat_nat_iff";
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   722
val eq_nat_number_of = thm"eq_nat_number_of";
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   723
val less_nat_number_of = thm"less_nat_number_of";
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   724
val power2_eq_square = thm "power2_eq_square";
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   725
val zero_le_power2 = thm "zero_le_power2";
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   726
val zero_less_power2 = thm "zero_less_power2";
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   727
val zero_eq_power2 = thm "zero_eq_power2";
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   728
val abs_power2 = thm "abs_power2";
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   729
val power2_abs = thm "power2_abs";
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   730
val power2_minus = thm "power2_minus";
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   731
val power_minus1_even = thm "power_minus1_even";
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   732
val power_minus_even = thm "power_minus_even";
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   733
val zero_le_even_power = thm "zero_le_even_power";
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   734
val odd_power_less_zero = thm "odd_power_less_zero";
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   735
val odd_0_le_power_imp_0_le = thm "odd_0_le_power_imp_0_le";
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   736
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   737
val Suc_pred' = thm"Suc_pred'";
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   738
val expand_Suc = thm"expand_Suc";
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   739
val Suc_eq_add_numeral_1 = thm"Suc_eq_add_numeral_1";
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   740
val add_eq_if = thm"add_eq_if";
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   741
val mult_eq_if = thm"mult_eq_if";
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   742
val power_eq_if = thm"power_eq_if";
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   743
val diff_less' = thm"diff_less'";
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   744
val eq_number_of_0 = thm"eq_number_of_0";
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   745
val eq_0_number_of = thm"eq_0_number_of";
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   746
val less_0_number_of = thm"less_0_number_of";
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   747
val neg_imp_number_of_eq_0 = thm"neg_imp_number_of_eq_0";
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   748
val eq_number_of_Suc = thm"eq_number_of_Suc";
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   749
val Suc_eq_number_of = thm"Suc_eq_number_of";
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   750
val less_number_of_Suc = thm"less_number_of_Suc";
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   751
val less_Suc_number_of = thm"less_Suc_number_of";
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   752
val le_number_of_Suc = thm"le_number_of_Suc";
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   753
val le_Suc_number_of = thm"le_Suc_number_of";
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   754
val eq_number_of_BIT_BIT = thm"eq_number_of_BIT_BIT";
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   755
val eq_number_of_BIT_Pls = thm"eq_number_of_BIT_Pls";
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   756
val eq_number_of_BIT_Min = thm"eq_number_of_BIT_Min";
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   757
val eq_number_of_Pls_Min = thm"eq_number_of_Pls_Min";
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   758
val nat_power_eq = thm"nat_power_eq";
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   759
val power_nat_number_of = thm"power_nat_number_of";
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   760
val zpower_even = thm"zpower_even";
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   761
val zpower_odd = thm"zpower_odd";
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   762
val zpower_number_of_even = thm"zpower_number_of_even";
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   763
val zpower_number_of_odd = thm"zpower_number_of_odd";
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   764
val nat_number_of_Pls = thm"nat_number_of_Pls";
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   765
val nat_number_of_Min = thm"nat_number_of_Min";
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   766
val nat_number_of_BIT_True = thm"nat_number_of_BIT_True";
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   767
val nat_number_of_BIT_False = thm"nat_number_of_BIT_False";
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   768
val Let_Suc = thm"Let_Suc";
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   769
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   770
val nat_number = thms"nat_number";
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   771
14273
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   772
val nat_number_of_add_left = thm"nat_number_of_add_left";
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   773
val left_add_mult_distrib = thm"left_add_mult_distrib";
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   774
val nat_diff_add_eq1 = thm"nat_diff_add_eq1";
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   775
val nat_diff_add_eq2 = thm"nat_diff_add_eq2";
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   776
val nat_eq_add_iff1 = thm"nat_eq_add_iff1";
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   777
val nat_eq_add_iff2 = thm"nat_eq_add_iff2";
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   778
val nat_less_add_iff1 = thm"nat_less_add_iff1";
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   779
val nat_less_add_iff2 = thm"nat_less_add_iff2";
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   780
val nat_le_add_iff1 = thm"nat_le_add_iff1";
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   781
val nat_le_add_iff2 = thm"nat_le_add_iff2";
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   782
val nat_mult_le_cancel1 = thm"nat_mult_le_cancel1";
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   783
val nat_mult_less_cancel1 = thm"nat_mult_less_cancel1";
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   784
val nat_mult_eq_cancel1 = thm"nat_mult_eq_cancel1";
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   785
val nat_mult_div_cancel1 = thm"nat_mult_div_cancel1";
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   786
val nat_mult_le_cancel_disj = thm"nat_mult_le_cancel_disj";
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   787
val nat_mult_less_cancel_disj = thm"nat_mult_less_cancel_disj";
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   788
val nat_mult_eq_cancel_disj = thm"nat_mult_eq_cancel_disj";
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   789
val nat_mult_div_cancel_disj = thm"nat_mult_div_cancel_disj";
14353
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   790
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   791
val power_minus1_even = thm"power_minus1_even";
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   792
val power_minus_even = thm"power_minus_even";
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   793
val zero_le_even_power = thm"zero_le_even_power";
14273
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   794
*}
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   795
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   796
12440
fb5851b71a82 Added code generator setup.
berghofe
parents: 11468
diff changeset
   797
subsection {* Configuration of the code generator *}
fb5851b71a82 Added code generator setup.
berghofe
parents: 11468
diff changeset
   798
12933
b85c62c4e826 Introduced variants of operators + * ~ constrained to type int
berghofe
parents: 12838
diff changeset
   799
ML {*
b85c62c4e826 Introduced variants of operators + * ~ constrained to type int
berghofe
parents: 12838
diff changeset
   800
infix 7 `*;
b85c62c4e826 Introduced variants of operators + * ~ constrained to type int
berghofe
parents: 12838
diff changeset
   801
infix 6 `+;
b85c62c4e826 Introduced variants of operators + * ~ constrained to type int
berghofe
parents: 12838
diff changeset
   802
b85c62c4e826 Introduced variants of operators + * ~ constrained to type int
berghofe
parents: 12838
diff changeset
   803
val op `* = op * : int * int -> int;
b85c62c4e826 Introduced variants of operators + * ~ constrained to type int
berghofe
parents: 12838
diff changeset
   804
val op `+ = op + : int * int -> int;
b85c62c4e826 Introduced variants of operators + * ~ constrained to type int
berghofe
parents: 12838
diff changeset
   805
val `~ = ~ : int -> int;
b85c62c4e826 Introduced variants of operators + * ~ constrained to type int
berghofe
parents: 12838
diff changeset
   806
*}
b85c62c4e826 Introduced variants of operators + * ~ constrained to type int
berghofe
parents: 12838
diff changeset
   807
12440
fb5851b71a82 Added code generator setup.
berghofe
parents: 11468
diff changeset
   808
types_code
fb5851b71a82 Added code generator setup.
berghofe
parents: 11468
diff changeset
   809
  "int" ("int")
fb5851b71a82 Added code generator setup.
berghofe
parents: 11468
diff changeset
   810
14194
8953b566dfed Improved efficiency of code generated for functions int and nat.
berghofe
parents: 13491
diff changeset
   811
constdefs
8953b566dfed Improved efficiency of code generated for functions int and nat.
berghofe
parents: 13491
diff changeset
   812
  int_aux :: "int \<Rightarrow> nat \<Rightarrow> int"
8953b566dfed Improved efficiency of code generated for functions int and nat.
berghofe
parents: 13491
diff changeset
   813
  "int_aux i n == (i + int n)"
8953b566dfed Improved efficiency of code generated for functions int and nat.
berghofe
parents: 13491
diff changeset
   814
  nat_aux :: "nat \<Rightarrow> int \<Rightarrow> nat"
8953b566dfed Improved efficiency of code generated for functions int and nat.
berghofe
parents: 13491
diff changeset
   815
  "nat_aux n i == (n + nat i)"
12440
fb5851b71a82 Added code generator setup.
berghofe
parents: 11468
diff changeset
   816
14194
8953b566dfed Improved efficiency of code generated for functions int and nat.
berghofe
parents: 13491
diff changeset
   817
lemma [code]:
8953b566dfed Improved efficiency of code generated for functions int and nat.
berghofe
parents: 13491
diff changeset
   818
  "int_aux i 0 = i"
8953b566dfed Improved efficiency of code generated for functions int and nat.
berghofe
parents: 13491
diff changeset
   819
  "int_aux i (Suc n) = int_aux (i + 1) n" -- {* tail recursive *}
8953b566dfed Improved efficiency of code generated for functions int and nat.
berghofe
parents: 13491
diff changeset
   820
  "int n = int_aux 0 n"
8953b566dfed Improved efficiency of code generated for functions int and nat.
berghofe
parents: 13491
diff changeset
   821
  by (simp add: int_aux_def)+
8953b566dfed Improved efficiency of code generated for functions int and nat.
berghofe
parents: 13491
diff changeset
   822
8953b566dfed Improved efficiency of code generated for functions int and nat.
berghofe
parents: 13491
diff changeset
   823
lemma [code]: "nat_aux n i = (if i <= 0 then n else nat_aux (Suc n) (i - 1))"
8953b566dfed Improved efficiency of code generated for functions int and nat.
berghofe
parents: 13491
diff changeset
   824
  by (simp add: nat_aux_def Suc_nat_eq_nat_zadd1) -- {* tail recursive *}
8953b566dfed Improved efficiency of code generated for functions int and nat.
berghofe
parents: 13491
diff changeset
   825
lemma [code]: "nat i = nat_aux 0 i"
8953b566dfed Improved efficiency of code generated for functions int and nat.
berghofe
parents: 13491
diff changeset
   826
  by (simp add: nat_aux_def)
12440
fb5851b71a82 Added code generator setup.
berghofe
parents: 11468
diff changeset
   827
fb5851b71a82 Added code generator setup.
berghofe
parents: 11468
diff changeset
   828
consts_code
fb5851b71a82 Added code generator setup.
berghofe
parents: 11468
diff changeset
   829
  "0" :: "int"                  ("0")
fb5851b71a82 Added code generator setup.
berghofe
parents: 11468
diff changeset
   830
  "1" :: "int"                  ("1")
12933
b85c62c4e826 Introduced variants of operators + * ~ constrained to type int
berghofe
parents: 12838
diff changeset
   831
  "uminus" :: "int => int"      ("`~")
b85c62c4e826 Introduced variants of operators + * ~ constrained to type int
berghofe
parents: 12838
diff changeset
   832
  "op +" :: "int => int => int" ("(_ `+/ _)")
b85c62c4e826 Introduced variants of operators + * ~ constrained to type int
berghofe
parents: 12838
diff changeset
   833
  "op *" :: "int => int => int" ("(_ `*/ _)")
14378
69c4d5997669 generic of_nat and of_int functions, and generalization of iszero
paulson
parents: 14365
diff changeset
   834
  "op <" :: "int => int => bool" ("(_ </ _)")
69c4d5997669 generic of_nat and of_int functions, and generalization of iszero
paulson
parents: 14365
diff changeset
   835
  "op <=" :: "int => int => bool" ("(_ <=/ _)")
12440
fb5851b71a82 Added code generator setup.
berghofe
parents: 11468
diff changeset
   836
  "neg"                         ("(_ < 0)")
fb5851b71a82 Added code generator setup.
berghofe
parents: 11468
diff changeset
   837
7032
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   838
end