src/HOL/Integ/NatBin.thy
author huffman
Tue, 08 May 2007 01:10:55 +0200
changeset 22854 51087b1cc77d
parent 22803 5129e02f4df2
child 23051 e98ed26577a2
permissions -rw-r--r--
add lemmas power2_le_imp_le and power2_less_imp_less
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
15131
c69542757a4d New theory header syntax.
nipkow
parents: 15129
diff changeset
     9
theory NatBin
15140
322485b816ac import -> imports
nipkow
parents: 15131
diff changeset
    10
imports IntDiv
15131
c69542757a4d New theory header syntax.
nipkow
parents: 15129
diff changeset
    11
begin
7032
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
    12
12838
wenzelm
parents: 12440
diff changeset
    13
text {*
14273
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
    14
  Arithmetic for naturals is reduced to that for the non-negative integers.
12838
wenzelm
parents: 12440
diff changeset
    15
*}
wenzelm
parents: 12440
diff changeset
    16
22319
6f162dd72f60 cleanup
haftmann
parents: 22218
diff changeset
    17
instance nat :: number
22803
5129e02f4df2 slightly tuned
haftmann
parents: 22393
diff changeset
    18
  nat_number_of_def [code inline]: "number_of v == nat (number_of (v\<Colon>int))" ..
19380
b808efaa5828 tuned syntax/abbreviations;
wenzelm
parents: 18984
diff changeset
    19
b808efaa5828 tuned syntax/abbreviations;
wenzelm
parents: 18984
diff changeset
    20
abbreviation (xsymbols)
21404
eb85850d3eb7 more robust syntax for definition/abbreviation/notation;
wenzelm
parents: 21210
diff changeset
    21
  square :: "'a::power => 'a"  ("(_\<twosuperior>)" [1000] 999) where
19380
b808efaa5828 tuned syntax/abbreviations;
wenzelm
parents: 18984
diff changeset
    22
  "x\<twosuperior> == x^2"
b808efaa5828 tuned syntax/abbreviations;
wenzelm
parents: 18984
diff changeset
    23
21210
c17fd2df4e9e renamed 'const_syntax' to 'notation';
wenzelm
parents: 21199
diff changeset
    24
notation (latex output)
19656
09be06943252 tuned concrete syntax -- abbreviation/const_syntax;
wenzelm
parents: 19601
diff changeset
    25
  square  ("(_\<twosuperior>)" [1000] 999)
19380
b808efaa5828 tuned syntax/abbreviations;
wenzelm
parents: 18984
diff changeset
    26
21210
c17fd2df4e9e renamed 'const_syntax' to 'notation';
wenzelm
parents: 21199
diff changeset
    27
notation (HTML output)
19656
09be06943252 tuned concrete syntax -- abbreviation/const_syntax;
wenzelm
parents: 19601
diff changeset
    28
  square  ("(_\<twosuperior>)" [1000] 999)
12838
wenzelm
parents: 12440
diff changeset
    29
14272
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
    30
14353
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
    31
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
    32
14273
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
    33
declare nat_0 [simp] nat_1 [simp]
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
    34
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
    35
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
    36
by (simp add: nat_number_of_def)
14272
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
    37
14387
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14378
diff changeset
    38
lemma nat_numeral_0_eq_0 [simp]: "Numeral0 = (0::nat)"
14273
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
    39
by (simp add: nat_number_of_def)
14272
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
    40
14387
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14378
diff changeset
    41
lemma nat_numeral_1_eq_1 [simp]: "Numeral1 = (1::nat)"
14273
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
    42
by (simp add: nat_1 nat_number_of_def)
14272
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
    43
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
    44
lemma numeral_1_eq_Suc_0: "Numeral1 = Suc 0"
14387
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14378
diff changeset
    45
by (simp add: nat_numeral_1_eq_1)
14272
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
    46
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
    47
lemma numeral_2_eq_2: "2 = Suc (Suc 0)"
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
    48
apply (unfold nat_number_of_def)
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
    49
apply (rule nat_2)
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
    50
done
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
    51
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
    52
