author | wenzelm |
Fri, 13 May 2011 23:58:40 +0200 | |
changeset 42795 | 66fcc9882784 |
parent 40690 | 3f472e57446a |
child 43526 | 2b92a6943915 |
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 |
||
25571
c9e39eafc7a0
instantiation target rather than legacy instance
haftmann
parents:
25481
diff
changeset
|
18 |
instantiation nat :: number |
c9e39eafc7a0
instantiation target rather than legacy instance
haftmann
parents:
25481
diff
changeset
|
19 |
begin |
c9e39eafc7a0
instantiation target rather than legacy instance
haftmann
parents:
25481
diff
changeset
|
20 |
|
c9e39eafc7a0
instantiation target rather than legacy instance
haftmann
parents:
25481
diff
changeset
|
21 |
definition |
32069
6d28bbd33e2c
prefer code_inline over code_unfold; use code_unfold_post where appropriate
haftmann
parents:
31998
diff
changeset
|
22 |
nat_number_of_def [code_unfold, code del]: "number_of v = nat (number_of v)" |
25571
c9e39eafc7a0
instantiation target rather than legacy instance
haftmann
parents:
25481
diff
changeset
|
23 |
|
c9e39eafc7a0
instantiation target rather than legacy instance
haftmann
parents:
25481
diff
changeset
|
24 |
instance .. |
c9e39eafc7a0
instantiation target rather than legacy instance
haftmann
parents:
25481
diff
changeset
|
25 |
|
c9e39eafc7a0
instantiation target rather than legacy instance
haftmann
parents:
25481
diff
changeset
|
26 |
end |
23164 | 27 |
|
31998
2c7a24f74db9
code attributes use common underscore convention
haftmann
parents:
31790
diff
changeset
|
28 |
lemma [code_post]: |
25965 | 29 |
"nat (number_of v) = number_of v" |
30 |
unfolding nat_number_of_def .. |
|
31 |
||
31014 | 32 |
|
33 |
subsection {* Special case: squares and cubes *} |
|
34 |
||
35 |
lemma numeral_2_eq_2: "2 = Suc (Suc 0)" |
|
36 |
by (simp add: nat_number_of_def) |
|
37 |
||
38 |
lemma numeral_3_eq_3: "3 = Suc (Suc (Suc 0))" |
|
39 |
by (simp add: nat_number_of_def) |
|
40 |
||
41 |
context power |
|
30960 | 42 |
begin |
43 |
||
23164 | 44 |
abbreviation (xsymbols) |
30960 | 45 |
power2 :: "'a \<Rightarrow> 'a" ("(_\<twosuperior>)" [1000] 999) where |
46 |
"x\<twosuperior> \<equiv> x ^ 2" |
|
23164 | 47 |
|
48 |
notation (latex output) |
|
29401
94fd5dd918f5
rename abbreviation square -> power2, to match theorem names
huffman
parents:
29045
diff
changeset
|
49 |
power2 ("(_\<twosuperior>)" [1000] 999) |
23164 | 50 |
|
51 |
notation (HTML output) |
|
29401
94fd5dd918f5
rename abbreviation square -> power2, to match theorem names
huffman
parents:
29045
diff
changeset
|
52 |
power2 ("(_\<twosuperior>)" [1000] 999) |
23164 | 53 |
|
30960 | 54 |
end |
55 |
||
31014 | 56 |
context monoid_mult |
57 |
begin |
|
58 |
||
59 |
lemma power2_eq_square: "a\<twosuperior> = a * a" |
|
60 |
by (simp add: numeral_2_eq_2) |
|
61 |
||
62 |
lemma power3_eq_cube: "a ^ 3 = a * a * a" |
|
63 |
by (simp add: numeral_3_eq_3 mult_assoc) |
|
64 |
||
65 |
lemma power_even_eq: |
|
66 |
"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
|
67 |
by (subst mult_commute) (simp add: power_mult) |
31014 | 68 |
|
69 |
lemma power_odd_eq: |
|
70 |
"a ^ Suc (2*n) = a * (a ^ n) ^ 2" |
|
71 |
by (simp add: power_even_eq) |
|
72 |
||
73 |
end |
|
74 |
||
75 |
context semiring_1 |
|
76 |
begin |
|
77 |
||
78 |
lemma zero_power2 [simp]: "0\<twosuperior> = 0" |
|
79 |
by (simp add: power2_eq_square) |
|
80 |
||
81 |
lemma one_power2 [simp]: "1\<twosuperior> = 1" |
|
82 |
by (simp add: power2_eq_square) |
|
83 |
||
84 |
end |
|
85 |
||
36823
001d1aad99de
add lemma power2_eq_1_iff; generalize some other lemmas
huffman
parents:
36719
diff
changeset
|
86 |
context ring_1 |
31014 | 87 |
begin |
88 |
||
89 |
lemma power2_minus [simp]: |
|
90 |
"(- a)\<twosuperior> = a\<twosuperior>" |
|
91 |
by (simp add: power2_eq_square) |
|
92 |
||
93 |
text{* |
|
94 |
We cannot prove general results about the numeral @{term "-1"}, |
|
95 |
so we have to use @{term "- 1"} instead. |
|
96 |
*} |
|
97 |
||
98 |
lemma power_minus1_even [simp]: |
|
99 |
"(- 1) ^ (2*n) = 1" |
|
100 |
proof (induct n) |
|
101 |
case 0 show ?case by simp |
|
102 |
next |
|
103 |
case (Suc n) then show ?case by (simp add: power_add) |
|
104 |
qed |
|
105 |
||
106 |
lemma power_minus1_odd: |
|
107 |
"(- 1) ^ Suc (2*n) = - 1" |
|
108 |
by simp |
|
109 |
||
110 |
lemma power_minus_even [simp]: |
|
111 |
"(-a) ^ (2*n) = a ^ (2*n)" |
|
112 |
by (simp add: power_minus [of a]) |
|
113 |
||
114 |
end |
|
115 |
||
36823
001d1aad99de
add lemma power2_eq_1_iff; generalize some other lemmas
huffman
parents:
36719
diff
changeset
|
116 |
context ring_1_no_zero_divisors |
001d1aad99de
add lemma power2_eq_1_iff; generalize some other lemmas
huffman
parents:
36719
diff
changeset
|
117 |
begin |
001d1aad99de
add lemma power2_eq_1_iff; generalize some other lemmas
huffman
parents:
36719
diff
changeset
|
118 |
|
001d1aad99de
add lemma power2_eq_1_iff; generalize some other lemmas
huffman
parents:
36719
diff
changeset
|
119 |
lemma zero_eq_power2 [simp]: |
001d1aad99de
add lemma power2_eq_1_iff; generalize some other lemmas
huffman
parents:
36719
diff
changeset
|
120 |
"a\<twosuperior> = 0 \<longleftrightarrow> a = 0" |
001d1aad99de
add lemma power2_eq_1_iff; generalize some other lemmas
huffman
parents:
36719
diff
changeset
|
121 |
unfolding power2_eq_square by simp |
001d1aad99de
add lemma power2_eq_1_iff; generalize some other lemmas
huffman
parents:
36719
diff
changeset
|
122 |
|
36964 | 123 |
lemma power2_eq_1_iff: |
36823
001d1aad99de
add lemma power2_eq_1_iff; generalize some other lemmas
huffman
parents:
36719
diff
changeset
|
124 |
"a\<twosuperior> = 1 \<longleftrightarrow> a = 1 \<or> a = - 1" |
36964 | 125 |
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
|
126 |
|
001d1aad99de
add lemma power2_eq_1_iff; generalize some other lemmas
huffman
parents:
36719
diff
changeset
|
127 |
end |
001d1aad99de
add lemma power2_eq_1_iff; generalize some other lemmas
huffman
parents:
36719
diff
changeset
|
128 |
|
35631
0b8a5fd339ab
generalize some lemmas from class linordered_ring_strict to linordered_ring
huffman
parents:
35216
diff
changeset
|
129 |
context linordered_ring |
31014 | 130 |
begin |
131 |
||
132 |
lemma sum_squares_ge_zero: |
|
133 |
"0 \<le> x * x + y * y" |
|
134 |
by (intro add_nonneg_nonneg zero_le_square) |
|
135 |
||
136 |
lemma not_sum_squares_lt_zero: |
|
137 |
"\<not> x * x + y * y < 0" |
|
138 |
by (simp add: not_less sum_squares_ge_zero) |
|
139 |
||
35631
0b8a5fd339ab
generalize some lemmas from class linordered_ring_strict to linordered_ring
huffman
parents:
35216
diff
changeset
|
140 |
end |
0b8a5fd339ab
generalize some lemmas from class linordered_ring_strict to linordered_ring
huffman
parents:
35216
diff
changeset
|
141 |
|
0b8a5fd339ab
generalize some lemmas from class linordered_ring_strict to linordered_ring
huffman
parents:
35216
diff
changeset
|
142 |
context linordered_ring_strict |
0b8a5fd339ab
generalize some lemmas from class linordered_ring_strict to linordered_ring
huffman
parents:
35216
diff
changeset
|
143 |
begin |
0b8a5fd339ab
generalize some lemmas from class linordered_ring_strict to linordered_ring
huffman
parents:
35216
diff
changeset
|
144 |
|
31014 | 145 |
lemma sum_squares_eq_zero_iff: |
146 |
"x * x + y * y = 0 \<longleftrightarrow> x = 0 \<and> y = 0" |
|
31034 | 147 |
by (simp add: add_nonneg_eq_0_iff) |
31014 | 148 |
|
149 |
lemma sum_squares_le_zero_iff: |
|
150 |
"x * x + y * y \<le> 0 \<longleftrightarrow> x = 0 \<and> y = 0" |
|
151 |
by (simp add: le_less not_sum_squares_lt_zero sum_squares_eq_zero_iff) |
|
152 |
||
153 |
lemma sum_squares_gt_zero_iff: |
|
154 |
"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
|
155 |
by (simp add: not_le [symmetric] sum_squares_le_zero_iff) |
31014 | 156 |
|
157 |
end |
|
158 |
||
35028
108662d50512
more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
haftmann
parents:
33342
diff
changeset
|
159 |
context linordered_semidom |
31014 | 160 |
begin |
161 |
||
162 |
lemma power2_le_imp_le: |
|
163 |
"x\<twosuperior> \<le> y\<twosuperior> \<Longrightarrow> 0 \<le> y \<Longrightarrow> x \<le> y" |
|
164 |
unfolding numeral_2_eq_2 by (rule power_le_imp_le_base) |
|
165 |
||
166 |
lemma power2_less_imp_less: |
|
167 |
"x\<twosuperior> < y\<twosuperior> \<Longrightarrow> 0 \<le> y \<Longrightarrow> x < y" |
|
168 |
by (rule power_less_imp_less_base) |
|
169 |
||
170 |
lemma power2_eq_imp_eq: |
|
171 |
"x\<twosuperior> = y\<twosuperior> \<Longrightarrow> 0 \<le> x \<Longrightarrow> 0 \<le> y \<Longrightarrow> x = y" |
|
172 |
unfolding numeral_2_eq_2 by (erule (2) power_eq_imp_eq_base) simp |
|
173 |
||
174 |
end |
|
175 |
||
35028
108662d50512
more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
haftmann
parents:
33342
diff
changeset
|
176 |
context linordered_idom |
31014 | 177 |
begin |
178 |
||
179 |
lemma zero_le_power2 [simp]: |
|
180 |
"0 \<le> a\<twosuperior>" |
|
181 |
by (simp add: power2_eq_square) |
|
182 |
||
183 |
lemma zero_less_power2 [simp]: |
|
184 |
"0 < a\<twosuperior> \<longleftrightarrow> a \<noteq> 0" |
|
185 |
by (force simp add: power2_eq_square zero_less_mult_iff linorder_neq_iff) |
|
186 |
||
187 |
lemma power2_less_0 [simp]: |
|
188 |
"\<not> a\<twosuperior> < 0" |
|
189 |
by (force simp add: power2_eq_square mult_less_0_iff) |
|
190 |
||
191 |
lemma abs_power2 [simp]: |
|
192 |
"abs (a\<twosuperior>) = a\<twosuperior>" |
|
193 |
by (simp add: power2_eq_square abs_mult abs_mult_self) |
|
194 |
||
195 |
lemma power2_abs [simp]: |
|
196 |
"(abs a)\<twosuperior> = a\<twosuperior>" |
|
197 |
by (simp add: power2_eq_square abs_mult_self) |
|
198 |
||
199 |
lemma odd_power_less_zero: |
|
200 |
"a < 0 \<Longrightarrow> a ^ Suc (2*n) < 0" |
|
201 |
proof (induct n) |
|
202 |
case 0 |
|
203 |
then show ?case by simp |
|
204 |
next |
|
205 |
case (Suc n) |
|
206 |
have "a ^ Suc (2 * Suc n) = (a*a) * a ^ Suc(2*n)" |
|
207 |
by (simp add: mult_ac power_add power2_eq_square) |
|
208 |
thus ?case |
|
209 |
by (simp del: power_Suc add: Suc mult_less_0_iff mult_neg_neg) |
|
210 |
qed |
|
211 |
||
212 |
lemma odd_0_le_power_imp_0_le: |
|
213 |
"0 \<le> a ^ Suc (2*n) \<Longrightarrow> 0 \<le> a" |
|
214 |
using odd_power_less_zero [of a n] |
|
215 |
by (force simp add: linorder_not_less [symmetric]) |
|
216 |
||
217 |
lemma zero_le_even_power'[simp]: |
|
218 |
"0 \<le> a ^ (2*n)" |
|
219 |
proof (induct n) |
|
220 |
case 0 |
|
35216 | 221 |
show ?case by simp |
31014 | 222 |
next |
223 |
case (Suc n) |
|
224 |
have "a ^ (2 * Suc n) = (a*a) * a ^ (2*n)" |
|
225 |
by (simp add: mult_ac power_add power2_eq_square) |
|
226 |
thus ?case |
|
227 |
by (simp add: Suc zero_le_mult_iff) |
|
228 |
qed |
|
229 |
||
230 |
lemma sum_power2_ge_zero: |
|
231 |
"0 \<le> x\<twosuperior> + y\<twosuperior>" |
|
232 |
unfolding power2_eq_square by (rule sum_squares_ge_zero) |
|
233 |
||
234 |
lemma not_sum_power2_lt_zero: |
|
235 |
"\<not> x\<twosuperior> + y\<twosuperior> < 0" |
|
236 |
unfolding power2_eq_square by (rule not_sum_squares_lt_zero) |
|
237 |
||
238 |
lemma sum_power2_eq_zero_iff: |
|
239 |
"x\<twosuperior> + y\<twosuperior> = 0 \<longleftrightarrow> x = 0 \<and> y = 0" |
|
240 |
unfolding power2_eq_square by (rule sum_squares_eq_zero_iff) |
|
241 |
||
242 |
lemma sum_power2_le_zero_iff: |
|
243 |
"x\<twosuperior> + y\<twosuperior> \<le> 0 \<longleftrightarrow> x = 0 \<and> y = 0" |
|
244 |
unfolding power2_eq_square by (rule sum_squares_le_zero_iff) |
|
245 |
||
246 |
lemma sum_power2_gt_zero_iff: |
|
247 |
"0 < x\<twosuperior> + y\<twosuperior> \<longleftrightarrow> x \<noteq> 0 \<or> y \<noteq> 0" |
|
248 |
unfolding power2_eq_square by (rule sum_squares_gt_zero_iff) |
|
249 |
||
250 |
end |
|
251 |
||
252 |
lemma power2_sum: |
|
253 |
fixes x y :: "'a::number_ring" |
|
254 |
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
|
255 |
by (simp add: ring_distribs power2_eq_square mult_2) (rule mult_commute) |
31014 | 256 |
|
257 |
lemma power2_diff: |
|
258 |
fixes x y :: "'a::number_ring" |
|
259 |
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
|
260 |
by (simp add: ring_distribs power2_eq_square mult_2) (rule mult_commute) |
31014 | 261 |
|
23164 | 262 |
|
29040
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
huffman
parents:
29039
diff
changeset
|
263 |
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
|
264 |
|
30652
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
265 |
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
|
266 |
"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
|
267 |
|
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
huffman
parents:
29039
diff
changeset
|
268 |
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
|
269 |
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
|
270 |
|
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
huffman
parents:
29039
diff
changeset
|
271 |
lemma neg_zminus_int [simp]: "neg (- (of_nat (Suc n)))" |
35216 | 272 |
by (simp add: neg_def del: of_nat_Suc) |
29040
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
huffman
parents:
29039
diff
changeset
|
273 |
|
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
huffman
parents:
29039
diff
changeset
|
274 |
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
|
275 |
|
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
huffman
parents:
29039
diff
changeset
|
276 |
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
|
277 |
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
|
278 |
|
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
huffman
parents:
29039
diff
changeset
|
279 |
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
|
280 |
|
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
huffman
parents:
29039
diff
changeset
|
281 |
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
|
282 |
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
|
283 |
|
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
huffman
parents:
29039
diff
changeset
|
284 |
lemma not_neg_1: "~ neg 1" |
35216 | 285 |
by (simp add: neg_def linorder_not_less) |
29040
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
huffman
parents:
29039
diff
changeset
|
286 |
|
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
huffman
parents:
29039
diff
changeset
|
287 |
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
|
288 |
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
|
289 |
|
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
huffman
parents:
29039
diff
changeset
|
290 |
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
|
291 |
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
|
292 |
|
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
huffman
parents:
29039
diff
changeset
|
293 |
text {* |
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
huffman
parents:
29039
diff
changeset
|
294 |
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
|
295 |
@{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
|
296 |
*} |
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
huffman
parents:
29039
diff
changeset
|
297 |
|
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
huffman
parents:
29039
diff
changeset
|
298 |
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
|
299 |
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
|
300 |
|
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
huffman
parents:
29039
diff
changeset
|
301 |
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
|
302 |
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
|
303 |
|
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
huffman
parents:
29039
diff
changeset
|
304 |
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
|
305 |
"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
|
306 |
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
|
307 |
|
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
huffman
parents:
29039
diff
changeset
|
308 |
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
|
309 |
"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
|
310 |
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
|
311 |
|
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
huffman
parents:
29039
diff
changeset
|
312 |
lemmas neg_simps [simp] = |
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
huffman
parents:
29039
diff
changeset
|
313 |
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
|
314 |
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
|
315 |
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
|
316 |
|
286c669d3a7a
move all neg-related lemmas to NatBin; make type of neg specific to int
huffman
parents:
29039
diff
changeset
|
317 |
|
23164 | 318 |
subsection{*Function @{term nat}: Coercion from Type @{typ int} to @{typ nat}*} |
319 |
||
35216 | 320 |
declare nat_1 [simp] |
23164 | 321 |
|
322 |
lemma nat_number_of [simp]: "nat (number_of w) = number_of w" |
|
323 |
by (simp add: nat_number_of_def) |
|
324 |
||
31998
2c7a24f74db9
code attributes use common underscore convention
haftmann
parents:
31790
diff
changeset
|
325 |
lemma nat_numeral_0_eq_0 [simp, code_post]: "Numeral0 = (0::nat)" |
23164 | 326 |
by (simp add: nat_number_of_def) |
327 |
||
328 |
lemma nat_numeral_1_eq_1 [simp]: "Numeral1 = (1::nat)" |
|
35216 | 329 |
by (simp add: nat_number_of_def) |
23164 | 330 |
|
36719 | 331 |
lemma Numeral1_eq1_nat: |
332 |
"(1::nat) = Numeral1" |
|
333 |
by simp |
|
334 |
||
31998
2c7a24f74db9
code attributes use common underscore convention
haftmann
parents:
31790
diff
changeset
|
335 |
lemma numeral_1_eq_Suc_0 [code_post]: "Numeral1 = Suc 0" |
35216 | 336 |
by (simp only: nat_numeral_1_eq_1 One_nat_def) |
23164 | 337 |
|
338 |
||
339 |
subsection{*Function @{term int}: Coercion from Type @{typ nat} to @{typ int}*} |
|
340 |
||
341 |
lemma int_nat_number_of [simp]: |
|
23365 | 342 |
"int (number_of v) = |
23307
2fe3345035c7
modify proofs to avoid referring to int::nat=>int
huffman
parents:
23294
diff
changeset
|
343 |
(if neg (number_of v :: int) then 0 |
2fe3345035c7
modify proofs to avoid referring to int::nat=>int
huffman
parents:
23294
diff
changeset
|
344 |
else (number_of v :: int))" |
28984 | 345 |
unfolding nat_number_of_def number_of_is_id neg_def |
346 |
by simp |
|
23307
2fe3345035c7
modify proofs to avoid referring to int::nat=>int
huffman
parents:
23294
diff
changeset
|
347 |
|
23164 | 348 |
|
349 |
subsubsection{*Successor *} |
|
350 |
||
351 |
lemma Suc_nat_eq_nat_zadd1: "(0::int) <= z ==> Suc (nat z) = nat (1 + z)" |
|
352 |
apply (rule sym) |
|
353 |
apply (simp add: nat_eq_iff int_Suc) |
|
354 |
done |
|
355 |
||
356 |
lemma Suc_nat_number_of_add: |
|
357 |
"Suc (number_of v + n) = |
|
28984 | 358 |
(if neg (number_of v :: int) then 1+n else number_of (Int.succ v) + n)" |
359 |
unfolding nat_number_of_def number_of_is_id neg_def numeral_simps |
|
360 |
by (simp add: Suc_nat_eq_nat_zadd1 add_ac) |
|
23164 | 361 |
|
362 |
lemma Suc_nat_number_of [simp]: |
|
363 |
"Suc (number_of v) = |
|
25919
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
25571
diff
changeset
|
364 |
(if neg (number_of v :: int) then 1 else number_of (Int.succ v))" |
23164 | 365 |
apply (cut_tac n = 0 in Suc_nat_number_of_add) |
366 |
apply (simp cong del: if_weak_cong) |
|
367 |
done |
|
368 |
||
369 |
||
370 |
subsubsection{*Addition *} |
|
371 |
||
372 |
lemma add_nat_number_of [simp]: |
|
373 |
"(number_of v :: nat) + number_of v' = |
|
29012 | 374 |
(if v < Int.Pls then number_of v' |
375 |
else if v' < Int.Pls then number_of v |
|
23164 | 376 |
else number_of (v + v'))" |
29012 | 377 |
unfolding nat_number_of_def number_of_is_id numeral_simps |
28984 | 378 |
by (simp add: nat_add_distrib) |
23164 | 379 |
|
30081 | 380 |
lemma nat_number_of_add_1 [simp]: |
381 |
"number_of v + (1::nat) = |
|
382 |
(if v < Int.Pls then 1 else number_of (Int.succ v))" |
|
383 |
unfolding nat_number_of_def number_of_is_id numeral_simps |
|
384 |
by (simp add: nat_add_distrib) |
|
385 |
||
386 |
lemma nat_1_add_number_of [simp]: |
|
387 |
"(1::nat) + number_of v = |
|
388 |
(if v < Int.Pls then 1 else number_of (Int.succ v))" |
|
389 |
unfolding nat_number_of_def number_of_is_id numeral_simps |
|
390 |
by (simp add: nat_add_distrib) |
|
391 |
||
392 |
lemma nat_1_add_1 [simp]: "1 + 1 = (2::nat)" |
|
393 |
by (rule int_int_eq [THEN iffD1]) simp |
|
394 |
||
23164 | 395 |
|
396 |
subsubsection{*Subtraction *} |
|
397 |
||
398 |
lemma diff_nat_eq_if: |
|
399 |
"nat z - nat z' = |
|
400 |
(if neg z' then nat z |
|
401 |
else let d = z-z' in |
|
402 |
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
|
403 |
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
|
404 |
|
23164 | 405 |
|
406 |
lemma diff_nat_number_of [simp]: |
|
407 |
"(number_of v :: nat) - number_of v' = |
|
29012 | 408 |
(if v' < Int.Pls then number_of v |
23164 | 409 |
else let d = number_of (v + uminus v') in |
410 |
if neg d then 0 else nat d)" |
|
29012 | 411 |
unfolding nat_number_of_def number_of_is_id numeral_simps neg_def |
412 |
by auto |
|
23164 | 413 |
|
30081 | 414 |
lemma nat_number_of_diff_1 [simp]: |
415 |
"number_of v - (1::nat) = |
|
416 |
(if v \<le> Int.Pls then 0 else number_of (Int.pred v))" |
|
417 |
unfolding nat_number_of_def number_of_is_id numeral_simps |
|
418 |
by auto |
|
419 |
||
23164 | 420 |
|
421 |
subsubsection{*Multiplication *} |
|
422 |
||
423 |
lemma mult_nat_number_of [simp]: |
|
424 |
"(number_of v :: nat) * number_of v' = |
|
29012 | 425 |
(if v < Int.Pls then 0 else number_of (v * v'))" |
426 |
unfolding nat_number_of_def number_of_is_id numeral_simps |
|
28984 | 427 |
by (simp add: nat_mult_distrib) |
23164 | 428 |
|
429 |
||
430 |
subsection{*Comparisons*} |
|
431 |
||
432 |
subsubsection{*Equals (=) *} |
|
433 |
||
434 |
lemma eq_nat_number_of [simp]: |
|
435 |
"((number_of v :: nat) = number_of v') = |
|
28969 | 436 |
(if neg (number_of v :: int) then (number_of v' :: int) \<le> 0 |
437 |
else if neg (number_of v' :: int) then (number_of v :: int) = 0 |
|
438 |
else v = v')" |
|
439 |
unfolding nat_number_of_def number_of_is_id neg_def |
|
440 |
by auto |
|
23164 | 441 |
|
442 |
||
443 |
subsubsection{*Less-than (<) *} |
|
444 |
||
445 |
lemma less_nat_number_of [simp]: |
|
29011 | 446 |
"(number_of v :: nat) < number_of v' \<longleftrightarrow> |
447 |
(if v < v' then Int.Pls < v' else False)" |
|
448 |
unfolding nat_number_of_def number_of_is_id numeral_simps |
|
28961 | 449 |
by auto |
23164 | 450 |
|
451 |
||
29010 | 452 |
subsubsection{*Less-than-or-equal *} |
453 |
||
454 |
lemma le_nat_number_of [simp]: |
|
455 |
"(number_of v :: nat) \<le> number_of v' \<longleftrightarrow> |
|
456 |
(if v \<le> v' then True else v \<le> Int.Pls)" |
|
457 |
unfolding nat_number_of_def number_of_is_id numeral_simps |
|
458 |
by auto |
|
459 |
||
23164 | 460 |
(*Maps #n to n for n = 0, 1, 2*) |
461 |
lemmas numerals = nat_numeral_0_eq_0 nat_numeral_1_eq_1 numeral_2_eq_2 |
|
462 |
||
463 |
||
464 |
subsection{*Powers with Numeric Exponents*} |
|
465 |
||
466 |
text{*Squares of literal numerals will be evaluated.*} |
|
31014 | 467 |
lemmas power2_eq_square_number_of [simp] = |
23164 | 468 |
power2_eq_square [of "number_of w", standard] |
469 |
||
470 |
||
471 |
text{*Simprules for comparisons where common factors can be cancelled.*} |
|
472 |
lemmas zero_compare_simps = |
|
473 |
add_strict_increasing add_strict_increasing2 add_increasing |
|
474 |
zero_le_mult_iff zero_le_divide_iff |
|
475 |
zero_less_mult_iff zero_less_divide_iff |
|
476 |
mult_le_0_iff divide_le_0_iff |
|
477 |
mult_less_0_iff divide_less_0_iff |
|
478 |
zero_le_power2 power2_less_0 |
|
479 |
||
480 |
subsubsection{*Nat *} |
|
481 |
||
482 |
lemma Suc_pred': "0 < n ==> n = Suc(n - 1)" |
|
35216 | 483 |
by simp |
23164 | 484 |
|
485 |
(*Expresses a natural number constant as the Suc of another one. |
|
486 |
NOT suitable for rewriting because n recurs in the condition.*) |
|
487 |
lemmas expand_Suc = Suc_pred' [of "number_of v", standard] |
|
488 |
||
489 |
subsubsection{*Arith *} |
|
490 |
||
31790 | 491 |
lemma Suc_eq_plus1: "Suc n = n + 1" |
35216 | 492 |
unfolding One_nat_def by simp |
23164 | 493 |
|
31790 | 494 |
lemma Suc_eq_plus1_left: "Suc n = 1 + n" |
35216 | 495 |
unfolding One_nat_def by simp |
23164 | 496 |
|
497 |
(* These two can be useful when m = number_of... *) |
|
498 |
||
499 |
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
|
500 |
unfolding One_nat_def by (cases m) simp_all |
23164 | 501 |
|
502 |
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
|
503 |
unfolding One_nat_def by (cases m) simp_all |
23164 | 504 |
|
505 |
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
|
506 |
unfolding One_nat_def by (cases m) simp_all |
23164 | 507 |
|
508 |
||
509 |
subsection{*Comparisons involving (0::nat) *} |
|
510 |
||
511 |
text{*Simplification already does @{term "n<0"}, @{term "n\<le>0"} and @{term "0\<le>n"}.*} |
|
512 |
||
513 |
lemma eq_number_of_0 [simp]: |
|
29012 | 514 |
"number_of v = (0::nat) \<longleftrightarrow> v \<le> Int.Pls" |
515 |
unfolding nat_number_of_def number_of_is_id numeral_simps |
|
516 |
by auto |
|
23164 | 517 |
|
518 |
lemma eq_0_number_of [simp]: |
|
29012 | 519 |
"(0::nat) = number_of v \<longleftrightarrow> v \<le> Int.Pls" |
23164 | 520 |
by (rule trans [OF eq_sym_conv eq_number_of_0]) |
521 |
||
522 |
lemma less_0_number_of [simp]: |
|
29012 | 523 |
"(0::nat) < number_of v \<longleftrightarrow> Int.Pls < v" |
524 |
unfolding nat_number_of_def number_of_is_id numeral_simps |
|
525 |
by simp |
|
23164 | 526 |
|
527 |
lemma neg_imp_number_of_eq_0: "neg (number_of v :: int) ==> number_of v = (0::nat)" |
|
28969 | 528 |
by (simp del: nat_numeral_0_eq_0 add: nat_numeral_0_eq_0 [symmetric]) |
23164 | 529 |
|
530 |
||
531 |
||
532 |
subsection{*Comparisons involving @{term Suc} *} |
|
533 |
||
534 |
lemma eq_number_of_Suc [simp]: |
|
535 |
"(number_of v = Suc n) = |
|
25919
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
25571
diff
changeset
|
536 |
(let pv = number_of (Int.pred v) in |
23164 | 537 |
if neg pv then False else nat pv = n)" |
538 |
apply (simp only: simp_thms Let_def neg_eq_less_0 linorder_not_less |
|
539 |
number_of_pred nat_number_of_def |
|
540 |
split add: split_if) |
|
541 |
apply (rule_tac x = "number_of v" in spec) |
|
542 |
apply (auto simp add: nat_eq_iff) |
|
543 |
done |
|
544 |
||
545 |
lemma Suc_eq_number_of [simp]: |
|
546 |
"(Suc n = number_of v) = |
|
25919
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
25571
diff
changeset
|
547 |
(let pv = number_of (Int.pred v) in |
23164 | 548 |
if neg pv then False else nat pv = n)" |
549 |
by (rule trans [OF eq_sym_conv eq_number_of_Suc]) |
|
550 |
||
551 |
lemma less_number_of_Suc [simp]: |
|
552 |
"(number_of v < Suc n) = |
|
25919
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
25571
diff
changeset
|
553 |
(let pv = number_of (Int.pred v) in |
23164 | 554 |
if neg pv then True else nat pv < n)" |
555 |
apply (simp only: simp_thms Let_def neg_eq_less_0 linorder_not_less |
|
556 |
number_of_pred nat_number_of_def |
|
557 |
split add: split_if) |
|
558 |
apply (rule_tac x = "number_of v" in spec) |
|
559 |
apply (auto simp add: nat_less_iff) |
|
560 |
done |
|
561 |
||
562 |
lemma less_Suc_number_of [simp]: |
|
563 |
"(Suc n < number_of v) = |
|
25919
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
25571
diff
changeset
|
564 |
(let pv = number_of (Int.pred v) in |
23164 | 565 |
if neg pv then False else n < nat pv)" |
566 |
apply (simp only: simp_thms Let_def neg_eq_less_0 linorder_not_less |
|
567 |
number_of_pred nat_number_of_def |
|
568 |
split add: split_if) |
|
569 |
apply (rule_tac x = "number_of v" in spec) |
|
570 |
apply (auto simp add: zless_nat_eq_int_zless) |
|
571 |
done |
|
572 |
||
573 |
lemma le_number_of_Suc [simp]: |
|
574 |
"(number_of v <= Suc n) = |
|
25919
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
25571
diff
changeset
|
575 |
(let pv = number_of (Int.pred v) in |
23164 | 576 |
if neg pv then True else nat pv <= n)" |
35216 | 577 |
by (simp add: Let_def linorder_not_less [symmetric]) |
23164 | 578 |
|
579 |
lemma le_Suc_number_of [simp]: |
|
580 |
"(Suc n <= number_of v) = |
|
25919
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
25571
diff
changeset
|
581 |
(let pv = number_of (Int.pred v) in |
23164 | 582 |
if neg pv then False else n <= nat pv)" |
35216 | 583 |
by (simp add: Let_def linorder_not_less [symmetric]) |
23164 | 584 |
|
585 |
||
25919
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
25571
diff
changeset
|
586 |
lemma eq_number_of_Pls_Min: "(Numeral0 ::int) ~= number_of Int.Min" |
23164 | 587 |
by auto |
588 |
||
589 |
||
590 |
||
591 |
subsection{*Max and Min Combined with @{term Suc} *} |
|
592 |
||
593 |
lemma max_number_of_Suc [simp]: |
|
594 |
"max (Suc n) (number_of v) = |
|
25919
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
25571
diff
changeset
|
595 |
(let pv = number_of (Int.pred v) in |
23164 | 596 |
if neg pv then Suc n else Suc(max n (nat pv)))" |
597 |
apply (simp only: Let_def neg_eq_less_0 number_of_pred nat_number_of_def |
|
598 |
split add: split_if nat.split) |
|
599 |
apply (rule_tac x = "number_of v" in spec) |
|
600 |
apply auto |
|
601 |
done |
|
602 |
||
603 |
lemma max_Suc_number_of [simp]: |
|
604 |
"max (number_of v) (Suc n) = |
|
25919
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
25571
diff
changeset
|
605 |
(let pv = number_of (Int.pred v) in |
23164 | 606 |
if neg pv then Suc n else Suc(max (nat pv) n))" |
607 |
apply (simp only: Let_def neg_eq_less_0 number_of_pred nat_number_of_def |
|
608 |
split add: split_if nat.split) |
|
609 |
apply (rule_tac x = "number_of v" in spec) |
|
610 |
apply auto |
|
611 |
done |
|
612 |
||
613 |
lemma min_number_of_Suc [simp]: |
|
614 |
"min (Suc n) (number_of v) = |
|
25919
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
25571
diff
changeset
|
615 |
(let pv = number_of (Int.pred v) in |
23164 | 616 |
if neg pv then 0 else Suc(min n (nat pv)))" |
617 |
apply (simp only: Let_def neg_eq_less_0 number_of_pred nat_number_of_def |
|
618 |
split add: split_if nat.split) |
|
619 |
apply (rule_tac x = "number_of v" in spec) |
|
620 |
apply auto |
|
621 |
done |
|
622 |
||
623 |
lemma min_Suc_number_of [simp]: |
|
624 |
"min (number_of v) (Suc n) = |
|
25919
8b1c0d434824
joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents:
25571
diff
changeset
|
625 |
(let pv = number_of (Int.pred v) in |
23164 | 626 |
if neg pv then 0 else Suc(min (nat pv) n))" |
627 |
apply (simp only: Let_def neg_eq_less_0 number_of_pred nat_number_of_def |
|
628 |
split add: split_if nat.split) |
|
629 |
apply (rule_tac x = "number_of v" in spec) |
|
630 |
apply auto |
|
631 |
done |
|
632 |
||
633 |
subsection{*Literal arithmetic involving powers*} |
|
634 |
||
635 |
lemma power_nat_number_of: |
|
636 |
"(number_of v :: nat) ^ n = |
|
637 |
(if neg (number_of v :: int) then 0^n else nat ((number_of v :: int) ^ n))" |
|
638 |
by (simp only: simp_thms neg_nat not_neg_eq_ge_0 nat_number_of_def nat_power_eq |
|
639 |
split add: split_if cong: imp_cong) |
|
640 |
||
641 |
||
642 |
lemmas power_nat_number_of_number_of = power_nat_number_of [of _ "number_of w", standard] |
|
643 |
declare power_nat_number_of_number_of [simp] |
|
644 |
||
645 |
||
646 |
||
23294 | 647 |
text{*For arbitrary rings*} |
23164 | 648 |
|
23294 | 649 |
lemma power_number_of_even: |
31014 | 650 |
fixes z :: "'a::number_ring" |
26086
3c243098b64a
New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents:
25965
diff
changeset
|
651 |
shows "z ^ number_of (Int.Bit0 w) = (let w = z ^ (number_of w) in w * w)" |
33296
a3924d1069e5
moved theory Divides after theory Nat_Numeral; tuned some proof texts
haftmann
parents:
32069
diff
changeset
|
652 |
by (cases "w \<ge> 0") (auto simp add: Let_def Bit0_def nat_number_of_def number_of_is_id |
a3924d1069e5
moved theory Divides after theory Nat_Numeral; tuned some proof texts
haftmann
parents:
32069
diff
changeset
|
653 |
nat_add_distrib power_add simp del: nat_number_of) |
23164 | 654 |
|
23294 | 655 |
lemma power_number_of_odd: |
31014 | 656 |
fixes z :: "'a::number_ring" |
26086
3c243098b64a
New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents:
25965
diff
changeset
|
657 |
shows "z ^ number_of (Int.Bit1 w) = (if (0::int) <= number_of w |
23164 | 658 |
then (let w = z ^ (number_of w) in z * w * w) else 1)" |
35815
10e723e54076
tuned proofs (to avoid linarith error message caused by bootstrapping of HOL)
boehmes
parents:
35631
diff
changeset
|
659 |
unfolding Let_def Bit1_def nat_number_of_def number_of_is_id |
10e723e54076
tuned proofs (to avoid linarith error message caused by bootstrapping of HOL)
boehmes
parents:
35631
diff
changeset
|
660 |
apply (cases "0 <= w") |
10e723e54076
tuned proofs (to avoid linarith error message caused by bootstrapping of HOL)
boehmes
parents:
35631
diff
changeset
|
661 |
apply (simp only: mult_assoc nat_add_distrib power_add, simp) |
33296
a3924d1069e5
moved theory Divides after theory Nat_Numeral; tuned some proof texts
haftmann
parents:
32069
diff
changeset
|
662 |
apply (simp add: not_le mult_2 [symmetric] add_assoc) |
23164 | 663 |
done |
664 |
||
23294 | 665 |
lemmas zpower_number_of_even = power_number_of_even [where 'a=int] |
666 |
lemmas zpower_number_of_odd = power_number_of_odd [where 'a=int] |
|
23164 | 667 |
|
23294 | 668 |
lemmas power_number_of_even_number_of [simp] = |
669 |
power_number_of_even [of "number_of v", standard] |
|
23164 | 670 |
|
23294 | 671 |
lemmas power_number_of_odd_number_of [simp] = |
672 |
power_number_of_odd [of "number_of v", standard] |
|
23164 | 673 |
|
674 |
lemma nat_number_of_Pls: "Numeral0 = (0::nat)" |
|
35216 | 675 |
by (simp add: nat_number_of_def) |
23164 | 676 |
|
40690
3f472e57446a
added "no_atp" for fact that confuses the SMT normalizer and that doesn't help ATPs anyway
blanchet
parents:
40077
diff
changeset
|
677 |
lemma nat_number_of_Min [no_atp]: "number_of Int.Min = (0::nat)" |
23164 | 678 |
apply (simp only: number_of_Min nat_number_of_def nat_zminus_int) |
679 |
done |
|
680 |
||
26086
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_Bit0: |
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.Bit0 w) = (let n::nat = number_of w in n + n)" |
33296
a3924d1069e5
moved theory Divides after theory Nat_Numeral; tuned some proof texts
haftmann
parents:
32069
diff
changeset
|
683 |
by (cases "w \<ge> 0") (auto simp add: Let_def Bit0_def nat_number_of_def number_of_is_id |
a3924d1069e5
moved theory Divides after theory Nat_Numeral; tuned some proof texts
haftmann
parents:
32069
diff
changeset
|
684 |
nat_add_distrib simp del: nat_number_of) |
26086
3c243098b64a
New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents:
25965
diff
changeset
|
685 |
|
3c243098b64a
New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents:
25965
diff
changeset
|
686 |
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
|
687 |
"number_of (Int.Bit1 w) = |
23164 | 688 |
(if neg (number_of w :: int) then 0 |
689 |
else let n = number_of w in Suc (n + n))" |
|
35815
10e723e54076
tuned proofs (to avoid linarith error message caused by bootstrapping of HOL)
boehmes
parents:
35631
diff
changeset
|
690 |
unfolding Let_def Bit1_def nat_number_of_def number_of_is_id neg_def |
10e723e54076
tuned proofs (to avoid linarith error message caused by bootstrapping of HOL)
boehmes
parents:
35631
diff
changeset
|
691 |
apply (cases "w < 0") |
33296
a3924d1069e5
moved theory Divides after theory Nat_Numeral; tuned some proof texts
haftmann
parents:
32069
diff
changeset
|
692 |
apply (simp add: mult_2 [symmetric] add_assoc) |
35815
10e723e54076
tuned proofs (to avoid linarith error message caused by bootstrapping of HOL)
boehmes
parents:
35631
diff
changeset
|
693 |
apply (simp only: nat_add_distrib, simp) |
33296
a3924d1069e5
moved theory Divides after theory Nat_Numeral; tuned some proof texts
haftmann
parents:
32069
diff
changeset
|
694 |
done |
23164 | 695 |
|
40077 | 696 |
lemmas eval_nat_numeral = |
35216 | 697 |
nat_number_of_Bit0 nat_number_of_Bit1 |
698 |
||
36699
816da1023508
moved nat_arith ot Nat_Numeral: clarified normalizer setup
haftmann
parents:
35815
diff
changeset
|
699 |
lemmas nat_arith = |
816da1023508
moved nat_arith ot Nat_Numeral: clarified normalizer setup
haftmann
parents:
35815
diff
changeset
|
700 |
add_nat_number_of |
816da1023508
moved nat_arith ot Nat_Numeral: clarified normalizer setup
haftmann
parents:
35815
diff
changeset
|
701 |
diff_nat_number_of |
816da1023508
moved nat_arith ot Nat_Numeral: clarified normalizer setup
haftmann
parents:
35815
diff
changeset
|
702 |
mult_nat_number_of |
816da1023508
moved nat_arith ot Nat_Numeral: clarified normalizer setup
haftmann
parents:
35815
diff
changeset
|
703 |
eq_nat_number_of |
816da1023508
moved nat_arith ot Nat_Numeral: clarified normalizer setup
haftmann
parents:
35815
diff
changeset
|
704 |
less_nat_number_of |
816da1023508
moved nat_arith ot Nat_Numeral: clarified normalizer setup
haftmann
parents:
35815
diff
changeset
|
705 |
|
36716 | 706 |
lemmas semiring_norm = |
707 |
Let_def arith_simps nat_arith rel_simps neg_simps if_False |
|
708 |
if_True add_0 add_Suc add_number_of_left mult_number_of_left |
|
709 |
numeral_1_eq_1 [symmetric] Suc_eq_plus1 |
|
710 |
numeral_0_eq_0 [symmetric] numerals [symmetric] |
|
36841
02df88789641
include iszero_simps in semiring_norm just once (they are already included in rel_simps)
huffman
parents:
36823
diff
changeset
|
711 |
not_iszero_Numeral1 |
36716 | 712 |
|
23164 | 713 |
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
|
714 |
by (fact Let_def) |
23164 | 715 |
|
31014 | 716 |
lemma power_m1_even: "(-1) ^ (2*n) = (1::'a::{number_ring})" |
717 |
by (simp only: number_of_Min power_minus1_even) |
|
23164 | 718 |
|
31014 | 719 |
lemma power_m1_odd: "(-1) ^ Suc(2*n) = (-1::'a::{number_ring})" |
720 |
by (simp only: number_of_Min power_minus1_odd) |
|
23164 | 721 |
|
33296
a3924d1069e5
moved theory Divides after theory Nat_Numeral; tuned some proof texts
haftmann
parents:
32069
diff
changeset
|
722 |
lemma nat_number_of_add_left: |
a3924d1069e5
moved theory Divides after theory Nat_Numeral; tuned some proof texts
haftmann
parents:
32069
diff
changeset
|
723 |
"number_of v + (number_of v' + (k::nat)) = |
a3924d1069e5
moved theory Divides after theory Nat_Numeral; tuned some proof texts
haftmann
parents:
32069
diff
changeset
|
724 |
(if neg (number_of v :: int) then number_of v' + k |
a3924d1069e5
moved theory Divides after theory Nat_Numeral; tuned some proof texts
haftmann
parents:
32069
diff
changeset
|
725 |
else if neg (number_of v' :: int) then number_of v + k |
a3924d1069e5
moved theory Divides after theory Nat_Numeral; tuned some proof texts
haftmann
parents:
32069
diff
changeset
|
726 |
else number_of (v + v') + k)" |
a3924d1069e5
moved theory Divides after theory Nat_Numeral; tuned some proof texts
haftmann
parents:
32069
diff
changeset
|
727 |
by (auto simp add: neg_def) |
a3924d1069e5
moved theory Divides after theory Nat_Numeral; tuned some proof texts
haftmann
parents:
32069
diff
changeset
|
728 |
|
a3924d1069e5
moved theory Divides after theory Nat_Numeral; tuned some proof texts
haftmann
parents:
32069
diff
changeset
|
729 |
lemma nat_number_of_mult_left: |
a3924d1069e5
moved theory Divides after theory Nat_Numeral; tuned some proof texts
haftmann
parents:
32069
diff
changeset
|
730 |
"number_of v * (number_of v' * (k::nat)) = |
a3924d1069e5
moved theory Divides after theory Nat_Numeral; tuned some proof texts
haftmann
parents:
32069
diff
changeset
|
731 |
(if v < Int.Pls then 0 |
a3924d1069e5
moved theory Divides after theory Nat_Numeral; tuned some proof texts
haftmann
parents:
32069
diff
changeset
|
732 |
else number_of (v * v') * k)" |
a3924d1069e5
moved theory Divides after theory Nat_Numeral; tuned some proof texts
haftmann
parents:
32069
diff
changeset
|
733 |
by (auto simp add: not_less Pls_def nat_number_of_def number_of_is_id |
a3924d1069e5
moved theory Divides after theory Nat_Numeral; tuned some proof texts
haftmann
parents:
32069
diff
changeset
|
734 |
nat_mult_distrib simp del: nat_number_of) |
a3924d1069e5
moved theory Divides after theory Nat_Numeral; tuned some proof texts
haftmann
parents:
32069
diff
changeset
|
735 |
|
23164 | 736 |
|
737 |
subsection{*Literal arithmetic and @{term of_nat}*} |
|
738 |
||
739 |
lemma of_nat_double: |
|
740 |
"0 \<le> x ==> of_nat (nat (2 * x)) = of_nat (nat x) + of_nat (nat x)" |
|
741 |
by (simp only: mult_2 nat_add_distrib of_nat_add) |
|
742 |
||
743 |
lemma nat_numeral_m1_eq_0: "-1 = (0::nat)" |
|
744 |
by (simp only: nat_number_of_def) |
|
745 |
||
746 |
lemma of_nat_number_of_lemma: |
|
747 |
"of_nat (number_of v :: nat) = |
|
748 |
(if 0 \<le> (number_of v :: int) |
|
749 |
then (number_of v :: 'a :: number_ring) |
|
750 |
else 0)" |
|
33296
a3924d1069e5
moved theory Divides after theory Nat_Numeral; tuned some proof texts
haftmann
parents:
32069
diff
changeset
|
751 |
by (simp add: int_number_of_def nat_number_of_def number_of_eq of_nat_nat) |
23164 | 752 |
|
753 |
lemma of_nat_number_of_eq [simp]: |
|
754 |
"of_nat (number_of v :: nat) = |
|
755 |
(if neg (number_of v :: int) then 0 |
|
756 |
else (number_of v :: 'a :: number_ring))" |
|
757 |
by (simp only: of_nat_number_of_lemma neg_def, simp) |
|
758 |
||
759 |
||
30652
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
760 |
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
|
761 |
|
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
762 |
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
|
763 |
|
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
764 |
lemma Suc_diff_eq_diff_pred: "Numeral0 < n ==> Suc m - n = m - (n - Numeral1)" |
35216 | 765 |
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
|
766 |
|
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
767 |
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
|
768 |
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
|
769 |
tests.*} |
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
770 |
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
|
771 |
"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
|
772 |
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
|
773 |
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
|
774 |
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
|
775 |
done |
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
776 |
|
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
777 |
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
|
778 |
simproc*} |
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
779 |
lemma Suc_diff_number_of: |
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
780 |
"Int.Pls < v ==> |
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
781 |
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
|
782 |
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
|
783 |
apply simp |
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
784 |
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
|
785 |
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
|
786 |
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
|
787 |
done |
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
788 |
|
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
789 |
lemma diff_Suc_eq_diff_pred: "m - Suc n = (m - 1) - n" |
35216 | 790 |
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
|
791 |
|
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
792 |
|
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
793 |
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
|
794 |
|
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
795 |
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
|
796 |
"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
|
797 |
(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
|
798 |
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
|
799 |
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
|
800 |
|
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
801 |
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
|
802 |
"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
|
803 |
(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
|
804 |
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
|
805 |
apply (subst add_eq_if) |
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
806 |
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
|
807 |
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
|
808 |
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
|
809 |
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
|
810 |
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
|
811 |
done |
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
812 |
|
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
813 |
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
|
814 |
"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
|
815 |
(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
|
816 |
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
|
817 |
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
|
818 |
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
|
819 |
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
|
820 |
done |
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
821 |
|
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
822 |
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
|
823 |
"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
|
824 |
(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
|
825 |
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
|
826 |
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
|
827 |
apply (subst add_eq_if) |
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
828 |
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
|
829 |
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
|
830 |
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
|
831 |
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
|
832 |
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
|
833 |
done |
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
834 |
|
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
835 |
|
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
836 |
subsubsection{*Various Other Lemmas*} |
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
837 |
|
31080 | 838 |
lemma card_UNIV_bool[simp]: "card (UNIV :: bool set) = 2" |
839 |
by(simp add: UNIV_bool) |
|
840 |
||
30652
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
841 |
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
|
842 |
|
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
843 |
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
|
844 |
lemma nat_mult_2: "2 * z = (z+z::nat)" |
33296
a3924d1069e5
moved theory Divides after theory Nat_Numeral; tuned some proof texts
haftmann
parents:
32069
diff
changeset
|
845 |
unfolding nat_1_add_1 [symmetric] left_distrib by simp |
30652
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
846 |
|
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
847 |
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
|
848 |
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
|
849 |
|
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
850 |
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
|
851 |
lemma less_2_cases: "(n::nat) < 2 ==> n = 0 | n = Suc 0" |
33296
a3924d1069e5
moved theory Divides after theory Nat_Numeral; tuned some proof texts
haftmann
parents:
32069
diff
changeset
|
852 |
by (auto simp add: nat_1_add_1 [symmetric]) |
30652
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
853 |
|
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
854 |
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
|
855 |
|
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
856 |
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
|
857 |
by simp |
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 |
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
|
860 |
by simp |
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
861 |
|
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
862 |
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
|
863 |
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
|
864 |
by simp |
752329615264
distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents:
30497
diff
changeset
|
865 |
|
31096 | 866 |
end |