| author | wenzelm |
| Mon, 26 Mar 2012 21:03:30 +0200 | |
| changeset 47133 | 89b13238d7f2 |
| parent 47108 | 2a1953f0d20d |
| child 47192 | 0c0501cb6da6 |
| 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 |
|
33296
a3924d1069e5
moved theory Divides after theory Nat_Numeral; tuned some proof texts
haftmann
parents:
32069
diff
changeset
|
9 |
imports Int |
| 23164 | 10 |
begin |
11 |
||
| 31014 | 12 |
subsection {* Numerals for natural numbers *}
|
13 |
||
| 23164 | 14 |
text {*
|
15 |
Arithmetic for naturals is reduced to that for the non-negative integers. |
|
16 |
*} |
|
17 |
||
| 31014 | 18 |
subsection {* Special case: squares and cubes *}
|
19 |
||
20 |
lemma numeral_2_eq_2: "2 = Suc (Suc 0)" |
|
|
47108
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46026
diff
changeset
|
21 |
by (simp add: nat_number(2-4)) |
| 31014 | 22 |
|
23 |
lemma numeral_3_eq_3: "3 = Suc (Suc (Suc 0))" |
|
|
47108
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46026
diff
changeset
|
24 |
by (simp add: nat_number(2-4)) |
| 31014 | 25 |
|
26 |
context power |
|
| 30960 | 27 |
begin |
28 |
||
| 23164 | 29 |
abbreviation (xsymbols) |
| 30960 | 30 |
power2 :: "'a \<Rightarrow> 'a" ("(_\<twosuperior>)" [1000] 999) where
|
31 |
"x\<twosuperior> \<equiv> x ^ 2" |
|
| 23164 | 32 |
|
33 |
notation (latex output) |
|
|
29401
94fd5dd918f5
rename abbreviation square -> power2, to match theorem names
huffman
parents:
29045
diff
changeset
|
34 |
power2 ("(_\<twosuperior>)" [1000] 999)
|
| 23164 | 35 |
|
36 |
notation (HTML output) |
|
|
29401
94fd5dd918f5
rename abbreviation square -> power2, to match theorem names
huffman
parents:
29045
diff
changeset
|
37 |
power2 ("(_\<twosuperior>)" [1000] 999)
|
| 23164 | 38 |
|
| 30960 | 39 |
end |
40 |
||
| 31014 | 41 |
context monoid_mult |
42 |
begin |
|
43 |
||
44 |
lemma power2_eq_square: "a\<twosuperior> = a * a" |
|
45 |
by (simp add: numeral_2_eq_2) |
|
46 |
||
47 |
lemma power3_eq_cube: "a ^ 3 = a * a * a" |
|
48 |
by (simp add: numeral_3_eq_3 mult_assoc) |
|
49 |
||
50 |
lemma power_even_eq: |
|
51 |
"a ^ (2*n) = (a ^ n) ^ 2" |
|
|
35047
1b2bae06c796
hide fact Nat.add_0_right; make add_0_right from Groups priority
haftmann
parents:
35043
diff
changeset
|
52 |
by (subst mult_commute) (simp add: power_mult) |
| 31014 | 53 |
|
54 |
lemma power_odd_eq: |
|
55 |
"a ^ Suc (2*n) = a * (a ^ n) ^ 2" |
|
56 |
by (simp add: power_even_eq) |
|
57 |
||
58 |
end |
|
59 |
||
60 |
context semiring_1 |
|
61 |
begin |
|
62 |
||
63 |
lemma zero_power2 [simp]: "0\<twosuperior> = 0" |
|
64 |
by (simp add: power2_eq_square) |
|
65 |
||
66 |
lemma one_power2 [simp]: "1\<twosuperior> = 1" |
|
67 |
by (simp add: power2_eq_square) |
|
68 |
||
69 |
end |
|
70 |
||
|
36823
001d1aad99de
add lemma power2_eq_1_iff; generalize some other lemmas
huffman
parents:
36719
diff
changeset
|
71 |
context ring_1 |
| 31014 | 72 |
begin |
73 |
||
74 |
lemma power2_minus [simp]: |
|
75 |
"(- a)\<twosuperior> = a\<twosuperior>" |
|
76 |
by (simp add: power2_eq_square) |
|
77 |
||
78 |
lemma power_minus1_even [simp]: |
|
|
47108
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46026
diff
changeset
|
79 |
"-1 ^ (2*n) = 1" |
| 31014 | 80 |
proof (induct n) |
81 |
case 0 show ?case by simp |
|
82 |
next |
|
|
47108
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46026
diff
changeset
|
83 |
case (Suc n) then show ?case by (simp add: power_add power2_eq_square) |
| 31014 | 84 |
qed |
85 |
||
86 |
lemma power_minus1_odd: |
|
|
47108
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46026
diff
changeset
|
87 |
"-1 ^ Suc (2*n) = -1" |
| 31014 | 88 |
by simp |
89 |
||
90 |
lemma power_minus_even [simp]: |
|
91 |
"(-a) ^ (2*n) = a ^ (2*n)" |
|
|
47108
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46026
diff
changeset
|
92 |
by (simp add: power_minus [of a]) |
| 31014 | 93 |
|
94 |
end |
|
95 |
||
|
36823
001d1aad99de
add lemma power2_eq_1_iff; generalize some other lemmas
huffman
parents:
36719
diff
changeset
|
96 |
context ring_1_no_zero_divisors |
|
001d1aad99de
add lemma power2_eq_1_iff; generalize some other lemmas
huffman
parents:
36719
diff
changeset
|
97 |
begin |
|
001d1aad99de
add lemma power2_eq_1_iff; generalize some other lemmas
huffman
parents:
36719
diff
changeset
|
98 |
|
|
001d1aad99de
add lemma power2_eq_1_iff; generalize some other lemmas
huffman
parents:
36719
diff
changeset
|
99 |
lemma zero_eq_power2 [simp]: |
|
001d1aad99de
add lemma power2_eq_1_iff; generalize some other lemmas
huffman
parents:
36719
diff
changeset
|
100 |
"a\<twosuperior> = 0 \<longleftrightarrow> a = 0" |
|
001d1aad99de
add lemma power2_eq_1_iff; generalize some other lemmas
huffman
parents:
36719
diff
changeset
|
101 |
unfolding power2_eq_square by simp |
|
001d1aad99de
add lemma power2_eq_1_iff; generalize some other lemmas
huffman
parents:
36719
diff
changeset
|
102 |
|
| 36964 | 103 |
lemma power2_eq_1_iff: |
|
36823
001d1aad99de
add lemma power2_eq_1_iff; generalize some other lemmas
huffman
parents:
36719
diff
changeset
|
104 |
"a\<twosuperior> = 1 \<longleftrightarrow> a = 1 \<or> a = - 1" |
| 36964 | 105 |
unfolding power2_eq_square by (rule square_eq_1_iff) |
|
36823
001d1aad99de
add lemma power2_eq_1_iff; generalize some other lemmas
huffman
parents:
36719
diff
changeset
|
106 |
|
|
001d1aad99de
add lemma power2_eq_1_iff; generalize some other lemmas
huffman
parents:
36719
diff
changeset
|
107 |
end |
|
001d1aad99de
add lemma power2_eq_1_iff; generalize some other lemmas
huffman
parents:
36719
diff
changeset
|
108 |
|
| 44345 | 109 |
context idom |
110 |
begin |
|
111 |
||
112 |
lemma power2_eq_iff: "x\<twosuperior> = y\<twosuperior> \<longleftrightarrow> x = y \<or> x = - y" |
|
113 |
unfolding power2_eq_square by (rule square_eq_iff) |
|
114 |
||
115 |
end |
|
116 |
||
|
35631
0b8a5fd339ab
generalize some lemmas from class linordered_ring_strict to linordered_ring
huffman
parents:
35216
diff
changeset
|
117 |
context linordered_ring |
| 31014 | 118 |
begin |
119 |
||
120 |
lemma sum_squares_ge_zero: |
|
121 |
"0 \<le> x * x + y * y" |
|
122 |
by (intro add_nonneg_nonneg zero_le_square) |
|
123 |
||
124 |
lemma not_sum_squares_lt_zero: |
|
125 |
"\<not> x * x + y * y < 0" |
|
126 |
by (simp add: not_less sum_squares_ge_zero) |
|
127 |
||
|
35631
0b8a5fd339ab
generalize some lemmas from class linordered_ring_strict to linordered_ring
huffman
parents:
35216
diff
changeset
|
128 |
end |
|
0b8a5fd339ab
generalize some lemmas from class linordered_ring_strict to linordered_ring
huffman
parents:
35216
diff
changeset
|
129 |
|
|
0b8a5fd339ab
generalize some lemmas from class linordered_ring_strict to linordered_ring
huffman
parents:
35216
diff
changeset
|
130 |
context linordered_ring_strict |
|
0b8a5fd339ab
generalize some lemmas from class linordered_ring_strict to linordered_ring
huffman
parents:
35216
diff
changeset
|
131 |
begin |
|
0b8a5fd339ab
generalize some lemmas from class linordered_ring_strict to linordered_ring
huffman
parents:
35216
diff
changeset
|
132 |
|
| 31014 | 133 |
lemma sum_squares_eq_zero_iff: |
134 |
"x * x + y * y = 0 \<longleftrightarrow> x = 0 \<and> y = 0" |
|
| 31034 | 135 |
by (simp add: add_nonneg_eq_0_iff) |
| 31014 | 136 |
|
137 |
lemma sum_squares_le_zero_iff: |
|
138 |
"x * x + y * y \<le> 0 \<longleftrightarrow> x = 0 \<and> y = 0" |
|
139 |
by (simp add: le_less not_sum_squares_lt_zero sum_squares_eq_zero_iff) |
|
140 |
||
141 |
lemma sum_squares_gt_zero_iff: |
|
142 |
"0 < x * x + y * y \<longleftrightarrow> x \<noteq> 0 \<or> y \<noteq> 0" |
|
|
35631
0b8a5fd339ab
generalize some lemmas from class linordered_ring_strict to linordered_ring
huffman
parents:
35216
diff
changeset
|
143 |
by (simp add: not_le [symmetric] sum_squares_le_zero_iff) |
| 31014 | 144 |
|
145 |
end |
|
146 |
||
|
35028
108662d50512
more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
haftmann
parents:
33342
diff
changeset
|
147 |
context linordered_semidom |
| 31014 | 148 |
begin |
149 |
||
150 |
lemma power2_le_imp_le: |
|
151 |
"x\<twosuperior> \<le> y\<twosuperior> \<Longrightarrow> 0 \<le> y \<Longrightarrow> x \<le> y" |
|
152 |
unfolding numeral_2_eq_2 by (rule power_le_imp_le_base) |
|
153 |
||
154 |
lemma power2_less_imp_less: |
|
155 |
"x\<twosuperior> < y\<twosuperior> \<Longrightarrow> 0 \<le> y \<Longrightarrow> x < y" |
|
156 |
by (rule power_less_imp_less_base) |
|
157 |
||
158 |
lemma power2_eq_imp_eq: |
|
159 |
"x\<twosuperior> = y\<twosuperior> \<Longrightarrow> 0 \<le> x \<Longrightarrow> 0 \<le> y \<Longrightarrow> x = y" |
|
160 |
unfolding numeral_2_eq_2 by (erule (2) power_eq_imp_eq_base) simp |
|
161 |
||
162 |
end |
|
163 |
||
|
35028
108662d50512
more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
haftmann
parents:
33342
diff
changeset
|
164 |
context linordered_idom |
| 31014 | 165 |
begin |
166 |
||
167 |
lemma zero_le_power2 [simp]: |
|
168 |
"0 \<le> a\<twosuperior>" |
|
169 |
by (simp add: power2_eq_square) |
|
170 |
||
171 |
lemma zero_less_power2 [simp]: |
|
172 |
"0 < a\<twosuperior> \<longleftrightarrow> a \<noteq> 0" |
|
173 |
by (force simp add: power2_eq_square zero_less_mult_iff linorder_neq_iff) |
|
174 |
||
175 |
lemma power2_less_0 [simp]: |
|
176 |
"\<not> a\<twosuperior> < 0" |
|
177 |
by (force simp add: power2_eq_square mult_less_0_iff) |
|
178 |
||
179 |
lemma abs_power2 [simp]: |
|
180 |
"abs (a\<twosuperior>) = a\<twosuperior>" |
|
181 |
by (simp add: power2_eq_square abs_mult abs_mult_self) |
|
182 |
||
183 |
lemma power2_abs [simp]: |
|
184 |
"(abs a)\<twosuperior> = a\<twosuperior>" |
|
185 |
by (simp add: power2_eq_square abs_mult_self) |
|
186 |
||
187 |
lemma odd_power_less_zero: |
|
188 |
"a < 0 \<Longrightarrow> a ^ Suc (2*n) < 0" |
|
189 |
proof (induct n) |
|
190 |
case 0 |
|
191 |
then show ?case by simp |
|
192 |
next |
|
193 |
case (Suc n) |
|
194 |
have "a ^ Suc (2 * Suc n) = (a*a) * a ^ Suc(2*n)" |
|
195 |
by (simp add: mult_ac power_add power2_eq_square) |
|
196 |
thus ?case |
|
197 |
by (simp del: power_Suc add: Suc mult_less_0_iff mult_neg_neg) |
|
198 |
qed |
|
199 |
||
200 |
lemma odd_0_le_power_imp_0_le: |
|
201 |
"0 \<le> a ^ Suc (2*n) \<Longrightarrow> 0 \<le> a" |
|
202 |
using odd_power_less_zero [of a n] |
|
203 |
by (force simp add: linorder_not_less [symmetric]) |
|
204 |
||
205 |
lemma zero_le_even_power'[simp]: |
|
206 |
"0 \<le> a ^ (2*n)" |
|
207 |
proof (induct n) |
|
208 |
case 0 |
|
| 35216 | 209 |
show ?case by simp |
| 31014 | 210 |
next |
211 |
case (Suc n) |
|
212 |
have "a ^ (2 * Suc n) = (a*a) * a ^ (2*n)" |
|
213 |
by (simp add: mult_ac power_add power2_eq_square) |
|
214 |
thus ?case |
|
215 |
by (simp add: Suc zero_le_mult_iff) |
|
216 |
qed |
|
217 |
||
218 |
lemma sum_power2_ge_zero: |
|
219 |
"0 \<le> x\<twosuperior> + y\<twosuperior>" |
|
220 |
unfolding power2_eq_square by (rule sum_squares_ge_zero) |
|
221 |
||
222 |
lemma not_sum_power2_lt_zero: |
|
223 |
"\<not> x\<twosuperior> + y\<twosuperior> < 0" |
|
224 |
unfolding power2_eq_square by (rule not_sum_squares_lt_zero) |
|
225 |
||
226 |
lemma sum_power2_eq_zero_iff: |
|
227 |
"x\<twosuperior> + y\<twosuperior> = 0 \<longleftrightarrow> x = 0 \<and> y = 0" |
|
228 |
unfolding power2_eq_square by (rule sum_squares_eq_zero_iff) |
|
229 |
||
230 |
lemma sum_power2_le_zero_iff: |
|
231 |
"x\<twosuperior> + y\<twosuperior> \<le> 0 \<longleftrightarrow> x = 0 \<and> y = 0" |
|
232 |
unfolding power2_eq_square by (rule sum_squares_le_zero_iff) |
|
233 |
||
234 |
lemma sum_power2_gt_zero_iff: |
|
235 |
"0 < x\<twosuperior> + y\<twosuperior> \<longleftrightarrow> x \<noteq> 0 \<or> y \<noteq> 0" |
|
236 |
unfolding power2_eq_square by (rule sum_squares_gt_zero_iff) |
|
237 |
||
238 |
end |
|
239 |
||
240 |
lemma power2_sum: |
|
|
47108
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46026
diff
changeset
|
241 |
fixes x y :: "'a::comm_semiring_1" |
| 31014 | 242 |
shows "(x + y)\<twosuperior> = x\<twosuperior> + y\<twosuperior> + 2 * x * y" |
|
47108
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46026
diff
changeset
|
243 |
by (simp add: algebra_simps power2_eq_square mult_2_right) |
| 31014 | 244 |
|
245 |
lemma power2_diff: |
|
|
47108
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46026
diff
changeset
|
246 |
fixes x y :: "'a::comm_ring_1" |
| 31014 | 247 |
shows "(x - y)\<twosuperior> = x\<twosuperior> + y\<twosuperior> - 2 * x * y" |
|
33296
a3924d1069e5
moved theory Divides after theory Nat_Numeral; tuned some proof texts
haftmann
parents:
32069
diff
changeset
|
248 |
by (simp add: ring_distribs power2_eq_square mult_2) (rule mult_commute) |
| 31014 | 249 |
|
| 23164 | 250 |
|
251 |
subsection{*Function @{term nat}: Coercion from Type @{typ int} to @{typ nat}*}
|
|
252 |
||
| 35216 | 253 |
declare nat_1 [simp] |
| 23164 | 254 |
|
|
47108
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46026
diff
changeset
|
255 |
lemma nat_neg_numeral [simp]: "nat (neg_numeral w) = 0" |
| 36719 | 256 |
by simp |
257 |
||
|
46026
83caa4f4bd56
semiring_numeral_0_eq_0, semiring_numeral_1_eq_1 now [simp], superseeding corresponding simp rules on type nat
haftmann
parents:
45607
diff
changeset
|
258 |
lemma numeral_1_eq_Suc_0: "Numeral1 = Suc 0" |
|
47108
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46026
diff
changeset
|
259 |
by simp |
| 23164 | 260 |
|
261 |
||
262 |
subsection{*Function @{term int}: Coercion from Type @{typ nat} to @{typ int}*}
|
|
263 |
||
|
47108
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46026
diff
changeset
|
264 |
lemma int_numeral: "int (numeral v) = numeral v" |
|
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46026
diff
changeset
|
265 |
by (rule of_nat_numeral) (* already simp *) |
|
23307
2fe3345035c7
modify proofs to avoid referring to int::nat=>int
huffman
parents:
23294
diff
changeset
|
266 |
|
|
43531
cc46a678faaf
added number_semiring class, plus a few new lemmas;
huffman
parents:
43526
diff
changeset
|
267 |
lemma nonneg_int_cases: |
|
cc46a678faaf
added number_semiring class, plus a few new lemmas;
huffman
parents:
43526
diff
changeset
|
268 |
fixes k :: int assumes "0 \<le> k" obtains n where "k = of_nat n" |
|
cc46a678faaf
added number_semiring class, plus a few new lemmas;
huffman
parents:
43526
diff
changeset
|
269 |
using assms by (cases k, simp, simp) |
| 23164 | 270 |
|
271 |
subsubsection{*Successor *}
|
|
272 |
||
273 |
lemma Suc_nat_eq_nat_zadd1: "(0::int) <= z ==> Suc (nat z) = nat (1 + z)" |
|
274 |
apply (rule sym) |
|
| 44766 | 275 |
apply (simp add: nat_eq_iff) |
| 23164 | 276 |
done |
277 |
||
278 |
lemma Suc_nat_number_of_add: |
|
|
47108
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46026
diff
changeset
|
279 |
"Suc (numeral v + n) = numeral (v + Num.One) + n" |
|
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46026
diff
changeset
|
280 |
by simp |
| 30081 | 281 |
|
|
47108
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46026
diff
changeset
|
282 |
lemma Suc_numeral [simp]: |
|
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46026
diff
changeset
|
283 |
"Suc (numeral v) = numeral (v + Num.One)" |
|
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46026
diff
changeset
|
284 |
by simp |
| 30081 | 285 |
|
| 23164 | 286 |
|
287 |
subsubsection{*Subtraction *}
|
|
288 |
||
289 |
lemma diff_nat_eq_if: |
|
290 |
"nat z - nat z' = |
|
|
47108
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46026
diff
changeset
|
291 |
(if z' < 0 then nat z |
| 23164 | 292 |
else let d = z-z' in |
|
47108
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46026
diff
changeset
|
293 |
if d < 0 then 0 else nat d)" |
|
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46026
diff
changeset
|
294 |
by (simp add: Let_def nat_diff_distrib [symmetric]) |
| 23164 | 295 |
|
|
47108
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46026
diff
changeset
|
296 |
(* Int.nat_diff_distrib has too-strong premises *) |
|
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46026
diff
changeset
|
297 |
lemma nat_diff_distrib': "\<lbrakk>0 \<le> x; 0 \<le> y\<rbrakk> \<Longrightarrow> nat (x - y) = nat x - nat y" |
|
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46026
diff
changeset
|
298 |
apply (rule int_int_eq [THEN iffD1], clarsimp) |
|
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46026
diff
changeset
|
299 |
apply (subst zdiff_int [symmetric]) |
|
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46026
diff
changeset
|
300 |
apply (rule nat_mono, simp_all) |
|
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46026
diff
changeset
|
301 |
done |
| 23164 | 302 |
|
|
47108
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46026
diff
changeset
|
303 |
lemma diff_nat_numeral [simp]: |
|
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46026
diff
changeset
|
304 |
"(numeral v :: nat) - numeral v' = nat (numeral v - numeral v')" |
|
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46026
diff
changeset
|
305 |
by (simp only: nat_diff_distrib' zero_le_numeral nat_numeral) |
| 23164 | 306 |
|
|
47108
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46026
diff
changeset
|
307 |
lemma nat_numeral_diff_1 [simp]: |
|
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46026
diff
changeset
|
308 |
"numeral v - (1::nat) = nat (numeral v - 1)" |
|
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46026
diff
changeset
|
309 |
using diff_nat_numeral [of v Num.One] by simp |
|
43531
cc46a678faaf
added number_semiring class, plus a few new lemmas;
huffman
parents:
43526
diff
changeset
|
310 |
|
| 23164 | 311 |
|
312 |
subsection{*Comparisons*}
|
|
313 |
||
|
47108
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46026
diff
changeset
|
314 |
(*Maps #n to n for n = 1, 2*) |
|
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46026
diff
changeset
|
315 |
lemmas numerals = numeral_1_eq_1 [where 'a=nat] numeral_2_eq_2 |
| 23164 | 316 |
|
317 |
||
318 |
subsection{*Powers with Numeric Exponents*}
|
|
319 |
||
320 |
text{*Squares of literal numerals will be evaluated.*}
|
|
|
47108
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46026
diff
changeset
|
321 |
(* FIXME: replace with more general rules for powers of numerals *) |
|
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46026
diff
changeset
|
322 |
lemmas power2_eq_square_numeral [simp] = |
|
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46026
diff
changeset
|
323 |
power2_eq_square [of "numeral w"] for w |
| 23164 | 324 |
|
325 |
||
326 |
text{*Simprules for comparisons where common factors can be cancelled.*}
|
|
327 |
lemmas zero_compare_simps = |
|
328 |
add_strict_increasing add_strict_increasing2 add_increasing |
|
329 |
zero_le_mult_iff zero_le_divide_iff |
|
330 |
zero_less_mult_iff zero_less_divide_iff |
|
331 |
mult_le_0_iff divide_le_0_iff |
|
332 |
mult_less_0_iff divide_less_0_iff |
|
333 |
zero_le_power2 power2_less_0 |
|
334 |
||
335 |
subsubsection{*Nat *}
|
|
336 |
||
337 |
lemma Suc_pred': "0 < n ==> n = Suc(n - 1)" |
|
| 35216 | 338 |
by simp |
| 23164 | 339 |
|
340 |
(*Expresses a natural number constant as the Suc of another one. |
|
|
47108
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46026
diff
changeset
|
341 |
NOT suitable for rewriting because n recurs on the right-hand side.*) |
|
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46026
diff
changeset
|
342 |
lemmas expand_Suc = Suc_pred' [of "numeral v", OF zero_less_numeral] for v |
| 23164 | 343 |
|
344 |
subsubsection{*Arith *}
|
|
345 |
||
| 31790 | 346 |
lemma Suc_eq_plus1: "Suc n = n + 1" |
| 35216 | 347 |
unfolding One_nat_def by simp |
| 23164 | 348 |
|
| 31790 | 349 |
lemma Suc_eq_plus1_left: "Suc n = 1 + n" |
| 35216 | 350 |
unfolding One_nat_def by simp |
| 23164 | 351 |
|
|
47108
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46026
diff
changeset
|
352 |
(* These two can be useful when m = numeral... *) |
| 23164 | 353 |
|
354 |
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
|
355 |
unfolding One_nat_def by (cases m) simp_all |
| 23164 | 356 |
|
357 |
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
|
358 |
unfolding One_nat_def by (cases m) simp_all |
| 23164 | 359 |
|
360 |
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
|
361 |
unfolding One_nat_def by (cases m) simp_all |
| 23164 | 362 |
|
363 |
||
364 |
subsection{*Comparisons involving @{term Suc} *}
|
|
365 |
||
|
47108
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46026
diff
changeset
|
366 |
lemma eq_numeral_Suc [simp]: "numeral v = Suc n \<longleftrightarrow> nat (numeral v - 1) = n" |
|
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46026
diff
changeset
|
367 |
by (subst expand_Suc, simp only: nat.inject nat_numeral_diff_1) |
| 23164 | 368 |
|
|
47108
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46026
diff
changeset
|
369 |
lemma Suc_eq_numeral [simp]: "Suc n = numeral v \<longleftrightarrow> n = nat (numeral v - 1)" |
|
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46026
diff
changeset
|
370 |
by (subst expand_Suc, simp only: nat.inject nat_numeral_diff_1) |
| 23164 | 371 |
|
|
47108
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46026
diff
changeset
|
372 |
lemma less_numeral_Suc [simp]: "numeral v < Suc n \<longleftrightarrow> nat (numeral v - 1) < n" |
|
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46026
diff
changeset
|
373 |
by (subst expand_Suc, simp only: Suc_less_eq nat_numeral_diff_1) |
| 23164 | 374 |
|
|
47108
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46026
diff
changeset
|
375 |
lemma less_Suc_numeral [simp]: "Suc n < numeral v \<longleftrightarrow> n < nat (numeral v - 1)" |
|
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46026
diff
changeset
|
376 |
by (subst expand_Suc, simp only: Suc_less_eq nat_numeral_diff_1) |
| 23164 | 377 |
|
|
47108
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46026
diff
changeset
|
378 |
lemma le_numeral_Suc [simp]: "numeral v \<le> Suc n \<longleftrightarrow> nat (numeral v - 1) \<le> n" |
|
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46026
diff
changeset
|
379 |
by (subst expand_Suc, simp only: Suc_le_mono nat_numeral_diff_1) |
| 23164 | 380 |
|
|
47108
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46026
diff
changeset
|
381 |
lemma le_Suc_numeral [simp]: "Suc n \<le> numeral v \<longleftrightarrow> n \<le> nat (numeral v - 1)" |
|
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46026
diff
changeset
|
382 |
by (subst expand_Suc, simp only: Suc_le_mono nat_numeral_diff_1) |
| 23164 | 383 |
|
384 |
||
385 |
subsection{*Max and Min Combined with @{term Suc} *}
|
|
386 |
||
|
47108
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46026
diff
changeset
|
387 |
lemma max_Suc_numeral [simp]: |
|
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46026
diff
changeset
|
388 |
"max (Suc n) (numeral v) = Suc (max n (nat (numeral v - 1)))" |
|
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46026
diff
changeset
|
389 |
by (subst expand_Suc, simp only: max_Suc_Suc nat_numeral_diff_1) |
|
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46026
diff
changeset
|
390 |
|
|
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46026
diff
changeset
|
391 |
lemma max_numeral_Suc [simp]: |
|
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46026
diff
changeset
|
392 |
"max (numeral v) (Suc n) = Suc (max (nat (numeral v - 1)) n)" |
|
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46026
diff
changeset
|
393 |
by (subst expand_Suc, simp only: max_Suc_Suc nat_numeral_diff_1) |
|
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46026
diff
changeset
|
394 |
|
|
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46026
diff
changeset
|
395 |
lemma min_Suc_numeral [simp]: |
|
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46026
diff
changeset
|
396 |
"min (Suc n) (numeral v) = Suc (min n (nat (numeral v - 1)))" |
|
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46026
diff
changeset
|
397 |
by (subst expand_Suc, simp only: min_Suc_Suc nat_numeral_diff_1) |
|
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46026
diff
changeset
|
398 |
|
|
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46026
diff
changeset
|
399 |
lemma min_numeral_Suc [simp]: |
|
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46026
diff
changeset
|
400 |
"min (numeral v) (Suc n) = Suc (min (nat (numeral v - 1)) n)" |
|
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46026
diff
changeset
|
401 |
by (subst expand_Suc, simp only: min_Suc_Suc nat_numeral_diff_1) |
| 23164 | 402 |
|
403 |
subsection{*Literal arithmetic involving powers*}
|
|
404 |
||
|
47108
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46026
diff
changeset
|
405 |
(* TODO: replace with more generic rule for powers of numerals *) |
|
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46026
diff
changeset
|
406 |
lemma power_nat_numeral: |
|
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46026
diff
changeset
|
407 |
"(numeral v :: nat) ^ n = nat ((numeral v :: int) ^ n)" |
|
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46026
diff
changeset
|
408 |
by (simp only: nat_power_eq zero_le_numeral nat_numeral) |
| 23164 | 409 |
|
|
47108
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46026
diff
changeset
|
410 |
lemmas power_nat_numeral_numeral = power_nat_numeral [of _ "numeral w"] for w |
|
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46026
diff
changeset
|
411 |
declare power_nat_numeral_numeral [simp] |
| 23164 | 412 |
|
413 |
||
| 23294 | 414 |
text{*For arbitrary rings*}
|
| 23164 | 415 |
|
|
47108
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46026
diff
changeset
|
416 |
lemma power_numeral_even: |
|
43526
2b92a6943915
generalize lemmas power_number_of_even and power_number_of_odd
huffman
parents:
40690
diff
changeset
|
417 |
fixes z :: "'a::monoid_mult" |
|
47108
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46026
diff
changeset
|
418 |
shows "z ^ numeral (Num.Bit0 w) = (let w = z ^ (numeral w) in w * w)" |
|
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46026
diff
changeset
|
419 |
unfolding numeral_Bit0 power_add Let_def .. |
| 23164 | 420 |
|
|
47108
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46026
diff
changeset
|
421 |
lemma power_numeral_odd: |
|
43526
2b92a6943915
generalize lemmas power_number_of_even and power_number_of_odd
huffman
parents:
40690
diff
changeset
|
422 |
fixes z :: "'a::monoid_mult" |
|
47108
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46026
diff
changeset
|
423 |
shows "z ^ numeral (Num.Bit1 w) = (let w = z ^ (numeral w) in z * w * w)" |
|
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46026
diff
changeset
|
424 |
unfolding numeral_Bit1 One_nat_def add_Suc_right add_0_right |
|
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46026
diff
changeset
|
425 |
unfolding power_Suc power_add Let_def mult_assoc .. |
| 23164 | 426 |
|
|
47108
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46026
diff
changeset
|
427 |
lemmas zpower_numeral_even = power_numeral_even [where 'a=int] |
|
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46026
diff
changeset
|
428 |
lemmas zpower_numeral_odd = power_numeral_odd [where 'a=int] |
| 23164 | 429 |
|
|
47108
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46026
diff
changeset
|
430 |
lemmas power_numeral_even_numeral [simp] = |
|
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46026
diff
changeset
|
431 |
power_numeral_even [of "numeral v"] for v |
| 23164 | 432 |
|
|
47108
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46026
diff
changeset
|
433 |
lemmas power_numeral_odd_numeral [simp] = |
|
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46026
diff
changeset
|
434 |
power_numeral_odd [of "numeral v"] for v |
| 23164 | 435 |
|
|
47108
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46026
diff
changeset
|
436 |
lemma nat_numeral_Bit0: |
|
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46026
diff
changeset
|
437 |
"numeral (Num.Bit0 w) = (let n::nat = numeral w in n + n)" |
|
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46026
diff
changeset
|
438 |
unfolding numeral_Bit0 Let_def .. |
|
26086
3c243098b64a
New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents:
25965
diff
changeset
|
439 |
|
|
47108
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46026
diff
changeset
|
440 |
lemma nat_numeral_Bit1: |
|
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46026
diff
changeset
|
441 |
"numeral (Num.Bit1 w) = (let n = numeral w in Suc (n + n))" |
|
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46026
diff
changeset
|
442 |
unfolding numeral_Bit1 Let_def by simp |
| 23164 | 443 |
|
| 40077 | 444 |
lemmas eval_nat_numeral = |
|
47108
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46026
diff
changeset
|
445 |
nat_numeral_Bit0 nat_numeral_Bit1 |
| 35216 | 446 |
|
|
36699
816da1023508
moved nat_arith ot Nat_Numeral: clarified normalizer setup
haftmann
parents:
35815
diff
changeset
|
447 |
lemmas nat_arith = |
|
47108
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46026
diff
changeset
|
448 |
diff_nat_numeral |
|
36699
816da1023508
moved nat_arith ot Nat_Numeral: clarified normalizer setup
haftmann
parents:
35815
diff
changeset
|
449 |
|
| 36716 | 450 |
lemmas semiring_norm = |
|
47108
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46026
diff
changeset
|
451 |
Let_def arith_simps nat_arith rel_simps |
|
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46026
diff
changeset
|
452 |
if_False if_True |
|
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46026
diff
changeset
|
453 |
add_0 add_Suc add_numeral_left |
|
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46026
diff
changeset
|
454 |
add_neg_numeral_left mult_numeral_left |
| 36716 | 455 |
numeral_1_eq_1 [symmetric] Suc_eq_plus1 |
|
47108
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46026
diff
changeset
|
456 |
eq_numeral_iff_iszero not_iszero_Numeral1 |
| 36716 | 457 |
|
| 23164 | 458 |
lemma Let_Suc [simp]: "Let (Suc n) f == f (Suc n)" |
|
33296
a3924d1069e5
moved theory Divides after theory Nat_Numeral; tuned some proof texts
haftmann
parents:
32069
diff
changeset
|
459 |
by (fact Let_def) |
| 23164 | 460 |
|
|
47108
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46026
diff
changeset
|
461 |
lemma power_m1_even: "(-1) ^ (2*n) = (1::'a::ring_1)" |
|
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46026
diff
changeset
|
462 |
by (fact power_minus1_even) (* FIXME: duplicate *) |
| 23164 | 463 |
|
|
47108
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46026
diff
changeset
|
464 |
lemma power_m1_odd: "(-1) ^ Suc(2*n) = (-1::'a::ring_1)" |
|
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46026
diff
changeset
|
465 |
by (fact power_minus1_odd) (* FIXME: duplicate *) |
|
33296
a3924d1069e5
moved theory Divides after theory Nat_Numeral; tuned some proof texts
haftmann
parents:
32069
diff
changeset
|
466 |
|
| 23164 | 467 |
|
468 |
subsection{*Literal arithmetic and @{term of_nat}*}
|
|
469 |
||
470 |
lemma of_nat_double: |
|
471 |
"0 \<le> x ==> of_nat (nat (2 * x)) = of_nat (nat x) + of_nat (nat x)" |
|
472 |
by (simp only: mult_2 nat_add_distrib of_nat_add) |
|
473 |
||
474 |
||
|
30652
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
475 |
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
|
476 |
|
|
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
477 |
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
|
478 |
|
|
47108
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46026
diff
changeset
|
479 |
lemma Suc_diff_eq_diff_pred: "0 < n ==> Suc m - n = m - (n - Numeral1)" |
| 35216 | 480 |
by (simp split: nat_diff_split) |
|
30652
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
481 |
|
|
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
482 |
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
|
483 |
simproc*} |
|
47108
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46026
diff
changeset
|
484 |
lemma Suc_diff_numeral: "Suc m - (numeral v) = m - (numeral v - 1)" |
|
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46026
diff
changeset
|
485 |
by (subst expand_Suc, simp only: diff_Suc_Suc) |
|
30652
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
486 |
|
|
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
487 |
lemma diff_Suc_eq_diff_pred: "m - Suc n = (m - 1) - n" |
| 35216 | 488 |
by (simp split: nat_diff_split) |
|
30652
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
489 |
|
|
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
490 |
|
|
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
491 |
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
|
492 |
|
|
47108
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46026
diff
changeset
|
493 |
lemma nat_case_numeral [simp]: |
|
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46026
diff
changeset
|
494 |
"nat_case a f (numeral v) = (let pv = nat (numeral v - 1) in f pv)" |
|
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46026
diff
changeset
|
495 |
by (subst expand_Suc, simp only: nat.cases nat_numeral_diff_1 Let_def) |
|
30652
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
496 |
|
|
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
497 |
lemma nat_case_add_eq_if [simp]: |
|
47108
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46026
diff
changeset
|
498 |
"nat_case a f ((numeral v) + n) = (let pv = nat (numeral v - 1) in f (pv + n))" |
|
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46026
diff
changeset
|
499 |
by (subst expand_Suc, simp only: nat.cases nat_numeral_diff_1 Let_def add_Suc) |
|
30652
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
500 |
|
|
47108
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46026
diff
changeset
|
501 |
lemma nat_rec_numeral [simp]: |
|
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46026
diff
changeset
|
502 |
"nat_rec a f (numeral v) = (let pv = nat (numeral v - 1) in f pv (nat_rec a f pv))" |
|
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46026
diff
changeset
|
503 |
by (subst expand_Suc, simp only: nat_rec_Suc nat_numeral_diff_1 Let_def) |
|
30652
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
504 |
|
|
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
505 |
lemma nat_rec_add_eq_if [simp]: |
|
47108
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46026
diff
changeset
|
506 |
"nat_rec a f (numeral v + n) = |
|
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46026
diff
changeset
|
507 |
(let pv = nat (numeral v - 1) in f (pv + n) (nat_rec a f (pv + n)))" |
|
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46026
diff
changeset
|
508 |
by (subst expand_Suc, simp only: nat_rec_Suc nat_numeral_diff_1 Let_def add_Suc) |
|
30652
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
509 |
|
|
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
510 |
|
|
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
511 |
subsubsection{*Various Other Lemmas*}
|
|
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
512 |
|
| 31080 | 513 |
lemma card_UNIV_bool[simp]: "card (UNIV :: bool set) = 2" |
514 |
by(simp add: UNIV_bool) |
|
515 |
||
|
30652
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
516 |
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
|
517 |
|
|
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
518 |
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
|
519 |
lemma nat_mult_2: "2 * z = (z+z::nat)" |
|
47108
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46026
diff
changeset
|
520 |
by (rule mult_2) (* FIXME: duplicate *) |
|
30652
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
521 |
|
|
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
522 |
lemma nat_mult_2_right: "z * 2 = (z+z::nat)" |
|
47108
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46026
diff
changeset
|
523 |
by (rule mult_2_right) (* FIXME: duplicate *) |
|
30652
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
524 |
|
|
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
525 |
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
|
526 |
lemma less_2_cases: "(n::nat) < 2 ==> n = 0 | n = Suc 0" |
|
47108
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46026
diff
changeset
|
527 |
by (auto simp add: numeral_2_eq_2) |
|
30652
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
528 |
|
|
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
529 |
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
|
530 |
|
|
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
531 |
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
|
532 |
by simp |
|
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
533 |
|
|
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
534 |
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
|
535 |
by simp |
|
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
536 |
|
|
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
537 |
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
|
538 |
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
|
539 |
by simp |
|
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
540 |
|
|
47108
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46026
diff
changeset
|
541 |
text{*Legacy theorems*}
|
|
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46026
diff
changeset
|
542 |
|
|
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46026
diff
changeset
|
543 |
lemmas nat_1_add_1 = one_add_one [where 'a=nat] |
|
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46026
diff
changeset
|
544 |
|
| 31096 | 545 |
end |