14273
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
    53
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
    54
   @{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
    55
   "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
    56
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
    57
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
    58
apply (case_tac "0 <= z'")
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
    59
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
    60
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
    61
apply (auto elim!: nonneg_eq_int)
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
    62
apply (rename_tac m m')
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
    63
apply (subgoal_tac "0 <= int m div int m'")
14387
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14378
diff changeset
    64
 prefer 2 apply (simp add: nat_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
    65
apply (rule inj_int [THEN injD], simp)
14272
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
    66
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
    67
 prefer 2 apply force
14387
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14378
diff changeset
    68
apply (simp add: nat_less_iff [symmetric] quorem_def nat_numeral_0_eq_0 zadd_int 
14273
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
    69
                 zmult_int)
14272
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
    70
done
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
    71
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
    72
(*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
    73
lemma nat_mod_distrib:
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
    74
     "[| (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
    75
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
    76
apply (auto elim!: nonneg_eq_int)
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
    77
apply (rename_tac m m')
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
    78
apply (subgoal_tac "0 <= int m mod int m'")
14387
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14378
diff changeset
    79
 prefer 2 apply (simp add: nat_less_iff nat_numeral_0_eq_0 pos_mod_sign) 
14273
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
    80
apply (rule inj_int [THEN injD], simp)
14272
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
    81
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
    82
 prefer 2 apply force
14387
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14378
diff changeset
    83
apply (simp add: nat_less_iff [symmetric] quorem_def nat_numeral_0_eq_0 zadd_int zmult_int)
14272
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
    84
done
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
    85
16413
47ffc49c7d7b a few new integer lemmas
paulson
parents: 15965
diff changeset
    86
text{*Suggested by Matthias Daum*}
47ffc49c7d7b a few new integer lemmas
paulson
parents: 15965
diff changeset
    87
lemma int_div_less_self: "\<lbrakk>0 < x; 1 < k\<rbrakk> \<Longrightarrow> x div k < (x::int)"
20217
25b068a99d2b linear arithmetic splits certain operators (e.g. min, max, abs)
webertj
parents: 20105
diff changeset
    88
apply (subgoal_tac "nat x div nat k < nat x")
25b068a99d2b linear arithmetic splits certain operators (e.g. min, max, abs)
webertj
parents: 20105
diff changeset
    89
 apply (simp (asm_lr) add: nat_div_distrib [symmetric])
16413
47ffc49c7d7b a few new integer lemmas
paulson
parents: 15965
diff changeset
    90
apply (rule Divides.div_less_dividend, simp_all) 
47ffc49c7d7b a few new integer lemmas
paulson
parents: 15965
diff changeset
    91
done
47ffc49c7d7b a few new integer lemmas
paulson
parents: 15965
diff changeset
    92
14353
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
    93
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
    94
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
    95
(*"neg" is used in rewrite rules for binary comparisons*)
14387
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14378
diff changeset
    96
lemma int_nat_number_of [simp]:
14273
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
    97
     "int (number_of v :: nat) =  
14378
69c4d5997669 generic of_nat and of_int functions, and generalization of iszero
paulson
parents: 14365
diff changeset
    98
         (if neg (number_of v :: int) then 0  
14272
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
    99
          else (number_of v :: int))"
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: 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
   102
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   103
14390
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
   104
subsubsection{*Successor *}
14272
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   105
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   106
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
   107
apply (rule sym)
14273
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   108
apply (simp add: nat_eq_iff int_Suc)
14272
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
14273
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   111
lemma Suc_nat_number_of_add:
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   112
     "Suc (number_of v + n) =  
20500
11da1ce8dbd8 hid succ, pred in Numeral.thy
haftmann
parents: 20485
diff changeset
   113
        (if neg (number_of v :: int) then 1+n else number_of (Numeral.succ v) + n)" 
14272
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   114
by (simp del: nat_number_of 
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   115
         add: nat_number_of_def neg_nat
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   116
              Suc_nat_eq_nat_zadd1 number_of_succ) 
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   117
14387
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14378
diff changeset
   118
lemma Suc_nat_number_of [simp]:
14273
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   119
     "Suc (number_of v) =  
20500
11da1ce8dbd8 hid succ, pred in Numeral.thy
haftmann
parents: 20485
diff changeset
   120
        (if neg (number_of v :: int) then 1 else number_of (Numeral.succ v))"
14273
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   121
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
   122
apply (simp cong del: if_weak_cong)
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   123
done
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
14390
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
   126
subsubsection{*Addition *}
14272
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
(*"neg" is used in rewrite rules for binary comparisons*)
14387
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14378
diff changeset
   129
lemma add_nat_number_of [simp]:
14273
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   130
     "(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
   131
         (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
   132
          else if neg (number_of v' :: int) then number_of v  
20485
3078fd2eec7b got rid of Numeral.bin type
haftmann
parents: 20355
diff changeset
   133
          else number_of (v + v'))"
14272
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   134
by (force dest!: neg_nat
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   135
          simp del: nat_number_of
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   136
          simp add: nat_number_of_def nat_add_distrib [symmetric]) 
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   137
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   138
14390
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
   139
subsubsection{*Subtraction *}
14272
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   140
14273
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   141
lemma diff_nat_eq_if:
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   142
     "nat z - nat z' =  
14272
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   143
        (if neg z' then nat z   
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   144
         else let d = z-z' in     
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   145
              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
   146
apply (simp add: Let_def nat_diff_distrib [symmetric] neg_eq_less_0 not_neg_eq_ge_0)
14272
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   147
done
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   148
14387
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14378
diff changeset
   149
lemma diff_nat_number_of [simp]: 
14272
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   150
     "(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
   151
        (if neg (number_of v' :: int) then number_of v  
20485
3078fd2eec7b got rid of Numeral.bin type
haftmann
parents: 20355
diff changeset
   152
         else let d = number_of (v + uminus v') in     
14272
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   153
              if neg d then 0 else nat d)"
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   154
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
   155
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   156
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   157
14390
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
   158
subsubsection{*Multiplication *}
14272
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   159
14387
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14378
diff changeset
   160
lemma mult_nat_number_of [simp]:
14273
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   161
     "(number_of v :: nat) * number_of v' =  
20485
3078fd2eec7b got rid of Numeral.bin type
haftmann
parents: 20355
diff changeset
   162
       (if neg (number_of v :: int) then 0 else number_of (v * v'))"
14272
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   163
by (force dest!: neg_nat
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   164
          simp del: nat_number_of
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   165
          simp add: nat_number_of_def nat_mult_distrib [symmetric]) 
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   166
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   167
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   168
14390
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
   169
subsubsection{*Quotient *}
14272
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   170
14387
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14378
diff changeset
   171
lemma div_nat_number_of [simp]:
14273
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   172
     "(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
   173
          (if neg (number_of v :: int) then 0  
14272
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   174
           else nat (number_of v div number_of v'))"
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   175
by (force dest!: neg_nat
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   176
          simp del: nat_number_of
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   177
          simp add: nat_number_of_def nat_div_distrib [symmetric]) 
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   178
14387
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14378
diff changeset
   179
lemma one_div_nat_number_of [simp]:
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14378
diff changeset
   180
     "(Suc 0)  div  number_of v' = (nat (1 div number_of v'))" 
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14378
diff changeset
   181
by (simp del: nat_numeral_1_eq_1 add: numeral_1_eq_Suc_0 [symmetric]) 
14272
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   182
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   183
14390
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
   184
subsubsection{*Remainder *}
14272
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   185
14387
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14378
diff changeset
   186
lemma mod_nat_number_of [simp]:
14273
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   187
     "(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
   188
        (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
   189
         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
   190
         else nat (number_of v mod number_of v'))"
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   191
by (force dest!: neg_nat
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   192
          simp del: nat_number_of
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   193
          simp add: nat_number_of_def nat_mod_distrib [symmetric]) 
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   194
14387
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14378
diff changeset
   195
lemma one_mod_nat_number_of [simp]:
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14378
diff changeset
   196
     "(Suc 0)  mod  number_of v' =  
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14378
diff changeset
   197
        (if neg (number_of v' :: int) then Suc 0
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14378
diff changeset
   198
         else nat (1 mod number_of v'))"
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14378
diff changeset
   199
by (simp del: nat_numeral_1_eq_1 add: numeral_1_eq_Suc_0 [symmetric]) 
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14378
diff changeset
   200
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14378
diff changeset
   201
18978
8971c306b94f made "dvd" on numbers executable by simp.
nipkow
parents: 18708
diff changeset
   202
subsubsection{* Divisibility *}
8971c306b94f made "dvd" on numbers executable by simp.
nipkow
parents: 18708
diff changeset
   203
18984
4301eb0f051f names for simprules
paulson
parents: 18978
diff changeset
   204
lemmas dvd_eq_mod_eq_0_number_of =
4301eb0f051f names for simprules
paulson
parents: 18978
diff changeset
   205
  dvd_eq_mod_eq_0 [of "number_of x" "number_of y", standard]
4301eb0f051f names for simprules
paulson
parents: 18978
diff changeset
   206
4301eb0f051f names for simprules
paulson
parents: 18978
diff changeset
   207
declare dvd_eq_mod_eq_0_number_of [simp]
14272
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
ML
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
val nat_number_of_def = thm"nat_number_of_def";
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
val nat_number_of = thm"nat_number_of";
14387
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14378
diff changeset
   214
val nat_numeral_0_eq_0 = thm"nat_numeral_0_eq_0";
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14378
diff changeset
   215
val nat_numeral_1_eq_1 = thm"nat_numeral_1_eq_1";
14272
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   216
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
   217
val numeral_2_eq_2 = thm"numeral_2_eq_2";
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   218
val nat_div_distrib = thm"nat_div_distrib";
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   219
val nat_mod_distrib = thm"nat_mod_distrib";
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   220
val int_nat_number_of = thm"int_nat_number_of";
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   221
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
   222
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
   223
val Suc_nat_number_of = thm"Suc_nat_number_of";
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   224
val add_nat_number_of = thm"add_nat_number_of";
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   225
val diff_nat_eq_if = thm"diff_nat_eq_if";
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   226
val diff_nat_number_of = thm"diff_nat_number_of";
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   227
val mult_nat_number_of = thm"mult_nat_number_of";
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   228
val div_nat_number_of = thm"div_nat_number_of";
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   229
val mod_nat_number_of = thm"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
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   232
14390
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
   233
subsection{*Comparisons*}
14272
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   234
14390
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
   235
subsubsection{*Equals (=) *}
14272
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   236
14273
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   237
lemma eq_nat_nat_iff:
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   238
     "[| (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
   239
by (auto elim!: nonneg_eq_int)
14272
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   240
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   241
(*"neg" is used in rewrite rules for binary comparisons*)
14390
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
   242
lemma eq_nat_number_of [simp]:
14273
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   243
     "((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
   244
      (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
   245
       else if neg (number_of v' :: int) then iszero (number_of v :: int)  
20485
3078fd2eec7b got rid of Numeral.bin type
haftmann
parents: 20355
diff changeset
   246
       else iszero (number_of (v + uminus v') :: int))"
14272
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   247
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
   248
                  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
   249
            split add: split_if cong add: imp_cong)
14272
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   250
apply (simp only: nat_eq_iff nat_eq_iff2)
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   251
apply (simp add: not_neg_eq_ge_0 [symmetric])
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   252
done
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   253
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   254
14390
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
   255
subsubsection{*Less-than (<) *}
14272
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
(*"neg" is used in rewrite rules for binary comparisons*)
14390
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
   258
lemma less_nat_number_of [simp]:
14273
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   259
     "((number_of v :: nat) < number_of v') =  
20485
3078fd2eec7b got rid of Numeral.bin type
haftmann
parents: 20355
diff changeset
   260
         (if neg (number_of v :: int) then neg (number_of (uminus v') :: int)  
3078fd2eec7b got rid of Numeral.bin type
haftmann
parents: 20355
diff changeset
   261
          else neg (number_of (v + uminus v') :: int))"
14390
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
   262
by (simp only: simp_thms neg_nat not_neg_eq_ge_0 nat_number_of_def
14272
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   263
                nat_less_eq_zless less_number_of_eq_neg zless_nat_eq_int_zless
20485
3078fd2eec7b got rid of Numeral.bin type
haftmann
parents: 20355
diff changeset
   264
         cong add: imp_cong, simp add: Pls_def)
14272
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   265
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   266
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   267
(*Maps #n to n for n = 0, 1, 2*)
14387
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14378
diff changeset
   268
lemmas numerals = nat_numeral_0_eq_0 nat_numeral_1_eq_1 numeral_2_eq_2
14272
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   269
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   270
15234
ec91a90c604e simplification tweaks for better arithmetic reasoning
paulson
parents: 15140
diff changeset
   271
subsection{*Powers with Numeric Exponents*}
14353
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   272
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   273
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
   274
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
   275
use @{term "- 1"} instead.*}
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   276
15003
6145dd7538d7 replaced monomorphic abs definitions by abs_if
paulson
parents: 14738
diff changeset
   277
lemma power2_eq_square: "(a::'a::{comm_semiring_1_cancel,recpower})\<twosuperior> = a * a"
14353
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   278
  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
   279
17724
e969fc0a4925 simprules need names
paulson
parents: 17668
diff changeset
   280
lemma zero_power2 [simp]: "(0::'a::{comm_semiring_1_cancel,recpower})\<twosuperior> = 0"
14353
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   281
  by (simp add: power2_eq_square)
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   282
17724
e969fc0a4925 simprules need names
paulson
parents: 17668
diff changeset
   283
lemma one_power2 [simp]: "(1::'a::{comm_semiring_1_cancel,recpower})\<twosuperior> = 1"
14353
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   284
  by (simp add: power2_eq_square)
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   285
16775
c1b87ef4a1c3 added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
avigad
parents: 16642
diff changeset
   286
lemma power3_eq_cube: "(x::'a::recpower) ^ 3 = x * x * x"
c1b87ef4a1c3 added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
avigad
parents: 16642
diff changeset
   287
  apply (subgoal_tac "3 = Suc (Suc (Suc 0))")
c1b87ef4a1c3 added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
avigad
parents: 16642
diff changeset
   288
  apply (erule ssubst)
c1b87ef4a1c3 added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
avigad
parents: 16642
diff changeset
   289
  apply (simp add: power_Suc mult_ac)
c1b87ef4a1c3 added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
avigad
parents: 16642
diff changeset
   290
  apply (unfold nat_number_of_def)
c1b87ef4a1c3 added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
avigad
parents: 16642
diff changeset
   291
  apply (subst nat_eq_iff)
c1b87ef4a1c3 added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
avigad
parents: 16642
diff changeset
   292
  apply simp
c1b87ef4a1c3 added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
avigad
parents: 16642
diff changeset
   293
done
c1b87ef4a1c3 added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
avigad
parents: 16642
diff changeset
   294
14353
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   295
text{*Squares of literal numerals will be evaluated.*}
17085
5b57f995a179 more simprules now have names
paulson
parents: 16775
diff changeset
   296
lemmas power2_eq_square_number_of =
5b57f995a179 more simprules now have names
paulson
parents: 16775
diff changeset
   297
    power2_eq_square [of "number_of w", standard]
5b57f995a179 more simprules now have names
paulson
parents: 16775
diff changeset
   298
declare power2_eq_square_number_of [simp]
5b57f995a179 more simprules now have names
paulson
parents: 16775
diff changeset
   299
14353
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   300
16775
c1b87ef4a1c3 added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
avigad
parents: 16642
diff changeset
   301
lemma zero_le_power2: "0 \<le> (a\<twosuperior>::'a::{ordered_idom,recpower})"
14353
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   302
  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
   303
16775
c1b87ef4a1c3 added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
avigad
parents: 16642
diff changeset
   304
lemma zero_less_power2:
15003
6145dd7538d7 replaced monomorphic abs definitions by abs_if
paulson
parents: 14738
diff changeset
   305
     "(0 < a\<twosuperior>) = (a \<noteq> (0::'a::{ordered_idom,recpower}))"
14353
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   306
  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
   307
16775
c1b87ef4a1c3 added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
avigad
parents: 16642
diff changeset
   308
lemma power2_less_0:
15234
ec91a90c604e simplification tweaks for better arithmetic reasoning
paulson
parents: 15140
diff changeset
   309
  fixes a :: "'a::{ordered_idom,recpower}"
ec91a90c604e simplification tweaks for better arithmetic reasoning
paulson
parents: 15140
diff changeset
   310
  shows "~ (a\<twosuperior> < 0)"
ec91a90c604e simplification tweaks for better arithmetic reasoning
paulson
parents: 15140
diff changeset
   311
by (force simp add: power2_eq_square mult_less_0_iff) 
ec91a90c604e simplification tweaks for better arithmetic reasoning
paulson
parents: 15140
diff changeset
   312
16775
c1b87ef4a1c3 added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
avigad
parents: 16642
diff changeset
   313
lemma zero_eq_power2:
15003
6145dd7538d7 replaced monomorphic abs definitions by abs_if
paulson
parents: 14738
diff changeset
   314
     "(a\<twosuperior> = 0) = (a = (0::'a::{ordered_idom,recpower}))"
14353
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   315
  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
   316
16775
c1b87ef4a1c3 added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
avigad
parents: 16642
diff changeset
   317
lemma abs_power2:
15003
6145dd7538d7 replaced monomorphic abs definitions by abs_if
paulson
parents: 14738
diff changeset
   318
     "abs(a\<twosuperior>) = (a\<twosuperior>::'a::{ordered_idom,recpower})"
14353
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   319
  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
   320
16775
c1b87ef4a1c3 added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
avigad
parents: 16642
diff changeset
   321
lemma power2_abs:
15003
6145dd7538d7 replaced monomorphic abs definitions by abs_if
paulson
parents: 14738
diff changeset
   322
     "(abs a)\<twosuperior> = (a\<twosuperior>::'a::{ordered_idom,recpower})"
14353
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   323
  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
   324
16775
c1b87ef4a1c3 added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
avigad
parents: 16642
diff changeset
   325
lemma power2_minus:
15003
6145dd7538d7 replaced monomorphic abs definitions by abs_if
paulson
parents: 14738
diff changeset
   326
     "(- a)\<twosuperior> = (a\<twosuperior>::'a::{comm_ring_1,recpower})"
14353
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   327
  by (simp add: power2_eq_square)
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   328
22854
51087b1cc77d add lemmas power2_le_imp_le and power2_less_imp_less
huffman
parents: 22803
diff changeset
   329
lemma power2_le_imp_le:
51087b1cc77d add lemmas power2_le_imp_le and power2_less_imp_less
huffman
parents: 22803
diff changeset
   330
  fixes x y :: "'a::{ordered_semidom,recpower}"
51087b1cc77d add lemmas power2_le_imp_le and power2_less_imp_less
huffman
parents: 22803
diff changeset
   331
  shows "\<lbrakk>x\<twosuperior> \<le> y\<twosuperior>; 0 \<le> y\<rbrakk> \<Longrightarrow> x \<le> y"
51087b1cc77d add lemmas power2_le_imp_le and power2_less_imp_less
huffman
parents: 22803
diff changeset
   332
unfolding numeral_2_eq_2 by (rule power_le_imp_le_base)
51087b1cc77d add lemmas power2_le_imp_le and power2_less_imp_less
huffman
parents: 22803
diff changeset
   333
51087b1cc77d add lemmas power2_le_imp_le and power2_less_imp_less
huffman
parents: 22803
diff changeset
   334
lemma power2_less_imp_less:
51087b1cc77d add lemmas power2_le_imp_le and power2_less_imp_less
huffman
parents: 22803
diff changeset
   335
  fixes x y :: "'a::{ordered_semidom,recpower}"
51087b1cc77d add lemmas power2_le_imp_le and power2_less_imp_less
huffman
parents: 22803
diff changeset
   336
  shows "\<lbrakk>x\<twosuperior> < y\<twosuperior>; 0 \<le> y\<rbrakk> \<Longrightarrow> x < y"
51087b1cc77d add lemmas power2_le_imp_le and power2_less_imp_less
huffman
parents: 22803
diff changeset
   337
by (rule power_less_imp_less_base)
51087b1cc77d add lemmas power2_le_imp_le and power2_less_imp_less
huffman
parents: 22803
diff changeset
   338
15003
6145dd7538d7 replaced monomorphic abs definitions by abs_if
paulson
parents: 14738
diff changeset
   339
lemma power_minus1_even: "(- 1) ^ (2*n) = (1::'a::{comm_ring_1,recpower})"
15251
bb6f072c8d10 converted some induct_tac to induct
paulson
parents: 15234
diff changeset
   340
apply (induct "n")
16775
c1b87ef4a1c3 added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
avigad
parents: 16642
diff changeset
   341
apply (auto simp add: power_Suc power_add power2_minus)
14353
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   342
done
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   343
15003
6145dd7538d7 replaced monomorphic abs definitions by abs_if
paulson
parents: 14738
diff changeset
   344
lemma power_even_eq: "(a::'a::recpower) ^ (2*n) = (a^n)^2"
21199
2d83f93c3580 * Added annihilation axioms ("x * 0 = 0") to axclass semiring_0.
krauss
parents: 20835
diff changeset
   345
by (subst mult_commute) (simp add: power_mult)
14443
75910c7557c5 generic theorems about exponentials; general tidying up
paulson
parents: 14430
diff changeset
   346
75910c7557c5 generic theorems about exponentials; general tidying up
paulson
parents: 14430
diff changeset
   347
lemma power_odd_eq: "(a::int) ^ Suc(2*n) = a * (a^n)^2"
75910c7557c5 generic theorems about exponentials; general tidying up
paulson
parents: 14430
diff changeset
   348
by (simp add: power_even_eq) 
75910c7557c5 generic theorems about exponentials; general tidying up
paulson
parents: 14430
diff changeset
   349
14353
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   350
lemma power_minus_even [simp]:
15003
6145dd7538d7 replaced monomorphic abs definitions by abs_if
paulson
parents: 14738
diff changeset
   351
     "(-a) ^ (2*n) = (a::'a::{comm_ring_1,recpower}) ^ (2*n)"
14353
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   352
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
   353
16775
c1b87ef4a1c3 added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
avigad
parents: 16642
diff changeset
   354
lemma zero_le_even_power':
15003
6145dd7538d7 replaced monomorphic abs definitions by abs_if
paulson
parents: 14738
diff changeset
   355
     "0 \<le> (a::'a::{ordered_idom,recpower}) ^ (2*n)"
14353
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   356
proof (induct "n")
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   357
  case 0
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   358
    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
   359
next
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   360
  case (Suc n)
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   361
    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
   362
      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
   363
    thus ?case
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   364
      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
   365
qed
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   366
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   367
lemma odd_power_less_zero:
15003
6145dd7538d7 replaced monomorphic abs definitions by abs_if
paulson
parents: 14738
diff changeset
   368
     "(a::'a::{ordered_idom,recpower}) < 0 ==> a ^ Suc(2*n) < 0"
14353
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   369
proof (induct "n")
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   370
  case 0
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   371
    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
   372
next
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   373
  case (Suc n)
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   374
    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
   375
      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
   376
    thus ?case
16775
c1b87ef4a1c3 added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
avigad
parents: 16642
diff changeset
   377
      by (simp add: prems mult_less_0_iff mult_neg_neg)
14353
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   378
qed
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   379
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   380
lemma odd_0_le_power_imp_0_le:
15003
6145dd7538d7 replaced monomorphic abs definitions by abs_if
paulson
parents: 14738
diff changeset
   381
     "0 \<le> a  ^ Suc(2*n) ==> 0 \<le> (a::'a::{ordered_idom,recpower})"
14353
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   382
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
   383
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
   384
done
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   385
15234
ec91a90c604e simplification tweaks for better arithmetic reasoning
paulson
parents: 15140
diff changeset
   386
text{*Simprules for comparisons where common factors can be cancelled.*}
ec91a90c604e simplification tweaks for better arithmetic reasoning
paulson
parents: 15140
diff changeset
   387
lemmas zero_compare_simps =
ec91a90c604e simplification tweaks for better arithmetic reasoning
paulson
parents: 15140
diff changeset
   388
    add_strict_increasing add_strict_increasing2 add_increasing
ec91a90c604e simplification tweaks for better arithmetic reasoning
paulson
parents: 15140
diff changeset
   389
    zero_le_mult_iff zero_le_divide_iff 
ec91a90c604e simplification tweaks for better arithmetic reasoning
paulson
parents: 15140
diff changeset
   390
    zero_less_mult_iff zero_less_divide_iff 
ec91a90c604e simplification tweaks for better arithmetic reasoning
paulson
parents: 15140
diff changeset
   391
    mult_le_0_iff divide_le_0_iff 
ec91a90c604e simplification tweaks for better arithmetic reasoning
paulson
parents: 15140
diff changeset
   392
    mult_less_0_iff divide_less_0_iff 
ec91a90c604e simplification tweaks for better arithmetic reasoning
paulson
parents: 15140
diff changeset
   393
    zero_le_power2 power2_less_0
14353
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   394
14390
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
   395
subsubsection{*Nat *}
14272
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   396
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   397
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
   398
by (simp add: numerals)
14272
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   399
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   400
(*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
   401
  NOT suitable for rewriting because n recurs in the condition.*)
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   402
lemmas expand_Suc = Suc_pred' [of "number_of v", standard]
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   403
14390
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
   404
subsubsection{*Arith *}
14272
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   405
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   406
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
   407
by (simp add: numerals)
14272
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   408
14467
bbfa6b01a55f new lemma
paulson
parents: 14443
diff changeset
   409
lemma Suc_eq_add_numeral_1_left: "Suc n = 1 + n"
bbfa6b01a55f new lemma
paulson
parents: 14443
diff changeset
   410
by (simp add: numerals)
bbfa6b01a55f new lemma
paulson
parents: 14443
diff changeset
   411
14272
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   412
(* These two can be useful when m = number_of... *)
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
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
   415
apply (case_tac "m")
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   416
apply (simp_all add: numerals)
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   417
done
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   418
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   419
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
   420
apply (case_tac "m")
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   421
apply (simp_all add: numerals)
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   422
done
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   423
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   424
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
   425
apply (case_tac "m")
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   426
apply (simp_all add: numerals)
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   427
done
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   428
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   429
14390
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
   430
subsection{*Comparisons involving (0::nat) *}
14272
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   431
14390
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
   432
text{*Simplification already does @{term "n<0"}, @{term "n\<le>0"} and @{term "0\<le>n"}.*}
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
   433
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
   434
lemma eq_number_of_0 [simp]:
14273
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   435
     "(number_of v = (0::nat)) =  
14378
69c4d5997669 generic of_nat and of_int functions, and generalization of iszero
paulson
parents: 14365
diff changeset
   436
      (if neg (number_of v :: int) then True else iszero (number_of v :: int))"
14390
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
   437
by (simp del: nat_numeral_0_eq_0 add: nat_numeral_0_eq_0 [symmetric] iszero_0)
14272
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   438
14390
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
   439
lemma eq_0_number_of [simp]:
14273
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   440
     "((0::nat) = number_of v) =  
14378
69c4d5997669 generic of_nat and of_int functions, and generalization of iszero
paulson
parents: 14365
diff changeset
   441
      (if neg (number_of v :: int) then True else iszero (number_of v :: int))"
14390
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
   442
by (rule trans [OF eq_sym_conv eq_number_of_0])
14272
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   443
14390
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
   444
lemma less_0_number_of [simp]:
20485
3078fd2eec7b got rid of Numeral.bin type
haftmann
parents: 20355
diff changeset
   445
     "((0::nat) < number_of v) = neg (number_of (uminus v) :: int)"
3078fd2eec7b got rid of Numeral.bin type
haftmann
parents: 20355
diff changeset
   446
by (simp del: nat_numeral_0_eq_0 add: nat_numeral_0_eq_0 [symmetric] Pls_def)
14272
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   447
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   448
14378
69c4d5997669 generic of_nat and of_int functions, and generalization of iszero
paulson
parents: 14365
diff changeset
   449
lemma neg_imp_number_of_eq_0: "neg (number_of v :: int) ==> number_of v = (0::nat)"
14387
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14378
diff changeset
   450
by (simp del: nat_numeral_0_eq_0 add: nat_numeral_0_eq_0 [symmetric] iszero_0)
14272
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   451
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   452
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   453
22190
d31dec6397be simplification of Suc/numeral combinations with min, max
paulson
parents: 22046
diff changeset
   454
subsection{*Comparisons involving  @{term Suc} *}
14272
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   455
14273
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   456
lemma eq_number_of_Suc [simp]:
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   457
     "(number_of v = Suc n) =  
20500
11da1ce8dbd8 hid succ, pred in Numeral.thy
haftmann
parents: 20485
diff changeset
   458
        (let pv = number_of (Numeral.pred v) in  
14272
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   459
         if neg pv then False else nat pv = n)"
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   460
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
   461
                  number_of_pred nat_number_of_def 
14273
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   462
            split add: split_if)
14272
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   463
apply (rule_tac x = "number_of v" in spec)
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   464
apply (auto simp add: nat_eq_iff)
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   465
done
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   466
14273
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   467
lemma Suc_eq_number_of [simp]:
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   468
     "(Suc n = number_of v) =  
20500
11da1ce8dbd8 hid succ, pred in Numeral.thy
haftmann
parents: 20485
diff changeset
   469
        (let pv = number_of (Numeral.pred v) in  
14272
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   470
         if neg pv then False else nat pv = n)"
14390
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
   471
by (rule trans [OF eq_sym_conv eq_number_of_Suc])
14272
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   472
14273
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   473
lemma less_number_of_Suc [simp]:
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   474
     "(number_of v < Suc n) =  
20500
11da1ce8dbd8 hid succ, pred in Numeral.thy
haftmann
parents: 20485
diff changeset
   475
        (let pv = number_of (Numeral.pred v) in  
14272
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   476
         if neg pv then True else nat pv < n)"
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   477
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
   478
                  number_of_pred nat_number_of_def  
14273
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   479
            split add: split_if)
14272
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   480
apply (rule_tac x = "number_of v" in spec)
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   481
apply (auto simp add: nat_less_iff)
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   482
done
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   483
14273
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   484
lemma less_Suc_number_of [simp]:
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   485
     "(Suc n < number_of v) =  
20500
11da1ce8dbd8 hid succ, pred in Numeral.thy
haftmann
parents: 20485
diff changeset
   486
        (let pv = number_of (Numeral.pred v) in  
14272
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   487
         if neg pv then False else n < nat pv)"
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   488
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
   489
                  number_of_pred nat_number_of_def
14273
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   490
            split add: split_if)
14272
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   491
apply (rule_tac x = "number_of v" in spec)
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   492
apply (auto simp add: zless_nat_eq_int_zless)
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   493
done
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   494
14273
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   495
lemma le_number_of_Suc [simp]:
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   496
     "(number_of v <= Suc n) =  
20500
11da1ce8dbd8 hid succ, pred in Numeral.thy
haftmann
parents: 20485
diff changeset
   497
        (let pv = number_of (Numeral.pred v) in  
14272
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   498
         if neg pv then True else nat pv <= n)"
14390
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
   499
by (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
   500
14273
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   501
lemma le_Suc_number_of [simp]:
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   502
     "(Suc n <= number_of v) =  
20500
11da1ce8dbd8 hid succ, pred in Numeral.thy
haftmann
parents: 20485
diff changeset
   503
        (let pv = number_of (Numeral.pred v) in  
14272
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   504
         if neg pv then False else n <= nat pv)"
14390
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
   505
by (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
   506
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   507
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   508
(* Push int(.) inwards: *)
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   509
declare zadd_int [symmetric, simp]
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   510
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   511
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
   512
by auto
14272
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   513
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   514
lemma lemma2: "m+m ~= (1::int) + (n + n)"
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   515
apply auto
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   516
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
   517
apply (simp add: zmod_zadd1_eq)
14272
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   518
done
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   519
14273
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   520
lemma eq_number_of_BIT_BIT:
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   521
     "((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
   522
      (x=y & (((number_of v) ::int) = number_of w))"
15620
8ccdc8bc66a2 replaced bool by a new datatype "bit" for binary numerals
paulson
parents: 15531
diff changeset
   523
apply (simp only: number_of_BIT lemma1 lemma2 eq_commute
14738
83f1a514dcb4 changes made due to new Ring_and_Field theory
obua
parents: 14467
diff changeset
   524
               OrderedGroup.add_left_cancel add_assoc OrderedGroup.add_0
15620
8ccdc8bc66a2 replaced bool by a new datatype "bit" for binary numerals
paulson
parents: 15531
diff changeset
   525
            split add: bit.split) 
8ccdc8bc66a2 replaced bool by a new datatype "bit" for binary numerals
paulson
parents: 15531
diff changeset
   526
apply simp
8ccdc8bc66a2 replaced bool by a new datatype "bit" for binary numerals
paulson
parents: 15531
diff changeset
   527
done
14272
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   528
14273
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   529
lemma eq_number_of_BIT_Pls:
15013
34264f5e4691 new treatment of binary numerals
paulson
parents: 15003
diff changeset
   530
     "((number_of (v BIT x) ::int) = Numeral0) =  
15620
8ccdc8bc66a2 replaced bool by a new datatype "bit" for binary numerals
paulson
parents: 15531
diff changeset
   531
      (x=bit.B0 & (((number_of v) ::int) = Numeral0))"
14272
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   532
apply (simp only: simp_thms  add: number_of_BIT number_of_Pls eq_commute
15620
8ccdc8bc66a2 replaced bool by a new datatype "bit" for binary numerals
paulson
parents: 15531
diff changeset
   533
            split add: bit.split cong: imp_cong)
14273
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   534
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
   535
apply (simp_all (no_asm_use))
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   536
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
   537
apply (simp add: zmod_zadd1_eq)
14272
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   538
done
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   539
14273
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   540
lemma eq_number_of_BIT_Min:
15013
34264f5e4691 new treatment of binary numerals
paulson
parents: 15003
diff changeset
   541
     "((number_of (v BIT x) ::int) = number_of Numeral.Min) =  
15620
8ccdc8bc66a2 replaced bool by a new datatype "bit" for binary numerals
paulson
parents: 15531
diff changeset
   542
      (x=bit.B1 & (((number_of v) ::int) = number_of Numeral.Min))"
14272
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   543
apply (simp only: simp_thms  add: number_of_BIT number_of_Min eq_commute
15620
8ccdc8bc66a2 replaced bool by a new datatype "bit" for binary numerals
paulson
parents: 15531
diff changeset
   544
            split add: bit.split cong: imp_cong)
14273
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   545
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
   546
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
   547
done
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   548
15013
34264f5e4691 new treatment of binary numerals
paulson
parents: 15003
diff changeset
   549
lemma eq_number_of_Pls_Min: "(Numeral0 ::int) ~= number_of Numeral.Min"
14273
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   550
by auto
14272
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   551
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   552
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   553
22190
d31dec6397be simplification of Suc/numeral combinations with min, max
paulson
parents: 22046
diff changeset
   554
subsection{*Max and Min Combined with @{term Suc} *}
d31dec6397be simplification of Suc/numeral combinations with min, max
paulson
parents: 22046
diff changeset
   555
d31dec6397be simplification of Suc/numeral combinations with min, max
paulson
parents: 22046
diff changeset
   556
lemma max_number_of_Suc [simp]:
d31dec6397be simplification of Suc/numeral combinations with min, max
paulson
parents: 22046
diff changeset
   557
     "max (Suc n) (number_of v) =  
d31dec6397be simplification of Suc/numeral combinations with min, max
paulson
parents: 22046
diff changeset
   558
        (let pv = number_of (Numeral.pred v) in  
d31dec6397be simplification of Suc/numeral combinations with min, max
paulson
parents: 22046
diff changeset
   559
         if neg pv then Suc n else Suc(max n (nat pv)))"
d31dec6397be simplification of Suc/numeral combinations with min, max
paulson
parents: 22046
diff changeset
   560
apply (simp only: Let_def neg_eq_less_0 number_of_pred nat_number_of_def 
d31dec6397be simplification of Suc/numeral combinations with min, max
paulson
parents: 22046
diff changeset
   561
            split add: split_if nat.split)
d31dec6397be simplification of Suc/numeral combinations with min, max
paulson
parents: 22046
diff changeset
   562
apply (rule_tac x = "number_of v" in spec) 
d31dec6397be simplification of Suc/numeral combinations with min, max
paulson
parents: 22046
diff changeset
   563
apply auto
d31dec6397be simplification of Suc/numeral combinations with min, max
paulson
parents: 22046
diff changeset
   564
done
d31dec6397be simplification of Suc/numeral combinations with min, max
paulson
parents: 22046
diff changeset
   565
 
d31dec6397be simplification of Suc/numeral combinations with min, max
paulson
parents: 22046
diff changeset
   566
lemma max_Suc_number_of [simp]:
d31dec6397be simplification of Suc/numeral combinations with min, max
paulson
parents: 22046
diff changeset
   567
     "max (number_of v) (Suc n) =  
d31dec6397be simplification of Suc/numeral combinations with min, max
paulson
parents: 22046
diff changeset
   568
        (let pv = number_of (Numeral.pred v) in  
d31dec6397be simplification of Suc/numeral combinations with min, max
paulson
parents: 22046
diff changeset
   569
         if neg pv then Suc n else Suc(max (nat pv) n))"
d31dec6397be simplification of Suc/numeral combinations with min, max
paulson
parents: 22046
diff changeset
   570
apply (simp only: Let_def neg_eq_less_0 number_of_pred nat_number_of_def 
d31dec6397be simplification of Suc/numeral combinations with min, max
paulson
parents: 22046
diff changeset
   571
            split add: split_if nat.split)
d31dec6397be simplification of Suc/numeral combinations with min, max
paulson
parents: 22046
diff changeset
   572
apply (rule_tac x = "number_of v" in spec) 
d31dec6397be simplification of Suc/numeral combinations with min, max
paulson
parents: 22046
diff changeset
   573
apply auto
d31dec6397be simplification of Suc/numeral combinations with min, max
paulson
parents: 22046
diff changeset
   574
done
d31dec6397be simplification of Suc/numeral combinations with min, max
paulson
parents: 22046
diff changeset
   575
 
d31dec6397be simplification of Suc/numeral combinations with min, max
paulson
parents: 22046
diff changeset
   576
lemma min_number_of_Suc [simp]:
d31dec6397be simplification of Suc/numeral combinations with min, max
paulson
parents: 22046
diff changeset
   577
     "min (Suc n) (number_of v) =  
d31dec6397be simplification of Suc/numeral combinations with min, max
paulson
parents: 22046
diff changeset
   578
        (let pv = number_of (Numeral.pred v) in  
d31dec6397be simplification of Suc/numeral combinations with min, max
paulson
parents: 22046
diff changeset
   579
         if neg pv then 0 else Suc(min n (nat pv)))"
d31dec6397be simplification of Suc/numeral combinations with min, max
paulson
parents: 22046
diff changeset
   580
apply (simp only: Let_def neg_eq_less_0 number_of_pred nat_number_of_def 
d31dec6397be simplification of Suc/numeral combinations with min, max
paulson
parents: 22046
diff changeset
   581
            split add: split_if nat.split)
d31dec6397be simplification of Suc/numeral combinations with min, max
paulson
parents: 22046
diff changeset
   582
apply (rule_tac x = "number_of v" in spec) 
d31dec6397be simplification of Suc/numeral combinations with min, max
paulson
parents: 22046
diff changeset
   583
apply auto
d31dec6397be simplification of Suc/numeral combinations with min, max
paulson
parents: 22046
diff changeset
   584
done
d31dec6397be simplification of Suc/numeral combinations with min, max
paulson
parents: 22046
diff changeset
   585
 
d31dec6397be simplification of Suc/numeral combinations with min, max
paulson
parents: 22046
diff changeset
   586
lemma min_Suc_number_of [simp]:
d31dec6397be simplification of Suc/numeral combinations with min, max
paulson
parents: 22046
diff changeset
   587
     "min (number_of v) (Suc n) =  
d31dec6397be simplification of Suc/numeral combinations with min, max
paulson
parents: 22046
diff changeset
   588
        (let pv = number_of (Numeral.pred v) in  
d31dec6397be simplification of Suc/numeral combinations with min, max
paulson
parents: 22046
diff changeset
   589
         if neg pv then 0 else Suc(min (nat pv) n))"
d31dec6397be simplification of Suc/numeral combinations with min, max
paulson
parents: 22046
diff changeset
   590
apply (simp only: Let_def neg_eq_less_0 number_of_pred nat_number_of_def 
d31dec6397be simplification of Suc/numeral combinations with min, max
paulson
parents: 22046
diff changeset
   591
            split add: split_if nat.split)
d31dec6397be simplification of Suc/numeral combinations with min, max
paulson
parents: 22046
diff changeset
   592
apply (rule_tac x = "number_of v" in spec) 
d31dec6397be simplification of Suc/numeral combinations with min, max
paulson
parents: 22046
diff changeset
   593
apply auto
d31dec6397be simplification of Suc/numeral combinations with min, max
paulson
parents: 22046
diff changeset
   594
done
d31dec6397be simplification of Suc/numeral combinations with min, max
paulson
parents: 22046
diff changeset
   595
 
14390
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
   596
subsection{*Literal arithmetic involving powers*}
14272
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   597
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   598
lemma nat_power_eq: "(0::int) <= z ==> nat (z^n) = nat z ^ n"
15251
bb6f072c8d10 converted some induct_tac to induct
paulson
parents: 15234
diff changeset
   599
apply (induct "n")
14272
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   600
apply (simp_all (no_asm_simp) add: nat_mult_distrib)
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   601
done
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   602
14273
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   603
lemma power_nat_number_of:
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   604
     "(number_of v :: nat) ^ n =  
14378
69c4d5997669 generic of_nat and of_int functions, and generalization of iszero
paulson
parents: 14365
diff changeset
   605
       (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
   606
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
   607
         split add: split_if cong: imp_cong)
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   608
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   609
17085
5b57f995a179 more simprules now have names
paulson
parents: 16775
diff changeset
   610
lemmas power_nat_number_of_number_of = power_nat_number_of [of _ "number_of w", standard]
5b57f995a179 more simprules now have names
paulson
parents: 16775
diff changeset
   611
declare power_nat_number_of_number_of [simp]
5b57f995a179 more simprules now have names
paulson
parents: 16775
diff changeset
   612
14272
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   613
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   614
14390
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
   615
text{*For the integers*}
14272
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   616
14273
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   617
lemma zpower_number_of_even:
20485
3078fd2eec7b got rid of Numeral.bin type
haftmann
parents: 20355
diff changeset
   618
  "(z::int) ^ number_of (w BIT bit.B0) = (let w = z ^ (number_of w) in w * w)"
3078fd2eec7b got rid of Numeral.bin type
haftmann
parents: 20355
diff changeset
   619
unfolding Let_def nat_number_of_def number_of_BIT bit.cases
14273
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   620
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
   621
apply (case_tac " (0::int) <= x")
14443
75910c7557c5 generic theorems about exponentials; general tidying up
paulson
parents: 14430
diff changeset
   622
apply (auto simp add: nat_mult_distrib power_even_eq power2_eq_square)
14272
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   623
done
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   624
14273
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   625
lemma zpower_number_of_odd:
20485
3078fd2eec7b got rid of Numeral.bin type
haftmann
parents: 20355
diff changeset
   626
  "(z::int) ^ number_of (w BIT bit.B1) = (if (0::int) <= number_of w                    
3078fd2eec7b got rid of Numeral.bin type
haftmann
parents: 20355
diff changeset
   627
     then (let w = z ^ (number_of w) in z * w * w) else 1)"
3078fd2eec7b got rid of Numeral.bin type
haftmann
parents: 20355
diff changeset
   628
unfolding Let_def nat_number_of_def number_of_BIT bit.cases
3078fd2eec7b got rid of Numeral.bin type
haftmann
parents: 20355
diff changeset
   629
apply (rule_tac x = "number_of w" in spec, auto)
3078fd2eec7b got rid of Numeral.bin type
haftmann
parents: 20355
diff changeset
   630
apply (simp only: nat_add_distrib nat_mult_distrib)
3078fd2eec7b got rid of Numeral.bin type
haftmann
parents: 20355
diff changeset
   631
apply simp
14443
75910c7557c5 generic theorems about exponentials; general tidying up
paulson
parents: 14430
diff changeset
   632
apply (auto simp add: nat_add_distrib nat_mult_distrib power_even_eq power2_eq_square neg_nat)
14272
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   633
done
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   634
17085
5b57f995a179 more simprules now have names
paulson
parents: 16775
diff changeset
   635
lemmas zpower_number_of_even_number_of =
5b57f995a179 more simprules now have names
paulson
parents: 16775
diff changeset
   636
    zpower_number_of_even [of "number_of v", standard]
5b57f995a179 more simprules now have names
paulson
parents: 16775
diff changeset
   637
declare zpower_number_of_even_number_of [simp]
5b57f995a179 more simprules now have names
paulson
parents: 16775
diff changeset
   638
5b57f995a179 more simprules now have names
paulson
parents: 16775
diff changeset
   639
lemmas zpower_number_of_odd_number_of =
5b57f995a179 more simprules now have names
paulson
parents: 16775
diff changeset
   640
    zpower_number_of_odd [of "number_of v", standard]
5b57f995a179 more simprules now have names
paulson
parents: 16775
diff changeset
   641
declare zpower_number_of_odd_number_of [simp]
5b57f995a179 more simprules now have names
paulson
parents: 16775
diff changeset
   642
14272
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   643
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   644
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   645
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   646
ML
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   647
{*
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   648
val numerals = thms"numerals";
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   649
val numeral_ss = simpset() addsimps numerals;
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   650
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   651
val nat_bin_arith_setup =
18708
4b3dadb4fe33 setup: theory -> theory;
wenzelm
parents: 18702
diff changeset
   652
 Fast_Arith.map_data
15921
b6e345548913 Fixing a problem with lin.arith.
nipkow
parents: 15620
diff changeset
   653
   (fn {add_mono_thms, mult_mono_thms, inj_thms, lessD, neqE, simpset} =>
14272
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   654
     {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
   655
      inj_thms = inj_thms,
15921
b6e345548913 Fixing a problem with lin.arith.
nipkow
parents: 15620
diff changeset
   656
      lessD = lessD, neqE = neqE,
14272
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   657
      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
   658
                                  not_neg_number_of_Pls,
18708
4b3dadb4fe33 setup: theory -> theory;
wenzelm
parents: 18702
diff changeset
   659
                                  neg_number_of_Min,neg_number_of_BIT]})
14272
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   660
*}
5efbb548107d Tidying of the integer development; towards removing the
paulson
parents: 14194
diff changeset
   661
12838
wenzelm
parents: 12440
diff changeset
   662
setup nat_bin_arith_setup
wenzelm
parents: 12440
diff changeset
   663
13189
81ed5c6de890 Now arith can deal with div/mod arbitrary nat numerals.
nipkow
parents: 13154
diff changeset
   664
(* 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
   665
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
   666
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
   667
15013
34264f5e4691 new treatment of binary numerals
paulson
parents: 15003
diff changeset
   668
lemma nat_number_of_Pls: "Numeral0 = (0::nat)"
12838
wenzelm
parents: 12440
diff changeset
   669
  by (simp add: number_of_Pls nat_number_of_def)
wenzelm
parents: 12440
diff changeset
   670
15013
34264f5e4691 new treatment of binary numerals
paulson
parents: 15003
diff changeset
   671
lemma nat_number_of_Min: "number_of Numeral.Min = (0::nat)"
12838
wenzelm
parents: 12440
diff changeset
   672
  apply (simp only: number_of_Min nat_number_of_def nat_zminus_int)
wenzelm
parents: 12440
diff changeset
   673
  done
7032
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   674
15620
8ccdc8bc66a2 replaced bool by a new datatype "bit" for binary numerals
paulson
parents: 15531
diff changeset
   675
lemma nat_number_of_BIT_1:
8ccdc8bc66a2 replaced bool by a new datatype "bit" for binary numerals
paulson
parents: 15531
diff changeset
   676
  "number_of (w BIT bit.B1) =
14378
69c4d5997669 generic of_nat and of_int functions, and generalization of iszero
paulson
parents: 14365
diff changeset
   677
    (if neg (number_of w :: int) then 0
12838
wenzelm
parents: 12440
diff changeset
   678
     else let n = number_of w in Suc (n + n))"
wenzelm
parents: 12440
diff changeset
   679
  apply (simp only: nat_number_of_def Let_def split: split_if)
wenzelm
parents: 12440
diff changeset
   680
  apply (intro conjI impI)
wenzelm
parents: 12440
diff changeset
   681
   apply (simp add: neg_nat neg_number_of_BIT)
wenzelm
parents: 12440
diff changeset
   682
  apply (rule int_int_eq [THEN iffD1])
wenzelm
parents: 12440
diff changeset
   683
  apply (simp only: not_neg_nat neg_number_of_BIT int_Suc zadd_int [symmetric] simp_thms)
15620
8ccdc8bc66a2 replaced bool by a new datatype "bit" for binary numerals
paulson
parents: 15531
diff changeset
   684
  apply (simp only: number_of_BIT zadd_assoc split: bit.split)
8ccdc8bc66a2 replaced bool by a new datatype "bit" for binary numerals
paulson
parents: 15531
diff changeset
   685
  apply simp
12838
wenzelm
parents: 12440
diff changeset
   686
  done
7032
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   687
15620
8ccdc8bc66a2 replaced bool by a new datatype "bit" for binary numerals
paulson
parents: 15531
diff changeset
   688
lemma nat_number_of_BIT_0:
8ccdc8bc66a2 replaced bool by a new datatype "bit" for binary numerals
paulson
parents: 15531
diff changeset
   689
    "number_of (w BIT bit.B0) = (let n::nat = number_of w in n + n)"
12838
wenzelm
parents: 12440
diff changeset
   690
  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
   691
  apply (cases "neg (number_of w :: int)")
12838
wenzelm
parents: 12440
diff changeset
   692
   apply (simp add: neg_nat neg_number_of_BIT)
wenzelm
parents: 12440
diff changeset
   693
  apply (rule int_int_eq [THEN iffD1])
wenzelm
parents: 12440
diff changeset
   694
  apply (simp only: not_neg_nat neg_number_of_BIT int_Suc zadd_int [symmetric] simp_thms)
15620
8ccdc8bc66a2 replaced bool by a new datatype "bit" for binary numerals
paulson
parents: 15531
diff changeset
   695
  apply (simp only: number_of_BIT zadd_assoc)
8ccdc8bc66a2 replaced bool by a new datatype "bit" for binary numerals
paulson
parents: 15531
diff changeset
   696
  apply simp
12838
wenzelm
parents: 12440
diff changeset
   697
  done
wenzelm
parents: 12440
diff changeset
   698
13043
ad1828b479b7 renamed nat_number_of to nat_number (avoid clash with separate theorem);
wenzelm
parents: 12933
diff changeset
   699
lemmas nat_number =
12838
wenzelm
parents: 12440
diff changeset
   700
  nat_number_of_Pls nat_number_of_Min
15620
8ccdc8bc66a2 replaced bool by a new datatype "bit" for binary numerals
paulson
parents: 15531
diff changeset
   701
  nat_number_of_BIT_1 nat_number_of_BIT_0
12838
wenzelm
parents: 12440
diff changeset
   702
wenzelm
parents: 12440
diff changeset
   703
lemma Let_Suc [simp]: "Let (Suc n) f == f (Suc n)"
wenzelm
parents: 12440
diff changeset
   704
  by (simp add: Let_def)
10574
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents: 9509
diff changeset
   705
15003
6145dd7538d7 replaced monomorphic abs definitions by abs_if
paulson
parents: 14738
diff changeset
   706
lemma power_m1_even: "(-1) ^ (2*n) = (1::'a::{number_ring,recpower})"
14443
75910c7557c5 generic theorems about exponentials; general tidying up
paulson
parents: 14430
diff changeset
   707
by (simp add: power_mult); 
75910c7557c5 generic theorems about exponentials; general tidying up
paulson
parents: 14430
diff changeset
   708
15003
6145dd7538d7 replaced monomorphic abs definitions by abs_if
paulson
parents: 14738
diff changeset
   709
lemma power_m1_odd: "(-1) ^ Suc(2*n) = (-1::'a::{number_ring,recpower})"
14443
75910c7557c5 generic theorems about exponentials; general tidying up
paulson
parents: 14430
diff changeset
   710
by (simp add: power_mult power_Suc); 
75910c7557c5 generic theorems about exponentials; general tidying up
paulson
parents: 14430
diff changeset
   711
12440
fb5851b71a82 Added code generator setup.
berghofe
parents: 11468
diff changeset
   712
14390
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
   713
subsection{*Literal arithmetic and @{term of_nat}*}
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
   714
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
   715
lemma of_nat_double:
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
   716
     "0 \<le> x ==> of_nat (nat (2 * x)) = of_nat (nat x) + of_nat (nat x)"
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
   717
by (simp only: mult_2 nat_add_distrib of_nat_add) 
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
   718
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
   719
lemma nat_numeral_m1_eq_0: "-1 = (0::nat)"
20217
25b068a99d2b linear arithmetic splits certain operators (e.g. min, max, abs)
webertj
parents: 20105
diff changeset
   720
by (simp only: nat_number_of_def)
14390
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
   721
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
   722
lemma of_nat_number_of_lemma:
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
   723
     "of_nat (number_of v :: nat) =  
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
   724
         (if 0 \<le> (number_of v :: int) 
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
   725
          then (number_of v :: 'a :: number_ring)
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
   726
          else 0)"
15013
34264f5e4691 new treatment of binary numerals
paulson
parents: 15003
diff changeset
   727
by (simp add: int_number_of_def nat_number_of_def number_of_eq of_nat_nat);
14390
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
   728
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
   729
lemma of_nat_number_of_eq [simp]:
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
   730
     "of_nat (number_of v :: nat) =  
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
   731
         (if neg (number_of v :: int) then 0  
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
   732
          else (number_of v :: 'a :: number_ring))"
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
   733
by (simp only: of_nat_number_of_lemma neg_def, simp) 
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
   734
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
   735
14273
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   736
subsection {*Lemmas for the Combination and Cancellation Simprocs*}
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   737
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   738
lemma nat_number_of_add_left:
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   739
     "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
   740
         (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
   741
          else if neg (number_of v' :: int) then number_of v + k  
20485
3078fd2eec7b got rid of Numeral.bin type
haftmann
parents: 20355
diff changeset
   742
          else number_of (v + v') + k)"
14390
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
   743
by simp
14273
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   744
14430
5cb24165a2e1 new material from Avigad, and simplified treatment of division by 0
paulson
parents: 14417
diff changeset
   745
lemma nat_number_of_mult_left:
5cb24165a2e1 new material from Avigad, and simplified treatment of division by 0
paulson
parents: 14417
diff changeset
   746
     "number_of v * (number_of v' * (k::nat)) =  
5cb24165a2e1 new material from Avigad, and simplified treatment of division by 0
paulson
parents: 14417
diff changeset
   747
         (if neg (number_of v :: int) then 0
20485
3078fd2eec7b got rid of Numeral.bin type
haftmann
parents: 20355
diff changeset
   748
          else number_of (v * v') * k)"
14430
5cb24165a2e1 new material from Avigad, and simplified treatment of division by 0
paulson
parents: 14417
diff changeset
   749
by simp
5cb24165a2e1 new material from Avigad, and simplified treatment of division by 0
paulson
parents: 14417
diff changeset
   750
14273
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   751
14390
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
   752
subsubsection{*For @{text combine_numerals}*}
14273
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   753
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   754
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
   755
by (simp add: add_mult_distrib)
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   756
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   757
14390
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
   758
subsubsection{*For @{text cancel_numerals}*}
14273
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   759
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   760
lemma nat_diff_add_eq1:
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   761
     "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
   762
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
   763
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   764
lemma nat_diff_add_eq2:
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   765
     "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
   766
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
   767
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   768
lemma nat_eq_add_iff1:
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   769
     "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
   770
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
   771
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   772
lemma nat_eq_add_iff2:
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   773
     "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
   774
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
   775
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   776
lemma nat_less_add_iff1:
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   777
     "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
   778
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
   779
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   780
lemma nat_less_add_iff2:
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   781
     "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
   782
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
   783
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   784
lemma nat_le_add_iff1:
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   785
     "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
   786
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
   787
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   788
lemma nat_le_add_iff2:
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   789
     "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
   790
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
   791
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   792
14390
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
   793
subsubsection{*For @{text cancel_numeral_factors} *}
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
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
   796
by auto
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   797
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   798
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
   799
by auto
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   800
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   801
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
   802
by auto
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   803
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   804
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
   805
by auto
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   806
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   807
14390
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
   808
subsubsection{*For @{text cancel_factor} *}
14273
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   809
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   810
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
   811
by auto
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   812
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   813
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
   814
by auto
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   815
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   816
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
   817
by auto
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   818
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   819
lemma nat_mult_div_cancel_disj:
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   820
     "(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
   821
by (simp add: nat_mult_div_cancel1)
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   822
20355
50aaae6ae4db cleanup code generation for Numerals
haftmann
parents: 20217
diff changeset
   823
19601
299d4cd2ef51 added codegen preprocessors for numerals
haftmann
parents: 19380
diff changeset
   824
subsection {* legacy ML bindings *}
299d4cd2ef51 added codegen preprocessors for numerals
haftmann
parents: 19380
diff changeset
   825
14273
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   826
ML
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   827
{*
14353
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   828
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
   829
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
   830
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
   831
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
   832
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
   833
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
   834
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
   835
val abs_power2 = thm "abs_power2";
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   836
val power2_abs = thm "power2_abs";
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   837
val power2_minus = thm "power2_minus";
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   838
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
   839
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
   840
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
   841
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
   842
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   843
val Suc_pred' = thm"Suc_pred'";
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   844
val expand_Suc = thm"expand_Suc";
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   845
val Suc_eq_add_numeral_1 = thm"Suc_eq_add_numeral_1";
14467
bbfa6b01a55f new lemma
paulson
parents: 14443
diff changeset
   846
val Suc_eq_add_numeral_1_left = thm"Suc_eq_add_numeral_1_left";
14353
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   847
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
   848
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
   849
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
   850
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
   851
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
   852
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
   853
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
   854
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
   855
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
   856
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
   857
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
   858
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
   859
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
   860
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
   861
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
   862
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
   863
val eq_number_of_Pls_Min = thm"eq_number_of_Pls_Min";
14390
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
   864
val of_nat_number_of_eq = thm"of_nat_number_of_eq";
14353
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   865
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
   866
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
   867
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
   868
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
   869
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
   870
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
   871
val Let_Suc = thm"Let_Suc";
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   872
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   873
val nat_number = thms"nat_number";
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   874
14273
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   875
val nat_number_of_add_left = thm"nat_number_of_add_left";
14430
5cb24165a2e1 new material from Avigad, and simplified treatment of division by 0
paulson
parents: 14417
diff changeset
   876
val nat_number_of_mult_left = thm"nat_number_of_mult_left";
14273
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   877
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
   878
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
   879
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
   880
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
   881
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
   882
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
   883
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
   884
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
   885
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
   886
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
   887
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
   888
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
   889
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
   890
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
   891
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
   892
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
   893
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
   894
79f9fbef9106 Added lemmas to Ring_and_Field with slightly modified simplification rules
paulson
parents: 14288
diff changeset
   895
val power_minus_even = thm"power_minus_even";
14273
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   896
*}
e33ffff0123c further simplifications of the integer development; converting more .ML files
paulson
parents: 14272
diff changeset
   897
7032
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   898
end