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