author | haftmann |
Wed, 15 Apr 2009 15:30:39 +0200 | |
changeset 30925 | c38cbc0ac8d1 |
parent 30685 | src/HOL/NatBin.thy@dd5fe091ff04 |
child 30960 | fec1a04b7220 |
permissions | -rw-r--r-- |
30925 | 1 |
(* Title: HOL/Nat_Numeral.thy |
23164 | 2 |
Author: Lawrence C Paulson, Cambridge University Computer Laboratory |
3 |
Copyright 1999 University of Cambridge |
|
4 |
*) |
|
5 |
||
30925 | 6 |
header {* Binary numerals for the natural numbers *} |
23164 | 7 |
|
30925 | 8 |
theory Nat_Numeral |
23164 | 9 |
imports IntDiv |
30652
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
10 |
uses ("Tools/nat_simprocs.ML") |
23164 | 11 |
begin |
12 |
||
13 |
text {* |
|
14 |
Arithmetic for naturals is reduced to that for the non-negative integers. |
|
15 |
*} |
|
16 |
||
25571
c9e39eafc7a0
instantiation target rather than legacy instance
haftmann
parents:
25481
diff
changeset
|
17 |
instantiation nat :: number |
c9e39eafc7a0
instantiation target rather than legacy instance
haftmann
parents:
25481
diff
changeset
|
18 |
begin |
c9e39eafc7a0
instantiation target rather than legacy instance
haftmann
parents:
25481
diff
changeset
|
19 |
|
c9e39eafc7a0
instantiation target rather than legacy instance
haftmann
parents:
25481
diff
changeset
|
20 |
definition |
28562 | 21 |
nat_number_of_def [code inline, code del]: "number_of v = nat (number_of v)" |
25571
c9e39eafc7a0
instantiation target rather than legacy instance
haftmann
parents:
25481
diff
changeset
|
22 |
|
c9e39eafc7a0
instantiation target rather than legacy instance
haftmann
parents:
25481
diff
changeset
|
23 |
instance .. |
c9e39eafc7a0
instantiation target rather than legacy instance
haftmann
parents:
25481
diff
changeset
|
24 |
|
c9e39eafc7a0
instantiation target rather than legacy instance
haftmann
parents:
25481
diff
changeset
|
25 |
end |
23164 | 26 |
|
25965 | 27 |
lemma [code post]: |
28 |
"nat (number_of v) = number_of v" |
|
29 |
unfolding nat_number_of_def .. |
|
30 |
||
23164 | 31 |
abbreviation (xsymbols) |
29401
94fd5dd918f5
rename abbreviation square -> power2, to match theorem names
huffman
parents:
29045
diff
changeset
|
32 |
power2 :: "'a::power => 'a" ("(_\<twosuperior>)" [1000] 999) where |
23164 | 33 |
"x\<twosuperior> == x^2" |
34 |
||
35 |
notation (latex output) |
|
29401
94fd5dd918f5
rename abbreviation square -> power2, to match theorem names
huffman
parents:
29045
diff
changeset
|
36 |
power2 ("(_\<twosuperior>)" [1000] 999) |
23164 | 37 |
|
38 |
notation (HTML output) |
|
29401
94fd5dd918f5
rename abbreviation square -> power2, to match theorem names
huffman
parents:
29045
diff
changeset
|
39 |
power2 ("(_\<twosuperior>)" [1000] 999) |
23164 | 40 |
|
41 |
||
29040
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
huffman
parents:
29039
diff
changeset
|
42 |
subsection {* Predicate for negative binary numbers *} |
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
huffman
parents:
29039
diff
changeset
|
43 |
|
30652
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
44 |
definition neg :: "int \<Rightarrow> bool" where |
29040
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
huffman
parents:
29039
diff
changeset
|
45 |
"neg Z \<longleftrightarrow> Z < 0" |
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
huffman
parents:
29039
diff
changeset
|
46 |
|
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
huffman
parents:
29039
diff
changeset
|
47 |
lemma not_neg_int [simp]: "~ neg (of_nat n)" |
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
huffman
parents:
29039
diff
changeset
|
48 |
by (simp add: neg_def) |
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
huffman
parents:
29039
diff
changeset
|
49 |
|
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
huffman
parents:
29039
diff
changeset
|
50 |
lemma neg_zminus_int [simp]: "neg (- (of_nat (Suc n)))" |
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
huffman
parents:
29039
diff
changeset
|
51 |
by (simp add: neg_def neg_less_0_iff_less del: of_nat_Suc) |
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
huffman
parents:
29039
diff
changeset
|
52 |
|
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
huffman
parents:
29039
diff
changeset
|
53 |
lemmas neg_eq_less_0 = neg_def |
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
huffman
parents:
29039
diff
changeset
|
54 |
|
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
huffman
parents:
29039
diff
changeset
|
55 |
lemma not_neg_eq_ge_0: "(~neg x) = (0 \<le> x)" |
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
huffman
parents:
29039
diff
changeset
|
56 |
by (simp add: neg_def linorder_not_less) |
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
huffman
parents:
29039
diff
changeset
|
57 |
|
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
huffman
parents:
29039
diff
changeset
|
58 |
text{*To simplify inequalities when Numeral1 can get simplified to 1*} |
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
huffman
parents:
29039
diff
changeset
|
59 |
|
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
huffman
parents:
29039
diff
changeset
|
60 |
lemma not_neg_0: "~ neg 0" |
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
huffman
parents:
29039
diff
changeset
|
61 |
by (simp add: One_int_def neg_def) |
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
huffman
parents:
29039
diff
changeset
|
62 |
|
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
huffman
parents:
29039
diff
changeset
|
63 |
lemma not_neg_1: "~ neg 1" |
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
huffman
parents:
29039
diff
changeset
|
64 |
by (simp add: neg_def linorder_not_less zero_le_one) |
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
huffman
parents:
29039
diff
changeset
|
65 |
|
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
huffman
parents:
29039
diff
changeset
|
66 |
lemma neg_nat: "neg z ==> nat z = 0" |
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
huffman
parents:
29039
diff
changeset
|
67 |
by (simp add: neg_def order_less_imp_le) |
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
huffman
parents:
29039
diff
changeset
|
68 |
|
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
huffman
parents:
29039
diff
changeset
|
69 |
lemma not_neg_nat: "~ neg z ==> of_nat (nat z) = z" |
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
huffman
parents:
29039
diff
changeset
|
70 |
by (simp add: linorder_not_less neg_def) |
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
huffman
parents:
29039
diff
changeset
|
71 |
|
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
huffman
parents:
29039
diff
changeset
|
72 |
text {* |
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
huffman
parents:
29039
diff
changeset
|
73 |
If @{term Numeral0} is rewritten to 0 then this rule can't be applied: |
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
huffman
parents:
29039
diff
changeset
|
74 |
@{term Numeral0} IS @{term "number_of Pls"} |
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
huffman
parents:
29039
diff
changeset
|
75 |
*} |
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
huffman
parents:
29039
diff
changeset
|
76 |
|
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
huffman
parents:
29039
diff
changeset
|
77 |
lemma not_neg_number_of_Pls: "~ neg (number_of Int.Pls)" |
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
huffman
parents:
29039
diff
changeset
|
78 |
by (simp add: neg_def) |
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
huffman
parents:
29039
diff
changeset
|
79 |
|
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
huffman
parents:
29039
diff
changeset
|
80 |
lemma neg_number_of_Min: "neg (number_of Int.Min)" |
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
huffman
parents:
29039
diff
changeset
|
81 |
by (simp add: neg_def) |
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
huffman
parents:
29039
diff
changeset
|
82 |
|
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
huffman
parents:
29039
diff
changeset
|
83 |
lemma neg_number_of_Bit0: |
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
huffman
parents:
29039
diff
changeset
|
84 |
"neg (number_of (Int.Bit0 w)) = neg (number_of w)" |
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
huffman
parents:
29039
diff
changeset
|
85 |
by (simp add: neg_def) |
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
huffman
parents:
29039
diff
changeset
|
86 |
|
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
huffman
parents:
29039
diff
changeset
|
87 |
lemma neg_number_of_Bit1: |
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
huffman
parents:
29039
diff
changeset
|
88 |
"neg (number_of (Int.Bit1 w)) = neg (number_of w)" |
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
huffman
parents:
29039
diff
changeset
|
89 |
by (simp add: neg_def) |
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
huffman
parents:
29039
diff
changeset
|
90 |
|
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
huffman
parents:
29039
diff
changeset
|
91 |
lemmas neg_simps [simp] = |
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
huffman
parents:
29039
diff
changeset
|
92 |
not_neg_0 not_neg_1 |
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
huffman
parents:
29039
diff
changeset
|
93 |
not_neg_number_of_Pls neg_number_of_Min |
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
huffman
parents:
29039
diff
changeset
|
94 |
neg_number_of_Bit0 neg_number_of_Bit1 |
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
huffman
parents:
29039
diff
changeset
|
95 |
|
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
huffman
parents:
29039
diff
changeset
|
96 |
|
23164 | 97 |
subsection{*Function @{term nat}: Coercion from Type @{typ int} to @{typ nat}*} |
98 |
||
99 |
declare nat_0 [simp] nat_1 [simp] |
|
100 |
||
101 |
lemma nat_number_of [simp]: "nat (number_of w) = number_of w" |
|
102 |
by (simp add: nat_number_of_def) |
|
103 |
||
104 |
lemma nat_numeral_0_eq_0 [simp]: "Numeral0 = (0::nat)" |
|
105 |
by (simp add: nat_number_of_def) |
|
106 |
||
107 |
lemma nat_numeral_1_eq_1 [simp]: "Numeral1 = (1::nat)" |
|
108 |
by (simp add: nat_1 nat_number_of_def) |
|
109 |
||
110 |
lemma numeral_1_eq_Suc_0: "Numeral1 = Suc 0" |
|
111 |
by (simp add: nat_numeral_1_eq_1) |
|
112 |
||
113 |
lemma numeral_2_eq_2: "2 = Suc (Suc 0)" |
|
114 |
apply (unfold nat_number_of_def) |
|
115 |
apply (rule nat_2) |
|
116 |
done |
|
117 |
||
118 |
||
119 |
subsection{*Function @{term int}: Coercion from Type @{typ nat} to @{typ int}*} |
|
120 |
||
121 |
lemma int_nat_number_of [simp]: |
|
23365 | 122 |
"int (number_of v) = |
23307
2fe3345035c7
modify proofs to avoid referring to int::nat=>int
huffman
parents:
23294
diff
changeset
|
123 |
(if neg (number_of v :: int) then 0 |
2fe3345035c7
modify proofs to avoid referring to int::nat=>int
huffman
parents:
23294
diff
changeset
|
124 |
else (number_of v :: int))" |
28984 | 125 |
unfolding nat_number_of_def number_of_is_id neg_def |
126 |
by simp |
|
23307
2fe3345035c7
modify proofs to avoid referring to int::nat=>int
huffman
parents:
23294
diff
changeset
|
127 |
|
23164 | 128 |
|
129 |
subsubsection{*Successor *} |
|
130 |
||
131 |
lemma Suc_nat_eq_nat_zadd1: "(0::int) <= z ==> Suc (nat z) = nat (1 + z)" |
|
132 |
apply (rule sym) |
|
133 |
apply (simp add: nat_eq_iff int_Suc) |
|
134 |
done |
|
135 |
||
136 |
lemma Suc_nat_number_of_add: |
|
137 |
"Suc (number_of v + n) = |
|
28984 | 138 |
(if neg (number_of v :: int) then 1+n else number_of (Int.succ v) + n)" |
139 |
unfolding nat_number_of_def number_of_is_id neg_def numeral_simps |
|
140 |
by (simp add: Suc_nat_eq_nat_zadd1 add_ac) |
|
23164 | 141 |
|
142 |
lemma Suc_nat_number_of [simp]: |
|
143 |
"Suc (number_of v) = |
|
25919
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
25571
diff
changeset
|
144 |
(if neg (number_of v :: int) then 1 else number_of (Int.succ v))" |
23164 | 145 |
apply (cut_tac n = 0 in Suc_nat_number_of_add) |
146 |
apply (simp cong del: if_weak_cong) |
|
147 |
done |
|
148 |
||
149 |
||
150 |
subsubsection{*Addition *} |
|
151 |
||
152 |
lemma add_nat_number_of [simp]: |
|
153 |
"(number_of v :: nat) + number_of v' = |
|
29012 | 154 |
(if v < Int.Pls then number_of v' |
155 |
else if v' < Int.Pls then number_of v |
|
23164 | 156 |
else number_of (v + v'))" |
29012 | 157 |
unfolding nat_number_of_def number_of_is_id numeral_simps |
28984 | 158 |
by (simp add: nat_add_distrib) |
23164 | 159 |
|
30081 | 160 |
lemma nat_number_of_add_1 [simp]: |
161 |
"number_of v + (1::nat) = |
|
162 |
(if v < Int.Pls then 1 else number_of (Int.succ v))" |
|
163 |
unfolding nat_number_of_def number_of_is_id numeral_simps |
|
164 |
by (simp add: nat_add_distrib) |
|
165 |
||
166 |
lemma nat_1_add_number_of [simp]: |
|
167 |
"(1::nat) + number_of v = |
|
168 |
(if v < Int.Pls then 1 else number_of (Int.succ v))" |
|
169 |
unfolding nat_number_of_def number_of_is_id numeral_simps |
|
170 |
by (simp add: nat_add_distrib) |
|
171 |
||
172 |
lemma nat_1_add_1 [simp]: "1 + 1 = (2::nat)" |
|
173 |
by (rule int_int_eq [THEN iffD1]) simp |
|
174 |
||
23164 | 175 |
|
176 |
subsubsection{*Subtraction *} |
|
177 |
||
178 |
lemma diff_nat_eq_if: |
|
179 |
"nat z - nat z' = |
|
180 |
(if neg z' then nat z |
|
181 |
else let d = z-z' in |
|
182 |
if neg d then 0 else nat d)" |
|
27651
16a26996c30e
moved op dvd to theory Ring_and_Field; generalized a couple of lemmas
haftmann
parents:
26342
diff
changeset
|
183 |
by (simp add: Let_def nat_diff_distrib [symmetric] neg_eq_less_0 not_neg_eq_ge_0) |
16a26996c30e
moved op dvd to theory Ring_and_Field; generalized a couple of lemmas
haftmann
parents:
26342
diff
changeset
|
184 |
|
23164 | 185 |
|
186 |
lemma diff_nat_number_of [simp]: |
|
187 |
"(number_of v :: nat) - number_of v' = |
|
29012 | 188 |
(if v' < Int.Pls then number_of v |
23164 | 189 |
else let d = number_of (v + uminus v') in |
190 |
if neg d then 0 else nat d)" |
|
29012 | 191 |
unfolding nat_number_of_def number_of_is_id numeral_simps neg_def |
192 |
by auto |
|
23164 | 193 |
|
30081 | 194 |
lemma nat_number_of_diff_1 [simp]: |
195 |
"number_of v - (1::nat) = |
|
196 |
(if v \<le> Int.Pls then 0 else number_of (Int.pred v))" |
|
197 |
unfolding nat_number_of_def number_of_is_id numeral_simps |
|
198 |
by auto |
|
199 |
||
23164 | 200 |
|
201 |
subsubsection{*Multiplication *} |
|
202 |
||
203 |
lemma mult_nat_number_of [simp]: |
|
204 |
"(number_of v :: nat) * number_of v' = |
|
29012 | 205 |
(if v < Int.Pls then 0 else number_of (v * v'))" |
206 |
unfolding nat_number_of_def number_of_is_id numeral_simps |
|
28984 | 207 |
by (simp add: nat_mult_distrib) |
23164 | 208 |
|
209 |
||
210 |
subsubsection{*Quotient *} |
|
211 |
||
212 |
lemma div_nat_number_of [simp]: |
|
213 |
"(number_of v :: nat) div number_of v' = |
|
214 |
(if neg (number_of v :: int) then 0 |
|
215 |
else nat (number_of v div number_of v'))" |
|
28984 | 216 |
unfolding nat_number_of_def number_of_is_id neg_def |
217 |
by (simp add: nat_div_distrib) |
|
23164 | 218 |
|
219 |
lemma one_div_nat_number_of [simp]: |
|
27651
16a26996c30e
moved op dvd to theory Ring_and_Field; generalized a couple of lemmas
haftmann
parents:
26342
diff
changeset
|
220 |
"Suc 0 div number_of v' = nat (1 div number_of v')" |
23164 | 221 |
by (simp del: nat_numeral_1_eq_1 add: numeral_1_eq_Suc_0 [symmetric]) |
222 |
||
223 |
||
224 |
subsubsection{*Remainder *} |
|
225 |
||
226 |
lemma mod_nat_number_of [simp]: |
|
227 |
"(number_of v :: nat) mod number_of v' = |
|
228 |
(if neg (number_of v :: int) then 0 |
|
229 |
else if neg (number_of v' :: int) then number_of v |
|
230 |
else nat (number_of v mod number_of v'))" |
|
28984 | 231 |
unfolding nat_number_of_def number_of_is_id neg_def |
232 |
by (simp add: nat_mod_distrib) |
|
23164 | 233 |
|
234 |
lemma one_mod_nat_number_of [simp]: |
|
27651
16a26996c30e
moved op dvd to theory Ring_and_Field; generalized a couple of lemmas
haftmann
parents:
26342
diff
changeset
|
235 |
"Suc 0 mod number_of v' = |
23164 | 236 |
(if neg (number_of v' :: int) then Suc 0 |
237 |
else nat (1 mod number_of v'))" |
|
238 |
by (simp del: nat_numeral_1_eq_1 add: numeral_1_eq_Suc_0 [symmetric]) |
|
239 |
||
240 |
||
241 |
subsubsection{* Divisibility *} |
|
242 |
||
243 |
lemmas dvd_eq_mod_eq_0_number_of = |
|
244 |
dvd_eq_mod_eq_0 [of "number_of x" "number_of y", standard] |
|
245 |
||
246 |
declare dvd_eq_mod_eq_0_number_of [simp] |
|
247 |
||
248 |
ML |
|
249 |
{* |
|
250 |
val nat_number_of_def = thm"nat_number_of_def"; |
|
251 |
||
252 |
val nat_number_of = thm"nat_number_of"; |
|
253 |
val nat_numeral_0_eq_0 = thm"nat_numeral_0_eq_0"; |
|
254 |
val nat_numeral_1_eq_1 = thm"nat_numeral_1_eq_1"; |
|
255 |
val numeral_1_eq_Suc_0 = thm"numeral_1_eq_Suc_0"; |
|
256 |
val numeral_2_eq_2 = thm"numeral_2_eq_2"; |
|
257 |
val nat_div_distrib = thm"nat_div_distrib"; |
|
258 |
val nat_mod_distrib = thm"nat_mod_distrib"; |
|
259 |
val int_nat_number_of = thm"int_nat_number_of"; |
|
260 |
val Suc_nat_eq_nat_zadd1 = thm"Suc_nat_eq_nat_zadd1"; |
|
261 |
val Suc_nat_number_of_add = thm"Suc_nat_number_of_add"; |
|
262 |
val Suc_nat_number_of = thm"Suc_nat_number_of"; |
|
263 |
val add_nat_number_of = thm"add_nat_number_of"; |
|
264 |
val diff_nat_eq_if = thm"diff_nat_eq_if"; |
|
265 |
val diff_nat_number_of = thm"diff_nat_number_of"; |
|
266 |
val mult_nat_number_of = thm"mult_nat_number_of"; |
|
267 |
val div_nat_number_of = thm"div_nat_number_of"; |
|
268 |
val mod_nat_number_of = thm"mod_nat_number_of"; |
|
269 |
*} |
|
270 |
||
271 |
||
272 |
subsection{*Comparisons*} |
|
273 |
||
274 |
subsubsection{*Equals (=) *} |
|
275 |
||
276 |
lemma eq_nat_nat_iff: |
|
277 |
"[| (0::int) <= z; 0 <= z' |] ==> (nat z = nat z') = (z=z')" |
|
278 |
by (auto elim!: nonneg_eq_int) |
|
279 |
||
280 |
lemma eq_nat_number_of [simp]: |
|
281 |
"((number_of v :: nat) = number_of v') = |
|
28969 | 282 |
(if neg (number_of v :: int) then (number_of v' :: int) \<le> 0 |
283 |
else if neg (number_of v' :: int) then (number_of v :: int) = 0 |
|
284 |
else v = v')" |
|
285 |
unfolding nat_number_of_def number_of_is_id neg_def |
|
286 |
by auto |
|
23164 | 287 |
|
288 |
||
289 |
subsubsection{*Less-than (<) *} |
|
290 |
||
291 |
lemma less_nat_number_of [simp]: |
|
29011 | 292 |
"(number_of v :: nat) < number_of v' \<longleftrightarrow> |
293 |
(if v < v' then Int.Pls < v' else False)" |
|
294 |
unfolding nat_number_of_def number_of_is_id numeral_simps |
|
28961 | 295 |
by auto |
23164 | 296 |
|
297 |
||
29010 | 298 |
subsubsection{*Less-than-or-equal *} |
299 |
||
300 |
lemma le_nat_number_of [simp]: |
|
301 |
"(number_of v :: nat) \<le> number_of v' \<longleftrightarrow> |
|
302 |
(if v \<le> v' then True else v \<le> Int.Pls)" |
|
303 |
unfolding nat_number_of_def number_of_is_id numeral_simps |
|
304 |
by auto |
|
305 |
||
23164 | 306 |
(*Maps #n to n for n = 0, 1, 2*) |
307 |
lemmas numerals = nat_numeral_0_eq_0 nat_numeral_1_eq_1 numeral_2_eq_2 |
|
308 |
||
309 |
||
310 |
subsection{*Powers with Numeric Exponents*} |
|
311 |
||
312 |
text{*We cannot refer to the number @{term 2} in @{text Ring_and_Field.thy}. |
|
313 |
We cannot prove general results about the numeral @{term "-1"}, so we have to |
|
314 |
use @{term "- 1"} instead.*} |
|
315 |
||
23277 | 316 |
lemma power2_eq_square: "(a::'a::recpower)\<twosuperior> = a * a" |
23164 | 317 |
by (simp add: numeral_2_eq_2 Power.power_Suc) |
318 |
||
23277 | 319 |
lemma zero_power2 [simp]: "(0::'a::{semiring_1,recpower})\<twosuperior> = 0" |
23164 | 320 |
by (simp add: power2_eq_square) |
321 |
||
23277 | 322 |
lemma one_power2 [simp]: "(1::'a::{semiring_1,recpower})\<twosuperior> = 1" |
23164 | 323 |
by (simp add: power2_eq_square) |
324 |
||
325 |
lemma power3_eq_cube: "(x::'a::recpower) ^ 3 = x * x * x" |
|
326 |
apply (subgoal_tac "3 = Suc (Suc (Suc 0))") |
|
327 |
apply (erule ssubst) |
|
328 |
apply (simp add: power_Suc mult_ac) |
|
329 |
apply (unfold nat_number_of_def) |
|
330 |
apply (subst nat_eq_iff) |
|
331 |
apply simp |
|
332 |
done |
|
333 |
||
334 |
text{*Squares of literal numerals will be evaluated.*} |
|
335 |
lemmas power2_eq_square_number_of = |
|
336 |
power2_eq_square [of "number_of w", standard] |
|
337 |
declare power2_eq_square_number_of [simp] |
|
338 |
||
339 |
||
340 |
lemma zero_le_power2[simp]: "0 \<le> (a\<twosuperior>::'a::{ordered_idom,recpower})" |
|
341 |
by (simp add: power2_eq_square) |
|
342 |
||
343 |
lemma zero_less_power2[simp]: |
|
344 |
"(0 < a\<twosuperior>) = (a \<noteq> (0::'a::{ordered_idom,recpower}))" |
|
345 |
by (force simp add: power2_eq_square zero_less_mult_iff linorder_neq_iff) |
|
346 |
||
347 |
lemma power2_less_0[simp]: |
|
348 |
fixes a :: "'a::{ordered_idom,recpower}" |
|
349 |
shows "~ (a\<twosuperior> < 0)" |
|
350 |
by (force simp add: power2_eq_square mult_less_0_iff) |
|
351 |
||
352 |
lemma zero_eq_power2[simp]: |
|
353 |
"(a\<twosuperior> = 0) = (a = (0::'a::{ordered_idom,recpower}))" |
|
354 |
by (force simp add: power2_eq_square mult_eq_0_iff) |
|
355 |
||
356 |
lemma abs_power2[simp]: |
|
357 |
"abs(a\<twosuperior>) = (a\<twosuperior>::'a::{ordered_idom,recpower})" |
|
358 |
by (simp add: power2_eq_square abs_mult abs_mult_self) |
|
359 |
||
360 |
lemma power2_abs[simp]: |
|
361 |
"(abs a)\<twosuperior> = (a\<twosuperior>::'a::{ordered_idom,recpower})" |
|
362 |
by (simp add: power2_eq_square abs_mult_self) |
|
363 |
||
364 |
lemma power2_minus[simp]: |
|
365 |
"(- a)\<twosuperior> = (a\<twosuperior>::'a::{comm_ring_1,recpower})" |
|
366 |
by (simp add: power2_eq_square) |
|
367 |
||
368 |
lemma power2_le_imp_le: |
|
369 |
fixes x y :: "'a::{ordered_semidom,recpower}" |
|
370 |
shows "\<lbrakk>x\<twosuperior> \<le> y\<twosuperior>; 0 \<le> y\<rbrakk> \<Longrightarrow> x \<le> y" |
|
371 |
unfolding numeral_2_eq_2 by (rule power_le_imp_le_base) |
|
372 |
||
373 |
lemma power2_less_imp_less: |
|
374 |
fixes x y :: "'a::{ordered_semidom,recpower}" |
|
375 |
shows "\<lbrakk>x\<twosuperior> < y\<twosuperior>; 0 \<le> y\<rbrakk> \<Longrightarrow> x < y" |
|
376 |
by (rule power_less_imp_less_base) |
|
377 |
||
378 |
lemma power2_eq_imp_eq: |
|
379 |
fixes x y :: "'a::{ordered_semidom,recpower}" |
|
380 |
shows "\<lbrakk>x\<twosuperior> = y\<twosuperior>; 0 \<le> x; 0 \<le> y\<rbrakk> \<Longrightarrow> x = y" |
|
381 |
unfolding numeral_2_eq_2 by (erule (2) power_eq_imp_eq_base, simp) |
|
382 |
||
383 |
lemma power_minus1_even[simp]: "(- 1) ^ (2*n) = (1::'a::{comm_ring_1,recpower})" |
|
29958 | 384 |
proof (induct n) |
385 |
case 0 show ?case by simp |
|
386 |
next |
|
387 |
case (Suc n) then show ?case by (simp add: power_Suc power_add) |
|
388 |
qed |
|
389 |
||
390 |
lemma power_minus1_odd: "(- 1) ^ Suc(2*n) = -(1::'a::{comm_ring_1,recpower})" |
|
391 |
by (simp add: power_Suc) |
|
23164 | 392 |
|
393 |
lemma power_even_eq: "(a::'a::recpower) ^ (2*n) = (a^n)^2" |
|
394 |
by (subst mult_commute) (simp add: power_mult) |
|
395 |
||
396 |
lemma power_odd_eq: "(a::int) ^ Suc(2*n) = a * (a^n)^2" |
|
397 |
by (simp add: power_even_eq) |
|
398 |
||
399 |
lemma power_minus_even [simp]: |
|
400 |
"(-a) ^ (2*n) = (a::'a::{comm_ring_1,recpower}) ^ (2*n)" |
|
401 |
by (simp add: power_minus1_even power_minus [of a]) |
|
402 |
||
403 |
lemma zero_le_even_power'[simp]: |
|
404 |
"0 \<le> (a::'a::{ordered_idom,recpower}) ^ (2*n)" |
|
405 |
proof (induct "n") |
|
406 |
case 0 |
|
407 |
show ?case by (simp add: zero_le_one) |
|
408 |
next |
|
409 |
case (Suc n) |
|
410 |
have "a ^ (2 * Suc n) = (a*a) * a ^ (2*n)" |
|
411 |
by (simp add: mult_ac power_add power2_eq_square) |
|
412 |
thus ?case |
|
413 |
by (simp add: prems zero_le_mult_iff) |
|
414 |
qed |
|
415 |
||
416 |
lemma odd_power_less_zero: |
|
417 |
"(a::'a::{ordered_idom,recpower}) < 0 ==> a ^ Suc(2*n) < 0" |
|
418 |
proof (induct "n") |
|
419 |
case 0 |
|
30273
ecd6f0ca62ea
declare power_Suc [simp]; remove redundant type-specific versions of power_Suc
huffman
parents:
30242
diff
changeset
|
420 |
then show ?case by simp |
23164 | 421 |
next |
422 |
case (Suc n) |
|
30273
ecd6f0ca62ea
declare power_Suc [simp]; remove redundant type-specific versions of power_Suc
huffman
parents:
30242
diff
changeset
|
423 |
have "a ^ Suc (2 * Suc n) = (a*a) * a ^ Suc(2*n)" |
ecd6f0ca62ea
declare power_Suc [simp]; remove redundant type-specific versions of power_Suc
huffman
parents:
30242
diff
changeset
|
424 |
by (simp add: mult_ac power_add power2_eq_square) |
23389 | 425 |
thus ?case |
30273
ecd6f0ca62ea
declare power_Suc [simp]; remove redundant type-specific versions of power_Suc
huffman
parents:
30242
diff
changeset
|
426 |
by (simp del: power_Suc add: prems mult_less_0_iff mult_neg_neg) |
23164 | 427 |
qed |
428 |
||
429 |
lemma odd_0_le_power_imp_0_le: |
|
430 |
"0 \<le> a ^ Suc(2*n) ==> 0 \<le> (a::'a::{ordered_idom,recpower})" |
|
431 |
apply (insert odd_power_less_zero [of a n]) |
|
432 |
apply (force simp add: linorder_not_less [symmetric]) |
|
433 |
done |
|
434 |
||
435 |
text{*Simprules for comparisons where common factors can be cancelled.*} |
|
436 |
lemmas zero_compare_simps = |
|
437 |
add_strict_increasing add_strict_increasing2 add_increasing |
|
438 |
zero_le_mult_iff zero_le_divide_iff |
|
439 |
zero_less_mult_iff zero_less_divide_iff |
|
440 |
mult_le_0_iff divide_le_0_iff |
|
441 |
mult_less_0_iff divide_less_0_iff |
|
442 |
zero_le_power2 power2_less_0 |
|
443 |
||
444 |
subsubsection{*Nat *} |
|
445 |
||
446 |
lemma Suc_pred': "0 < n ==> n = Suc(n - 1)" |
|
447 |
by (simp add: numerals) |
|
448 |
||
449 |
(*Expresses a natural number constant as the Suc of another one. |
|
450 |
NOT suitable for rewriting because n recurs in the condition.*) |
|
451 |
lemmas expand_Suc = Suc_pred' [of "number_of v", standard] |
|
452 |
||
453 |
subsubsection{*Arith *} |
|
454 |
||
455 |
lemma Suc_eq_add_numeral_1: "Suc n = n + 1" |
|
456 |
by (simp add: numerals) |
|
457 |
||
458 |
lemma Suc_eq_add_numeral_1_left: "Suc n = 1 + n" |
|
459 |
by (simp add: numerals) |
|
460 |
||
461 |
(* These two can be useful when m = number_of... *) |
|
462 |
||
463 |
lemma add_eq_if: "(m::nat) + n = (if m=0 then n else Suc ((m - 1) + n))" |
|
30079
293b896b9c25
make proofs work whether or not One_nat_def is a simp rule; replace 1 with Suc 0 in the rhs of some simp rules
huffman
parents:
29958
diff
changeset
|
464 |
unfolding One_nat_def by (cases m) simp_all |
23164 | 465 |
|
466 |
lemma mult_eq_if: "(m::nat) * n = (if m=0 then 0 else n + ((m - 1) * n))" |
|
30079
293b896b9c25
make proofs work whether or not One_nat_def is a simp rule; replace 1 with Suc 0 in the rhs of some simp rules
huffman
parents:
29958
diff
changeset
|
467 |
unfolding One_nat_def by (cases m) simp_all |
23164 | 468 |
|
469 |
lemma power_eq_if: "(p ^ m :: nat) = (if m=0 then 1 else p * (p ^ (m - 1)))" |
|
30079
293b896b9c25
make proofs work whether or not One_nat_def is a simp rule; replace 1 with Suc 0 in the rhs of some simp rules
huffman
parents:
29958
diff
changeset
|
470 |
unfolding One_nat_def by (cases m) simp_all |
23164 | 471 |
|
472 |
||
473 |
subsection{*Comparisons involving (0::nat) *} |
|
474 |
||
475 |
text{*Simplification already does @{term "n<0"}, @{term "n\<le>0"} and @{term "0\<le>n"}.*} |
|
476 |
||
477 |
lemma eq_number_of_0 [simp]: |
|
29012 | 478 |
"number_of v = (0::nat) \<longleftrightarrow> v \<le> Int.Pls" |
479 |
unfolding nat_number_of_def number_of_is_id numeral_simps |
|
480 |
by auto |
|
23164 | 481 |
|
482 |
lemma eq_0_number_of [simp]: |
|
29012 | 483 |
"(0::nat) = number_of v \<longleftrightarrow> v \<le> Int.Pls" |
23164 | 484 |
by (rule trans [OF eq_sym_conv eq_number_of_0]) |
485 |
||
486 |
lemma less_0_number_of [simp]: |
|
29012 | 487 |
"(0::nat) < number_of v \<longleftrightarrow> Int.Pls < v" |
488 |
unfolding nat_number_of_def number_of_is_id numeral_simps |
|
489 |
by simp |
|
23164 | 490 |
|
491 |
lemma neg_imp_number_of_eq_0: "neg (number_of v :: int) ==> number_of v = (0::nat)" |
|
28969 | 492 |
by (simp del: nat_numeral_0_eq_0 add: nat_numeral_0_eq_0 [symmetric]) |
23164 | 493 |
|
494 |
||
495 |
||
496 |
subsection{*Comparisons involving @{term Suc} *} |
|
497 |
||
498 |
lemma eq_number_of_Suc [simp]: |
|
499 |
"(number_of v = Suc n) = |
|
25919
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
25571
diff
changeset
|
500 |
(let pv = number_of (Int.pred v) in |
23164 | 501 |
if neg pv then False else nat pv = n)" |
502 |
apply (simp only: simp_thms Let_def neg_eq_less_0 linorder_not_less |
|
503 |
number_of_pred nat_number_of_def |
|
504 |
split add: split_if) |
|
505 |
apply (rule_tac x = "number_of v" in spec) |
|
506 |
apply (auto simp add: nat_eq_iff) |
|
507 |
done |
|
508 |
||
509 |
lemma Suc_eq_number_of [simp]: |
|
510 |
"(Suc n = number_of v) = |
|
25919
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
25571
diff
changeset
|
511 |
(let pv = number_of (Int.pred v) in |
23164 | 512 |
if neg pv then False else nat pv = n)" |
513 |
by (rule trans [OF eq_sym_conv eq_number_of_Suc]) |
|
514 |
||
515 |
lemma less_number_of_Suc [simp]: |
|
516 |
"(number_of v < Suc n) = |
|
25919
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
25571
diff
changeset
|
517 |
(let pv = number_of (Int.pred v) in |
23164 | 518 |
if neg pv then True else nat pv < n)" |
519 |
apply (simp only: simp_thms Let_def neg_eq_less_0 linorder_not_less |
|
520 |
number_of_pred nat_number_of_def |
|
521 |
split add: split_if) |
|
522 |
apply (rule_tac x = "number_of v" in spec) |
|
523 |
apply (auto simp add: nat_less_iff) |
|
524 |
done |
|
525 |
||
526 |
lemma less_Suc_number_of [simp]: |
|
527 |
"(Suc n < number_of v) = |
|
25919
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
25571
diff
changeset
|
528 |
(let pv = number_of (Int.pred v) in |
23164 | 529 |
if neg pv then False else n < nat pv)" |
530 |
apply (simp only: simp_thms Let_def neg_eq_less_0 linorder_not_less |
|
531 |
number_of_pred nat_number_of_def |
|
532 |
split add: split_if) |
|
533 |
apply (rule_tac x = "number_of v" in spec) |
|
534 |
apply (auto simp add: zless_nat_eq_int_zless) |
|
535 |
done |
|
536 |
||
537 |
lemma le_number_of_Suc [simp]: |
|
538 |
"(number_of v <= Suc n) = |
|
25919
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
25571
diff
changeset
|
539 |
(let pv = number_of (Int.pred v) in |
23164 | 540 |
if neg pv then True else nat pv <= n)" |
541 |
by (simp add: Let_def less_Suc_number_of linorder_not_less [symmetric]) |
|
542 |
||
543 |
lemma le_Suc_number_of [simp]: |
|
544 |
"(Suc n <= number_of v) = |
|
25919
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
25571
diff
changeset
|
545 |
(let pv = number_of (Int.pred v) in |
23164 | 546 |
if neg pv then False else n <= nat pv)" |
547 |
by (simp add: Let_def less_number_of_Suc linorder_not_less [symmetric]) |
|
548 |
||
549 |
||
25919
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
25571
diff
changeset
|
550 |
lemma eq_number_of_Pls_Min: "(Numeral0 ::int) ~= number_of Int.Min" |
23164 | 551 |
by auto |
552 |
||
553 |
||
554 |
||
555 |
subsection{*Max and Min Combined with @{term Suc} *} |
|
556 |
||
557 |
lemma max_number_of_Suc [simp]: |
|
558 |
"max (Suc n) (number_of v) = |
|
25919
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
25571
diff
changeset
|
559 |
(let pv = number_of (Int.pred v) in |
23164 | 560 |
if neg pv then Suc n else Suc(max n (nat pv)))" |
561 |
apply (simp only: Let_def neg_eq_less_0 number_of_pred nat_number_of_def |
|
562 |
split add: split_if nat.split) |
|
563 |
apply (rule_tac x = "number_of v" in spec) |
|
564 |
apply auto |
|
565 |
done |
|
566 |
||
567 |
lemma max_Suc_number_of [simp]: |
|
568 |
"max (number_of v) (Suc n) = |
|
25919
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
25571
diff
changeset
|
569 |
(let pv = number_of (Int.pred v) in |
23164 | 570 |
if neg pv then Suc n else Suc(max (nat pv) n))" |
571 |
apply (simp only: Let_def neg_eq_less_0 number_of_pred nat_number_of_def |
|
572 |
split add: split_if nat.split) |
|
573 |
apply (rule_tac x = "number_of v" in spec) |
|
574 |
apply auto |
|
575 |
done |
|
576 |
||
577 |
lemma min_number_of_Suc [simp]: |
|
578 |
"min (Suc n) (number_of v) = |
|
25919
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
25571
diff
changeset
|
579 |
(let pv = number_of (Int.pred v) in |
23164 | 580 |
if neg pv then 0 else Suc(min n (nat pv)))" |
581 |
apply (simp only: Let_def neg_eq_less_0 number_of_pred nat_number_of_def |
|
582 |
split add: split_if nat.split) |
|
583 |
apply (rule_tac x = "number_of v" in spec) |
|
584 |
apply auto |
|
585 |
done |
|
586 |
||
587 |
lemma min_Suc_number_of [simp]: |
|
588 |
"min (number_of v) (Suc n) = |
|
25919
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
25571
diff
changeset
|
589 |
(let pv = number_of (Int.pred v) in |
23164 | 590 |
if neg pv then 0 else Suc(min (nat pv) n))" |
591 |
apply (simp only: Let_def neg_eq_less_0 number_of_pred nat_number_of_def |
|
592 |
split add: split_if nat.split) |
|
593 |
apply (rule_tac x = "number_of v" in spec) |
|
594 |
apply auto |
|
595 |
done |
|
596 |
||
597 |
subsection{*Literal arithmetic involving powers*} |
|
598 |
||
599 |
lemma nat_power_eq: "(0::int) <= z ==> nat (z^n) = nat z ^ n" |
|
600 |
apply (induct "n") |
|
601 |
apply (simp_all (no_asm_simp) add: nat_mult_distrib) |
|
602 |
done |
|
603 |
||
604 |
lemma power_nat_number_of: |
|
605 |
"(number_of v :: nat) ^ n = |
|
606 |
(if neg (number_of v :: int) then 0^n else nat ((number_of v :: int) ^ n))" |
|
607 |
by (simp only: simp_thms neg_nat not_neg_eq_ge_0 nat_number_of_def nat_power_eq |
|
608 |
split add: split_if cong: imp_cong) |
|
609 |
||
610 |
||
611 |
lemmas power_nat_number_of_number_of = power_nat_number_of [of _ "number_of w", standard] |
|
612 |
declare power_nat_number_of_number_of [simp] |
|
613 |
||
614 |
||
615 |
||
23294 | 616 |
text{*For arbitrary rings*} |
23164 | 617 |
|
23294 | 618 |
lemma power_number_of_even: |
619 |
fixes z :: "'a::{number_ring,recpower}" |
|
26086
3c243098b64a
New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents:
25965
diff
changeset
|
620 |
shows "z ^ number_of (Int.Bit0 w) = (let w = z ^ (number_of w) in w * w)" |
3c243098b64a
New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents:
25965
diff
changeset
|
621 |
unfolding Let_def nat_number_of_def number_of_Bit0 |
23164 | 622 |
apply (rule_tac x = "number_of w" in spec, clarify) |
623 |
apply (case_tac " (0::int) <= x") |
|
624 |
apply (auto simp add: nat_mult_distrib power_even_eq power2_eq_square) |
|
625 |
done |
|
626 |
||
23294 | 627 |
lemma power_number_of_odd: |
628 |
fixes z :: "'a::{number_ring,recpower}" |
|
26086
3c243098b64a
New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents:
25965
diff
changeset
|
629 |
shows "z ^ number_of (Int.Bit1 w) = (if (0::int) <= number_of w |
23164 | 630 |
then (let w = z ^ (number_of w) in z * w * w) else 1)" |
26086
3c243098b64a
New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents:
25965
diff
changeset
|
631 |
unfolding Let_def nat_number_of_def number_of_Bit1 |
23164 | 632 |
apply (rule_tac x = "number_of w" in spec, auto) |
633 |
apply (simp only: nat_add_distrib nat_mult_distrib) |
|
634 |
apply simp |
|
23294 | 635 |
apply (auto simp add: nat_add_distrib nat_mult_distrib power_even_eq power2_eq_square neg_nat power_Suc) |
23164 | 636 |
done |
637 |
||
23294 | 638 |
lemmas zpower_number_of_even = power_number_of_even [where 'a=int] |
639 |
lemmas zpower_number_of_odd = power_number_of_odd [where 'a=int] |
|
23164 | 640 |
|
23294 | 641 |
lemmas power_number_of_even_number_of [simp] = |
642 |
power_number_of_even [of "number_of v", standard] |
|
23164 | 643 |
|
23294 | 644 |
lemmas power_number_of_odd_number_of [simp] = |
645 |
power_number_of_odd [of "number_of v", standard] |
|
23164 | 646 |
|
647 |
||
648 |
||
649 |
ML |
|
650 |
{* |
|
26342 | 651 |
val numeral_ss = @{simpset} addsimps @{thms numerals}; |
23164 | 652 |
|
653 |
val nat_bin_arith_setup = |
|
30685 | 654 |
Lin_Arith.map_data |
23164 | 655 |
(fn {add_mono_thms, mult_mono_thms, inj_thms, lessD, neqE, simpset} => |
656 |
{add_mono_thms = add_mono_thms, mult_mono_thms = mult_mono_thms, |
|
657 |
inj_thms = inj_thms, |
|
658 |
lessD = lessD, neqE = neqE, |
|
29039 | 659 |
simpset = simpset addsimps @{thms neg_simps} @ |
660 |
[@{thm Suc_nat_number_of}, @{thm int_nat_number_of}]}) |
|
23164 | 661 |
*} |
662 |
||
24075 | 663 |
declaration {* K nat_bin_arith_setup *} |
23164 | 664 |
|
665 |
(* Enable arith to deal with div/mod k where k is a numeral: *) |
|
666 |
declare split_div[of _ _ "number_of k", standard, arith_split] |
|
667 |
declare split_mod[of _ _ "number_of k", standard, arith_split] |
|
668 |
||
669 |
lemma nat_number_of_Pls: "Numeral0 = (0::nat)" |
|
670 |
by (simp add: number_of_Pls nat_number_of_def) |
|
671 |
||
25919
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
25571
diff
changeset
|
672 |
lemma nat_number_of_Min: "number_of Int.Min = (0::nat)" |
23164 | 673 |
apply (simp only: number_of_Min nat_number_of_def nat_zminus_int) |
674 |
done |
|
675 |
||
26086
3c243098b64a
New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents:
25965
diff
changeset
|
676 |
lemma nat_number_of_Bit0: |
3c243098b64a
New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents:
25965
diff
changeset
|
677 |
"number_of (Int.Bit0 w) = (let n::nat = number_of w in n + n)" |
28969 | 678 |
unfolding nat_number_of_def number_of_is_id numeral_simps Let_def |
679 |
by auto |
|
26086
3c243098b64a
New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents:
25965
diff
changeset
|
680 |
|
3c243098b64a
New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents:
25965
diff
changeset
|
681 |
lemma nat_number_of_Bit1: |
3c243098b64a
New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents:
25965
diff
changeset
|
682 |
"number_of (Int.Bit1 w) = |
23164 | 683 |
(if neg (number_of w :: int) then 0 |
684 |
else let n = number_of w in Suc (n + n))" |
|
28969 | 685 |
unfolding nat_number_of_def number_of_is_id numeral_simps neg_def Let_def |
28968 | 686 |
by auto |
23164 | 687 |
|
688 |
lemmas nat_number = |
|
689 |
nat_number_of_Pls nat_number_of_Min |
|
26086
3c243098b64a
New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents:
25965
diff
changeset
|
690 |
nat_number_of_Bit0 nat_number_of_Bit1 |
23164 | 691 |
|
692 |
lemma Let_Suc [simp]: "Let (Suc n) f == f (Suc n)" |
|
693 |
by (simp add: Let_def) |
|
694 |
||
695 |
lemma power_m1_even: "(-1) ^ (2*n) = (1::'a::{number_ring,recpower})" |
|
23294 | 696 |
by (simp add: power_mult power_Suc); |
23164 | 697 |
|
698 |
lemma power_m1_odd: "(-1) ^ Suc(2*n) = (-1::'a::{number_ring,recpower})" |
|
699 |
by (simp add: power_mult power_Suc); |
|
700 |
||
701 |
||
702 |
subsection{*Literal arithmetic and @{term of_nat}*} |
|
703 |
||
704 |
lemma of_nat_double: |
|
705 |
"0 \<le> x ==> of_nat (nat (2 * x)) = of_nat (nat x) + of_nat (nat x)" |
|
706 |
by (simp only: mult_2 nat_add_distrib of_nat_add) |
|
707 |
||
708 |
lemma nat_numeral_m1_eq_0: "-1 = (0::nat)" |
|
709 |
by (simp only: nat_number_of_def) |
|
710 |
||
711 |
lemma of_nat_number_of_lemma: |
|
712 |
"of_nat (number_of v :: nat) = |
|
713 |
(if 0 \<le> (number_of v :: int) |
|
714 |
then (number_of v :: 'a :: number_ring) |
|
715 |
else 0)" |
|
716 |
by (simp add: int_number_of_def nat_number_of_def number_of_eq of_nat_nat); |
|
717 |
||
718 |
lemma of_nat_number_of_eq [simp]: |
|
719 |
"of_nat (number_of v :: nat) = |
|
720 |
(if neg (number_of v :: int) then 0 |
|
721 |
else (number_of v :: 'a :: number_ring))" |
|
722 |
by (simp only: of_nat_number_of_lemma neg_def, simp) |
|
723 |
||
724 |
||
725 |
subsection {*Lemmas for the Combination and Cancellation Simprocs*} |
|
726 |
||
727 |
lemma nat_number_of_add_left: |
|
728 |
"number_of v + (number_of v' + (k::nat)) = |
|
729 |
(if neg (number_of v :: int) then number_of v' + k |
|
730 |
else if neg (number_of v' :: int) then number_of v + k |
|
731 |
else number_of (v + v') + k)" |
|
28968 | 732 |
unfolding nat_number_of_def number_of_is_id neg_def |
733 |
by auto |
|
23164 | 734 |
|
735 |
lemma nat_number_of_mult_left: |
|
736 |
"number_of v * (number_of v' * (k::nat)) = |
|
29012 | 737 |
(if v < Int.Pls then 0 |
23164 | 738 |
else number_of (v * v') * k)" |
739 |
by simp |
|
740 |
||
741 |
||
742 |
subsubsection{*For @{text combine_numerals}*} |
|
743 |
||
744 |
lemma left_add_mult_distrib: "i*u + (j*u + k) = (i+j)*u + (k::nat)" |
|
745 |
by (simp add: add_mult_distrib) |
|
746 |
||
747 |
||
748 |
subsubsection{*For @{text cancel_numerals}*} |
|
749 |
||
750 |
lemma nat_diff_add_eq1: |
|
751 |
"j <= (i::nat) ==> ((i*u + m) - (j*u + n)) = (((i-j)*u + m) - n)" |
|
752 |
by (simp split add: nat_diff_split add: add_mult_distrib) |
|
753 |
||
754 |
lemma nat_diff_add_eq2: |
|
755 |
"i <= (j::nat) ==> ((i*u + m) - (j*u + n)) = (m - ((j-i)*u + n))" |
|
756 |
by (simp split add: nat_diff_split add: add_mult_distrib) |
|
757 |
||
758 |
lemma nat_eq_add_iff1: |
|
759 |
"j <= (i::nat) ==> (i*u + m = j*u + n) = ((i-j)*u + m = n)" |
|
760 |
by (auto split add: nat_diff_split simp add: add_mult_distrib) |
|
761 |
||
762 |
lemma nat_eq_add_iff2: |
|
763 |
"i <= (j::nat) ==> (i*u + m = j*u + n) = (m = (j-i)*u + n)" |
|
764 |
by (auto split add: nat_diff_split simp add: add_mult_distrib) |
|
765 |
||
766 |
lemma nat_less_add_iff1: |
|
767 |
"j <= (i::nat) ==> (i*u + m < j*u + n) = ((i-j)*u + m < n)" |
|
768 |
by (auto split add: nat_diff_split simp add: add_mult_distrib) |
|
769 |
||
770 |
lemma nat_less_add_iff2: |
|
771 |
"i <= (j::nat) ==> (i*u + m < j*u + n) = (m < (j-i)*u + n)" |
|
772 |
by (auto split add: nat_diff_split simp add: add_mult_distrib) |
|
773 |
||
774 |
lemma nat_le_add_iff1: |
|
775 |
"j <= (i::nat) ==> (i*u + m <= j*u + n) = ((i-j)*u + m <= n)" |
|
776 |
by (auto split add: nat_diff_split simp add: add_mult_distrib) |
|
777 |
||
778 |
lemma nat_le_add_iff2: |
|
779 |
"i <= (j::nat) ==> (i*u + m <= j*u + n) = (m <= (j-i)*u + n)" |
|
780 |
by (auto split add: nat_diff_split simp add: add_mult_distrib) |
|
781 |
||
782 |
||
783 |
subsubsection{*For @{text cancel_numeral_factors} *} |
|
784 |
||
785 |
lemma nat_mult_le_cancel1: "(0::nat) < k ==> (k*m <= k*n) = (m<=n)" |
|
786 |
by auto |
|
787 |
||
788 |
lemma nat_mult_less_cancel1: "(0::nat) < k ==> (k*m < k*n) = (m<n)" |
|
789 |
by auto |
|
790 |
||
791 |
lemma nat_mult_eq_cancel1: "(0::nat) < k ==> (k*m = k*n) = (m=n)" |
|
792 |
by auto |
|
793 |
||
794 |
lemma nat_mult_div_cancel1: "(0::nat) < k ==> (k*m) div (k*n) = (m div n)" |
|
795 |
by auto |
|
796 |
||
23969 | 797 |
lemma nat_mult_dvd_cancel_disj[simp]: |
798 |
"(k*m) dvd (k*n) = (k=0 | m dvd (n::nat))" |
|
799 |
by(auto simp: dvd_eq_mod_eq_0 mod_mult_distrib2[symmetric]) |
|
800 |
||
801 |
lemma nat_mult_dvd_cancel1: "0 < k \<Longrightarrow> (k*m) dvd (k*n::nat) = (m dvd n)" |
|
802 |
by(auto) |
|
803 |
||
23164 | 804 |
|
805 |
subsubsection{*For @{text cancel_factor} *} |
|
806 |
||
807 |
lemma nat_mult_le_cancel_disj: "(k*m <= k*n) = ((0::nat) < k --> m<=n)" |
|
808 |
by auto |
|
809 |
||
810 |
lemma nat_mult_less_cancel_disj: "(k*m < k*n) = ((0::nat) < k & m<n)" |
|
811 |
by auto |
|
812 |
||
813 |
lemma nat_mult_eq_cancel_disj: "(k*m = k*n) = (k = (0::nat) | m=n)" |
|
814 |
by auto |
|
815 |
||
23969 | 816 |
lemma nat_mult_div_cancel_disj[simp]: |
23164 | 817 |
"(k*m) div (k*n) = (if k = (0::nat) then 0 else m div n)" |
818 |
by (simp add: nat_mult_div_cancel1) |
|
819 |
||
30652
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
820 |
|
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
821 |
subsection {* Simprocs for the Naturals *} |
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
822 |
|
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
823 |
use "Tools/nat_simprocs.ML" |
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
824 |
declaration {* K nat_simprocs_setup *} |
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
825 |
|
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
826 |
subsubsection{*For simplifying @{term "Suc m - K"} and @{term "K - Suc m"}*} |
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
827 |
|
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
828 |
text{*Where K above is a literal*} |
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
829 |
|
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
830 |
lemma Suc_diff_eq_diff_pred: "Numeral0 < n ==> Suc m - n = m - (n - Numeral1)" |
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
831 |
by (simp add: numeral_0_eq_0 numeral_1_eq_1 split add: nat_diff_split) |
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
832 |
|
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
833 |
text {*Now just instantiating @{text n} to @{text "number_of v"} does |
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
834 |
the right simplification, but with some redundant inequality |
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
835 |
tests.*} |
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
836 |
lemma neg_number_of_pred_iff_0: |
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
837 |
"neg (number_of (Int.pred v)::int) = (number_of v = (0::nat))" |
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
838 |
apply (subgoal_tac "neg (number_of (Int.pred v)) = (number_of v < Suc 0) ") |
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
839 |
apply (simp only: less_Suc_eq_le le_0_eq) |
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
840 |
apply (subst less_number_of_Suc, simp) |
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
841 |
done |
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
842 |
|
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
843 |
text{*No longer required as a simprule because of the @{text inverse_fold} |
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
844 |
simproc*} |
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
845 |
lemma Suc_diff_number_of: |
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
846 |
"Int.Pls < v ==> |
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
847 |
Suc m - (number_of v) = m - (number_of (Int.pred v))" |
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
848 |
apply (subst Suc_diff_eq_diff_pred) |
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
849 |
apply simp |
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
850 |
apply (simp del: nat_numeral_1_eq_1) |
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
851 |
apply (auto simp only: diff_nat_number_of less_0_number_of [symmetric] |
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
852 |
neg_number_of_pred_iff_0) |
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
853 |
done |
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
854 |
|
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
855 |
lemma diff_Suc_eq_diff_pred: "m - Suc n = (m - 1) - n" |
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
856 |
by (simp add: numerals split add: nat_diff_split) |
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
857 |
|
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
858 |
|
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
859 |
subsubsection{*For @{term nat_case} and @{term nat_rec}*} |
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
860 |
|
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
861 |
lemma nat_case_number_of [simp]: |
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
862 |
"nat_case a f (number_of v) = |
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
863 |
(let pv = number_of (Int.pred v) in |
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
864 |
if neg pv then a else f (nat pv))" |
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
865 |
by (simp split add: nat.split add: Let_def neg_number_of_pred_iff_0) |
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
866 |
|
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
867 |
lemma nat_case_add_eq_if [simp]: |
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
868 |
"nat_case a f ((number_of v) + n) = |
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
869 |
(let pv = number_of (Int.pred v) in |
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
870 |
if neg pv then nat_case a f n else f (nat pv + n))" |
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
871 |
apply (subst add_eq_if) |
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
872 |
apply (simp split add: nat.split |
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
873 |
del: nat_numeral_1_eq_1 |
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
874 |
add: nat_numeral_1_eq_1 [symmetric] |
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
875 |
numeral_1_eq_Suc_0 [symmetric] |
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
876 |
neg_number_of_pred_iff_0) |
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
877 |
done |
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
878 |
|
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
879 |
lemma nat_rec_number_of [simp]: |
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
880 |
"nat_rec a f (number_of v) = |
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
881 |
(let pv = number_of (Int.pred v) in |
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
882 |
if neg pv then a else f (nat pv) (nat_rec a f (nat pv)))" |
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
883 |
apply (case_tac " (number_of v) ::nat") |
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
884 |
apply (simp_all (no_asm_simp) add: Let_def neg_number_of_pred_iff_0) |
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
885 |
apply (simp split add: split_if_asm) |
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
886 |
done |
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
887 |
|
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
888 |
lemma nat_rec_add_eq_if [simp]: |
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
889 |
"nat_rec a f (number_of v + n) = |
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
890 |
(let pv = number_of (Int.pred v) in |
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
891 |
if neg pv then nat_rec a f n |
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
892 |
else f (nat pv + n) (nat_rec a f (nat pv + n)))" |
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
893 |
apply (subst add_eq_if) |
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
894 |
apply (simp split add: nat.split |
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
895 |
del: nat_numeral_1_eq_1 |
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
896 |
add: nat_numeral_1_eq_1 [symmetric] |
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
897 |
numeral_1_eq_Suc_0 [symmetric] |
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
898 |
neg_number_of_pred_iff_0) |
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
899 |
done |
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
900 |
|
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
901 |
|
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
902 |
subsubsection{*Various Other Lemmas*} |
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
903 |
|
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
904 |
text {*Evens and Odds, for Mutilated Chess Board*} |
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
905 |
|
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
906 |
text{*Lemmas for specialist use, NOT as default simprules*} |
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
907 |
lemma nat_mult_2: "2 * z = (z+z::nat)" |
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
908 |
proof - |
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
909 |
have "2*z = (1 + 1)*z" by simp |
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
910 |
also have "... = z+z" by (simp add: left_distrib) |
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
911 |
finally show ?thesis . |
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
912 |
qed |
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
913 |
|
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
914 |
lemma nat_mult_2_right: "z * 2 = (z+z::nat)" |
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
915 |
by (subst mult_commute, rule nat_mult_2) |
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
916 |
|
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
917 |
text{*Case analysis on @{term "n<2"}*} |
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
918 |
lemma less_2_cases: "(n::nat) < 2 ==> n = 0 | n = Suc 0" |
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
919 |
by arith |
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
920 |
|
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
921 |
lemma div2_Suc_Suc [simp]: "Suc(Suc m) div 2 = Suc (m div 2)" |
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
922 |
by arith |
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
923 |
|
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
924 |
lemma add_self_div_2 [simp]: "(m + m) div 2 = (m::nat)" |
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
925 |
by (simp add: nat_mult_2 [symmetric]) |
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
926 |
|
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
927 |
lemma mod2_Suc_Suc [simp]: "Suc(Suc(m)) mod 2 = m mod 2" |
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
928 |
apply (subgoal_tac "m mod 2 < 2") |
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
929 |
apply (erule less_2_cases [THEN disjE]) |
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
930 |
apply (simp_all (no_asm_simp) add: Let_def mod_Suc nat_1) |
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
931 |
done |
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
932 |
|
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
933 |
lemma mod2_gr_0 [simp]: "!!m::nat. (0 < m mod 2) = (m mod 2 = 1)" |
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
934 |
apply (subgoal_tac "m mod 2 < 2") |
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
935 |
apply (force simp del: mod_less_divisor, simp) |
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
936 |
done |
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
937 |
|
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
938 |
text{*Removal of Small Numerals: 0, 1 and (in additive positions) 2*} |
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
939 |
|
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
940 |
lemma add_2_eq_Suc [simp]: "2 + n = Suc (Suc n)" |
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
941 |
by simp |
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
942 |
|
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
943 |
lemma add_2_eq_Suc' [simp]: "n + 2 = Suc (Suc n)" |
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
944 |
by simp |
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
945 |
|
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
946 |
text{*Can be used to eliminate long strings of Sucs, but not by default*} |
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
947 |
lemma Suc3_eq_add_3: "Suc (Suc (Suc n)) = 3 + n" |
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
948 |
by simp |
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
949 |
|
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
950 |
|
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
951 |
text{*These lemmas collapse some needless occurrences of Suc: |
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
952 |
at least three Sucs, since two and fewer are rewritten back to Suc again! |
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
953 |
We already have some rules to simplify operands smaller than 3.*} |
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
954 |
|
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
955 |
lemma div_Suc_eq_div_add3 [simp]: "m div (Suc (Suc (Suc n))) = m div (3+n)" |
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
956 |
by (simp add: Suc3_eq_add_3) |
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
957 |
|
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
958 |
lemma mod_Suc_eq_mod_add3 [simp]: "m mod (Suc (Suc (Suc n))) = m mod (3+n)" |
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
959 |
by (simp add: Suc3_eq_add_3) |
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
960 |
|
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
961 |
lemma Suc_div_eq_add3_div: "(Suc (Suc (Suc m))) div n = (3+m) div n" |
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
962 |
by (simp add: Suc3_eq_add_3) |
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
963 |
|
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
964 |
lemma Suc_mod_eq_add3_mod: "(Suc (Suc (Suc m))) mod n = (3+m) mod n" |
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
965 |
by (simp add: Suc3_eq_add_3) |
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
966 |
|
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
967 |
lemmas Suc_div_eq_add3_div_number_of = |
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
968 |
Suc_div_eq_add3_div [of _ "number_of v", standard] |
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
969 |
declare Suc_div_eq_add3_div_number_of [simp] |
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
970 |
|
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
971 |
lemmas Suc_mod_eq_add3_mod_number_of = |
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
972 |
Suc_mod_eq_add3_mod [of _ "number_of v", standard] |
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
973 |
declare Suc_mod_eq_add3_mod_number_of [simp] |
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
974 |
|
23164 | 975 |
end |