40 |
51 |
41 notation (HTML output) |
52 notation (HTML output) |
42 power2 ("(_\<twosuperior>)" [1000] 999) |
53 power2 ("(_\<twosuperior>)" [1000] 999) |
43 |
54 |
44 end |
55 end |
|
56 |
|
57 context monoid_mult |
|
58 begin |
|
59 |
|
60 lemma power2_eq_square: "a\<twosuperior> = a * a" |
|
61 by (simp add: numeral_2_eq_2) |
|
62 |
|
63 lemma power3_eq_cube: "a ^ 3 = a * a * a" |
|
64 by (simp add: numeral_3_eq_3 mult_assoc) |
|
65 |
|
66 lemma power_even_eq: |
|
67 "a ^ (2*n) = (a ^ n) ^ 2" |
|
68 by (subst OrderedGroup.mult_commute) (simp add: power_mult) |
|
69 |
|
70 lemma power_odd_eq: |
|
71 "a ^ Suc (2*n) = a * (a ^ n) ^ 2" |
|
72 by (simp add: power_even_eq) |
|
73 |
|
74 end |
|
75 |
|
76 context semiring_1 |
|
77 begin |
|
78 |
|
79 lemma zero_power2 [simp]: "0\<twosuperior> = 0" |
|
80 by (simp add: power2_eq_square) |
|
81 |
|
82 lemma one_power2 [simp]: "1\<twosuperior> = 1" |
|
83 by (simp add: power2_eq_square) |
|
84 |
|
85 end |
|
86 |
|
87 context comm_ring_1 |
|
88 begin |
|
89 |
|
90 lemma power2_minus [simp]: |
|
91 "(- a)\<twosuperior> = a\<twosuperior>" |
|
92 by (simp add: power2_eq_square) |
|
93 |
|
94 text{* |
|
95 We cannot prove general results about the numeral @{term "-1"}, |
|
96 so we have to use @{term "- 1"} instead. |
|
97 *} |
|
98 |
|
99 lemma power_minus1_even [simp]: |
|
100 "(- 1) ^ (2*n) = 1" |
|
101 proof (induct n) |
|
102 case 0 show ?case by simp |
|
103 next |
|
104 case (Suc n) then show ?case by (simp add: power_add) |
|
105 qed |
|
106 |
|
107 lemma power_minus1_odd: |
|
108 "(- 1) ^ Suc (2*n) = - 1" |
|
109 by simp |
|
110 |
|
111 lemma power_minus_even [simp]: |
|
112 "(-a) ^ (2*n) = a ^ (2*n)" |
|
113 by (simp add: power_minus [of a]) |
|
114 |
|
115 end |
|
116 |
|
117 context ordered_ring_strict |
|
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 |
|
128 lemma sum_squares_eq_zero_iff: |
|
129 "x * x + y * y = 0 \<longleftrightarrow> x = 0 \<and> y = 0" |
|
130 by (simp add: sum_nonneg_eq_zero_iff) |
|
131 |
|
132 lemma sum_squares_le_zero_iff: |
|
133 "x * x + y * y \<le> 0 \<longleftrightarrow> x = 0 \<and> y = 0" |
|
134 by (simp add: le_less not_sum_squares_lt_zero sum_squares_eq_zero_iff) |
|
135 |
|
136 lemma sum_squares_gt_zero_iff: |
|
137 "0 < x * x + y * y \<longleftrightarrow> x \<noteq> 0 \<or> y \<noteq> 0" |
|
138 proof - |
|
139 have "x * x + y * y \<noteq> 0 \<longleftrightarrow> x \<noteq> 0 \<or> y \<noteq> 0" |
|
140 by (simp add: sum_squares_eq_zero_iff) |
|
141 then have "0 \<noteq> x * x + y * y \<longleftrightarrow> x \<noteq> 0 \<or> y \<noteq> 0" |
|
142 by auto |
|
143 then show ?thesis |
|
144 by (simp add: less_le sum_squares_ge_zero) |
|
145 qed |
|
146 |
|
147 end |
|
148 |
|
149 context ordered_semidom |
|
150 begin |
|
151 |
|
152 lemma power2_le_imp_le: |
|
153 "x\<twosuperior> \<le> y\<twosuperior> \<Longrightarrow> 0 \<le> y \<Longrightarrow> x \<le> y" |
|
154 unfolding numeral_2_eq_2 by (rule power_le_imp_le_base) |
|
155 |
|
156 lemma power2_less_imp_less: |
|
157 "x\<twosuperior> < y\<twosuperior> \<Longrightarrow> 0 \<le> y \<Longrightarrow> x < y" |
|
158 by (rule power_less_imp_less_base) |
|
159 |
|
160 lemma power2_eq_imp_eq: |
|
161 "x\<twosuperior> = y\<twosuperior> \<Longrightarrow> 0 \<le> x \<Longrightarrow> 0 \<le> y \<Longrightarrow> x = y" |
|
162 unfolding numeral_2_eq_2 by (erule (2) power_eq_imp_eq_base) simp |
|
163 |
|
164 end |
|
165 |
|
166 context ordered_idom |
|
167 begin |
|
168 |
|
169 lemma zero_eq_power2 [simp]: |
|
170 "a\<twosuperior> = 0 \<longleftrightarrow> a = 0" |
|
171 by (force simp add: power2_eq_square) |
|
172 |
|
173 lemma zero_le_power2 [simp]: |
|
174 "0 \<le> a\<twosuperior>" |
|
175 by (simp add: power2_eq_square) |
|
176 |
|
177 lemma zero_less_power2 [simp]: |
|
178 "0 < a\<twosuperior> \<longleftrightarrow> a \<noteq> 0" |
|
179 by (force simp add: power2_eq_square zero_less_mult_iff linorder_neq_iff) |
|
180 |
|
181 lemma power2_less_0 [simp]: |
|
182 "\<not> a\<twosuperior> < 0" |
|
183 by (force simp add: power2_eq_square mult_less_0_iff) |
|
184 |
|
185 lemma abs_power2 [simp]: |
|
186 "abs (a\<twosuperior>) = a\<twosuperior>" |
|
187 by (simp add: power2_eq_square abs_mult abs_mult_self) |
|
188 |
|
189 lemma power2_abs [simp]: |
|
190 "(abs a)\<twosuperior> = a\<twosuperior>" |
|
191 by (simp add: power2_eq_square abs_mult_self) |
|
192 |
|
193 lemma odd_power_less_zero: |
|
194 "a < 0 \<Longrightarrow> a ^ Suc (2*n) < 0" |
|
195 proof (induct n) |
|
196 case 0 |
|
197 then show ?case by simp |
|
198 next |
|
199 case (Suc n) |
|
200 have "a ^ Suc (2 * Suc n) = (a*a) * a ^ Suc(2*n)" |
|
201 by (simp add: mult_ac power_add power2_eq_square) |
|
202 thus ?case |
|
203 by (simp del: power_Suc add: Suc mult_less_0_iff mult_neg_neg) |
|
204 qed |
|
205 |
|
206 lemma odd_0_le_power_imp_0_le: |
|
207 "0 \<le> a ^ Suc (2*n) \<Longrightarrow> 0 \<le> a" |
|
208 using odd_power_less_zero [of a n] |
|
209 by (force simp add: linorder_not_less [symmetric]) |
|
210 |
|
211 lemma zero_le_even_power'[simp]: |
|
212 "0 \<le> a ^ (2*n)" |
|
213 proof (induct n) |
|
214 case 0 |
|
215 show ?case by (simp add: zero_le_one) |
|
216 next |
|
217 case (Suc n) |
|
218 have "a ^ (2 * Suc n) = (a*a) * a ^ (2*n)" |
|
219 by (simp add: mult_ac power_add power2_eq_square) |
|
220 thus ?case |
|
221 by (simp add: Suc zero_le_mult_iff) |
|
222 qed |
|
223 |
|
224 lemma sum_power2_ge_zero: |
|
225 "0 \<le> x\<twosuperior> + y\<twosuperior>" |
|
226 unfolding power2_eq_square by (rule sum_squares_ge_zero) |
|
227 |
|
228 lemma not_sum_power2_lt_zero: |
|
229 "\<not> x\<twosuperior> + y\<twosuperior> < 0" |
|
230 unfolding power2_eq_square by (rule not_sum_squares_lt_zero) |
|
231 |
|
232 lemma sum_power2_eq_zero_iff: |
|
233 "x\<twosuperior> + y\<twosuperior> = 0 \<longleftrightarrow> x = 0 \<and> y = 0" |
|
234 unfolding power2_eq_square by (rule sum_squares_eq_zero_iff) |
|
235 |
|
236 lemma sum_power2_le_zero_iff: |
|
237 "x\<twosuperior> + y\<twosuperior> \<le> 0 \<longleftrightarrow> x = 0 \<and> y = 0" |
|
238 unfolding power2_eq_square by (rule sum_squares_le_zero_iff) |
|
239 |
|
240 lemma sum_power2_gt_zero_iff: |
|
241 "0 < x\<twosuperior> + y\<twosuperior> \<longleftrightarrow> x \<noteq> 0 \<or> y \<noteq> 0" |
|
242 unfolding power2_eq_square by (rule sum_squares_gt_zero_iff) |
|
243 |
|
244 end |
|
245 |
|
246 lemma power2_sum: |
|
247 fixes x y :: "'a::number_ring" |
|
248 shows "(x + y)\<twosuperior> = x\<twosuperior> + y\<twosuperior> + 2 * x * y" |
|
249 by (simp add: ring_distribs power2_eq_square) |
|
250 |
|
251 lemma power2_diff: |
|
252 fixes x y :: "'a::number_ring" |
|
253 shows "(x - y)\<twosuperior> = x\<twosuperior> + y\<twosuperior> - 2 * x * y" |
|
254 by (simp add: ring_distribs power2_eq_square) |
45 |
255 |
46 |
256 |
47 subsection {* Predicate for negative binary numbers *} |
257 subsection {* Predicate for negative binary numbers *} |
48 |
258 |
49 definition neg :: "int \<Rightarrow> bool" where |
259 definition neg :: "int \<Rightarrow> bool" where |
312 lemmas numerals = nat_numeral_0_eq_0 nat_numeral_1_eq_1 numeral_2_eq_2 |
517 lemmas numerals = nat_numeral_0_eq_0 nat_numeral_1_eq_1 numeral_2_eq_2 |
313 |
518 |
314 |
519 |
315 subsection{*Powers with Numeric Exponents*} |
520 subsection{*Powers with Numeric Exponents*} |
316 |
521 |
317 text{*We cannot refer to the number @{term 2} in @{text Ring_and_Field.thy}. |
|
318 We cannot prove general results about the numeral @{term "-1"}, so we have to |
|
319 use @{term "- 1"} instead.*} |
|
320 |
|
321 lemma power2_eq_square: "(a::'a::recpower)\<twosuperior> = a * a" |
|
322 by (simp add: numeral_2_eq_2 Power.power_Suc) |
|
323 |
|
324 lemma zero_power2 [simp]: "(0::'a::{semiring_1,recpower})\<twosuperior> = 0" |
|
325 by (simp add: power2_eq_square) |
|
326 |
|
327 lemma one_power2 [simp]: "(1::'a::{semiring_1,recpower})\<twosuperior> = 1" |
|
328 by (simp add: power2_eq_square) |
|
329 |
|
330 lemma power3_eq_cube: "(x::'a::recpower) ^ 3 = x * x * x" |
|
331 apply (subgoal_tac "3 = Suc (Suc (Suc 0))") |
|
332 apply (erule ssubst) |
|
333 apply (simp add: power_Suc mult_ac) |
|
334 apply (unfold nat_number_of_def) |
|
335 apply (subst nat_eq_iff) |
|
336 apply simp |
|
337 done |
|
338 |
|
339 text{*Squares of literal numerals will be evaluated.*} |
522 text{*Squares of literal numerals will be evaluated.*} |
340 lemmas power2_eq_square_number_of = |
523 lemmas power2_eq_square_number_of [simp] = |
341 power2_eq_square [of "number_of w", standard] |
524 power2_eq_square [of "number_of w", standard] |
342 declare power2_eq_square_number_of [simp] |
525 |
343 |
|
344 |
|
345 lemma zero_le_power2[simp]: "0 \<le> (a\<twosuperior>::'a::{ordered_idom,recpower})" |
|
346 by (simp add: power2_eq_square) |
|
347 |
|
348 lemma zero_less_power2[simp]: |
|
349 "(0 < a\<twosuperior>) = (a \<noteq> (0::'a::{ordered_idom,recpower}))" |
|
350 by (force simp add: power2_eq_square zero_less_mult_iff linorder_neq_iff) |
|
351 |
|
352 lemma power2_less_0[simp]: |
|
353 fixes a :: "'a::{ordered_idom,recpower}" |
|
354 shows "~ (a\<twosuperior> < 0)" |
|
355 by (force simp add: power2_eq_square mult_less_0_iff) |
|
356 |
|
357 lemma zero_eq_power2[simp]: |
|
358 "(a\<twosuperior> = 0) = (a = (0::'a::{ordered_idom,recpower}))" |
|
359 by (force simp add: power2_eq_square mult_eq_0_iff) |
|
360 |
|
361 lemma abs_power2[simp]: |
|
362 "abs(a\<twosuperior>) = (a\<twosuperior>::'a::{ordered_idom,recpower})" |
|
363 by (simp add: power2_eq_square abs_mult abs_mult_self) |
|
364 |
|
365 lemma power2_abs[simp]: |
|
366 "(abs a)\<twosuperior> = (a\<twosuperior>::'a::{ordered_idom,recpower})" |
|
367 by (simp add: power2_eq_square abs_mult_self) |
|
368 |
|
369 lemma power2_minus[simp]: |
|
370 "(- a)\<twosuperior> = (a\<twosuperior>::'a::{comm_ring_1,recpower})" |
|
371 by (simp add: power2_eq_square) |
|
372 |
|
373 lemma power2_le_imp_le: |
|
374 fixes x y :: "'a::{ordered_semidom,recpower}" |
|
375 shows "\<lbrakk>x\<twosuperior> \<le> y\<twosuperior>; 0 \<le> y\<rbrakk> \<Longrightarrow> x \<le> y" |
|
376 unfolding numeral_2_eq_2 by (rule power_le_imp_le_base) |
|
377 |
|
378 lemma power2_less_imp_less: |
|
379 fixes x y :: "'a::{ordered_semidom,recpower}" |
|
380 shows "\<lbrakk>x\<twosuperior> < y\<twosuperior>; 0 \<le> y\<rbrakk> \<Longrightarrow> x < y" |
|
381 by (rule power_less_imp_less_base) |
|
382 |
|
383 lemma power2_eq_imp_eq: |
|
384 fixes x y :: "'a::{ordered_semidom,recpower}" |
|
385 shows "\<lbrakk>x\<twosuperior> = y\<twosuperior>; 0 \<le> x; 0 \<le> y\<rbrakk> \<Longrightarrow> x = y" |
|
386 unfolding numeral_2_eq_2 by (erule (2) power_eq_imp_eq_base, simp) |
|
387 |
|
388 lemma power_minus1_even[simp]: "(- 1) ^ (2*n) = (1::'a::{comm_ring_1,recpower})" |
|
389 proof (induct n) |
|
390 case 0 show ?case by simp |
|
391 next |
|
392 case (Suc n) then show ?case by (simp add: power_Suc power_add) |
|
393 qed |
|
394 |
|
395 lemma power_minus1_odd: "(- 1) ^ Suc(2*n) = -(1::'a::{comm_ring_1,recpower})" |
|
396 by (simp add: power_Suc) |
|
397 |
|
398 lemma power_even_eq: "(a::'a::recpower) ^ (2*n) = (a^n)^2" |
|
399 by (subst mult_commute) (simp add: power_mult) |
|
400 |
|
401 lemma power_odd_eq: "(a::int) ^ Suc(2*n) = a * (a^n)^2" |
|
402 by (simp add: power_even_eq) |
|
403 |
|
404 lemma power_minus_even [simp]: |
|
405 "(-a) ^ (2*n) = (a::'a::{comm_ring_1,recpower}) ^ (2*n)" |
|
406 by (simp add: power_minus [of a]) |
|
407 |
|
408 lemma zero_le_even_power'[simp]: |
|
409 "0 \<le> (a::'a::{ordered_idom,recpower}) ^ (2*n)" |
|
410 proof (induct "n") |
|
411 case 0 |
|
412 show ?case by (simp add: zero_le_one) |
|
413 next |
|
414 case (Suc n) |
|
415 have "a ^ (2 * Suc n) = (a*a) * a ^ (2*n)" |
|
416 by (simp add: mult_ac power_add power2_eq_square) |
|
417 thus ?case |
|
418 by (simp add: prems zero_le_mult_iff) |
|
419 qed |
|
420 |
|
421 lemma odd_power_less_zero: |
|
422 "(a::'a::{ordered_idom,recpower}) < 0 ==> a ^ Suc(2*n) < 0" |
|
423 proof (induct "n") |
|
424 case 0 |
|
425 then show ?case by simp |
|
426 next |
|
427 case (Suc n) |
|
428 have "a ^ Suc (2 * Suc n) = (a*a) * a ^ Suc(2*n)" |
|
429 by (simp add: mult_ac power_add power2_eq_square) |
|
430 thus ?case |
|
431 by (simp del: power_Suc add: prems mult_less_0_iff mult_neg_neg) |
|
432 qed |
|
433 |
|
434 lemma odd_0_le_power_imp_0_le: |
|
435 "0 \<le> a ^ Suc(2*n) ==> 0 \<le> (a::'a::{ordered_idom,recpower})" |
|
436 apply (insert odd_power_less_zero [of a n]) |
|
437 apply (force simp add: linorder_not_less [symmetric]) |
|
438 done |
|
439 |
526 |
440 text{*Simprules for comparisons where common factors can be cancelled.*} |
527 text{*Simprules for comparisons where common factors can be cancelled.*} |
441 lemmas zero_compare_simps = |
528 lemmas zero_compare_simps = |
442 add_strict_increasing add_strict_increasing2 add_increasing |
529 add_strict_increasing add_strict_increasing2 add_increasing |
443 zero_le_mult_iff zero_le_divide_iff |
530 zero_le_mult_iff zero_le_divide_iff |
619 |
706 |
620 |
707 |
621 text{*For arbitrary rings*} |
708 text{*For arbitrary rings*} |
622 |
709 |
623 lemma power_number_of_even: |
710 lemma power_number_of_even: |
624 fixes z :: "'a::{number_ring,recpower}" |
711 fixes z :: "'a::number_ring" |
625 shows "z ^ number_of (Int.Bit0 w) = (let w = z ^ (number_of w) in w * w)" |
712 shows "z ^ number_of (Int.Bit0 w) = (let w = z ^ (number_of w) in w * w)" |
626 unfolding Let_def nat_number_of_def number_of_Bit0 |
713 unfolding Let_def nat_number_of_def number_of_Bit0 |
627 apply (rule_tac x = "number_of w" in spec, clarify) |
714 apply (rule_tac x = "number_of w" in spec, clarify) |
628 apply (case_tac " (0::int) <= x") |
715 apply (case_tac " (0::int) <= x") |
629 apply (auto simp add: nat_mult_distrib power_even_eq power2_eq_square) |
716 apply (auto simp add: nat_mult_distrib power_even_eq power2_eq_square) |
630 done |
717 done |
631 |
718 |
632 lemma power_number_of_odd: |
719 lemma power_number_of_odd: |
633 fixes z :: "'a::{number_ring,recpower}" |
720 fixes z :: "'a::number_ring" |
634 shows "z ^ number_of (Int.Bit1 w) = (if (0::int) <= number_of w |
721 shows "z ^ number_of (Int.Bit1 w) = (if (0::int) <= number_of w |
635 then (let w = z ^ (number_of w) in z * w * w) else 1)" |
722 then (let w = z ^ (number_of w) in z * w * w) else 1)" |
636 unfolding Let_def nat_number_of_def number_of_Bit1 |
723 unfolding Let_def nat_number_of_def number_of_Bit1 |
637 apply (rule_tac x = "number_of w" in spec, auto) |
724 apply (rule_tac x = "number_of w" in spec, auto) |
638 apply (simp only: nat_add_distrib nat_mult_distrib) |
725 apply (simp only: nat_add_distrib nat_mult_distrib) |