author | haftmann |
Fri, 11 Jun 2010 17:14:02 +0200 | |
changeset 37407 | 61dd8c145da7 |
parent 36840 | 1e020f445846 |
child 41959 | b460124855b8 |
permissions | -rw-r--r-- |
21263 | 1 |
(* Title: HOL/Library/Parity.thy |
25600 | 2 |
Author: Jeremy Avigad, Jacques D. Fleuriot |
21256 | 3 |
*) |
4 |
||
5 |
header {* Even and Odd for int and nat *} |
|
6 |
||
7 |
theory Parity |
|
30738 | 8 |
imports Main |
21256 | 9 |
begin |
10 |
||
29608 | 11 |
class even_odd = |
22390 | 12 |
fixes even :: "'a \<Rightarrow> bool" |
21256 | 13 |
|
14 |
abbreviation |
|
22390 | 15 |
odd :: "'a\<Colon>even_odd \<Rightarrow> bool" where |
16 |
"odd x \<equiv> \<not> even x" |
|
17 |
||
26259 | 18 |
instantiation nat and int :: even_odd |
25571
c9e39eafc7a0
instantiation target rather than legacy instance
haftmann
parents:
25502
diff
changeset
|
19 |
begin |
c9e39eafc7a0
instantiation target rather than legacy instance
haftmann
parents:
25502
diff
changeset
|
20 |
|
c9e39eafc7a0
instantiation target rather than legacy instance
haftmann
parents:
25502
diff
changeset
|
21 |
definition |
c9e39eafc7a0
instantiation target rather than legacy instance
haftmann
parents:
25502
diff
changeset
|
22 |
even_def [presburger]: "even x \<longleftrightarrow> (x\<Colon>int) mod 2 = 0" |
22390 | 23 |
|
25571
c9e39eafc7a0
instantiation target rather than legacy instance
haftmann
parents:
25502
diff
changeset
|
24 |
definition |
c9e39eafc7a0
instantiation target rather than legacy instance
haftmann
parents:
25502
diff
changeset
|
25 |
even_nat_def [presburger]: "even x \<longleftrightarrow> even (int x)" |
c9e39eafc7a0
instantiation target rather than legacy instance
haftmann
parents:
25502
diff
changeset
|
26 |
|
c9e39eafc7a0
instantiation target rather than legacy instance
haftmann
parents:
25502
diff
changeset
|
27 |
instance .. |
c9e39eafc7a0
instantiation target rather than legacy instance
haftmann
parents:
25502
diff
changeset
|
28 |
|
c9e39eafc7a0
instantiation target rather than legacy instance
haftmann
parents:
25502
diff
changeset
|
29 |
end |
21256 | 30 |
|
33318
ddd97d9dfbfb
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
31718
diff
changeset
|
31 |
lemma transfer_int_nat_relations: |
ddd97d9dfbfb
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
31718
diff
changeset
|
32 |
"even (int x) \<longleftrightarrow> even x" |
ddd97d9dfbfb
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
31718
diff
changeset
|
33 |
by (simp add: even_nat_def) |
ddd97d9dfbfb
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
31718
diff
changeset
|
34 |
|
35644 | 35 |
declare transfer_morphism_int_nat[transfer add return: |
33318
ddd97d9dfbfb
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
31718
diff
changeset
|
36 |
transfer_int_nat_relations |
ddd97d9dfbfb
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
31718
diff
changeset
|
37 |
] |
21256 | 38 |
|
31148 | 39 |
lemma even_zero_int[simp]: "even (0::int)" by presburger |
40 |
||
41 |
lemma odd_one_int[simp]: "odd (1::int)" by presburger |
|
42 |
||
43 |
lemma even_zero_nat[simp]: "even (0::nat)" by presburger |
|
44 |
||
31718 | 45 |
lemma odd_1_nat [simp]: "odd (1::nat)" by presburger |
31148 | 46 |
|
47 |
declare even_def[of "number_of v", standard, simp] |
|
48 |
||
49 |
declare even_nat_def[of "number_of v", standard, simp] |
|
50 |
||
21256 | 51 |
subsection {* Even and odd are mutually exclusive *} |
52 |
||
21263 | 53 |
lemma int_pos_lt_two_imp_zero_or_one: |
21256 | 54 |
"0 <= x ==> (x::int) < 2 ==> x = 0 | x = 1" |
23522 | 55 |
by presburger |
21256 | 56 |
|
23522 | 57 |
lemma neq_one_mod_two [simp, presburger]: |
58 |
"((x::int) mod 2 ~= 0) = (x mod 2 = 1)" by presburger |
|
21256 | 59 |
|
25600 | 60 |
|
21256 | 61 |
subsection {* Behavior under integer arithmetic operations *} |
27668 | 62 |
declare dvd_def[algebra] |
63 |
lemma nat_even_iff_2_dvd[algebra]: "even (x::nat) \<longleftrightarrow> 2 dvd x" |
|
36840 | 64 |
by presburger |
27668 | 65 |
lemma int_even_iff_2_dvd[algebra]: "even (x::int) \<longleftrightarrow> 2 dvd x" |
66 |
by presburger |
|
21256 | 67 |
|
68 |
lemma even_times_anything: "even (x::int) ==> even (x * y)" |
|
27668 | 69 |
by algebra |
21256 | 70 |
|
27668 | 71 |
lemma anything_times_even: "even (y::int) ==> even (x * y)" by algebra |
21256 | 72 |
|
27668 | 73 |
lemma odd_times_odd: "odd (x::int) ==> odd y ==> odd (x * y)" |
21256 | 74 |
by (simp add: even_def zmod_zmult1_eq) |
75 |
||
31148 | 76 |
lemma even_product[simp,presburger]: "even((x::int) * y) = (even x | even y)" |
21263 | 77 |
apply (auto simp add: even_times_anything anything_times_even) |
21256 | 78 |
apply (rule ccontr) |
79 |
apply (auto simp add: odd_times_odd) |
|
80 |
done |
|
81 |
||
82 |
lemma even_plus_even: "even (x::int) ==> even y ==> even (x + y)" |
|
31148 | 83 |
by presburger |
21256 | 84 |
|
85 |
lemma even_plus_odd: "even (x::int) ==> odd y ==> odd (x + y)" |
|
31148 | 86 |
by presburger |
21256 | 87 |
|
88 |
lemma odd_plus_even: "odd (x::int) ==> even y ==> odd (x + y)" |
|
31148 | 89 |
by presburger |
21256 | 90 |
|
23522 | 91 |
lemma odd_plus_odd: "odd (x::int) ==> odd y ==> even (x + y)" by presburger |
21256 | 92 |
|
31148 | 93 |
lemma even_sum[simp,presburger]: |
94 |
"even ((x::int) + y) = ((even x & even y) | (odd x & odd y))" |
|
95 |
by presburger |
|
21256 | 96 |
|
31148 | 97 |
lemma even_neg[simp,presburger,algebra]: "even (-(x::int)) = even x" |
98 |
by presburger |
|
21256 | 99 |
|
31148 | 100 |
lemma even_difference[simp]: |
23522 | 101 |
"even ((x::int) - y) = ((even x & even y) | (odd x & odd y))" by presburger |
21256 | 102 |
|
31148 | 103 |
lemma even_power[simp,presburger]: "even ((x::int)^n) = (even x & n \<noteq> 0)" |
104 |
by (induct n) auto |
|
21256 | 105 |
|
31148 | 106 |
lemma odd_pow: "odd x ==> odd((x::int)^n)" by simp |
21256 | 107 |
|
108 |
||
109 |
subsection {* Equivalent definitions *} |
|
110 |
||
23522 | 111 |
lemma two_times_even_div_two: "even (x::int) ==> 2 * (x div 2) = x" |
31148 | 112 |
by presburger |
21256 | 113 |
|
31148 | 114 |
lemma two_times_odd_div_two_plus_one: |
115 |
"odd (x::int) ==> 2 * (x div 2) + 1 = x" |
|
116 |
by presburger |
|
21256 | 117 |
|
23522 | 118 |
lemma even_equiv_def: "even (x::int) = (EX y. x = 2 * y)" by presburger |
21256 | 119 |
|
23522 | 120 |
lemma odd_equiv_def: "odd (x::int) = (EX y. x = 2 * y + 1)" by presburger |
21256 | 121 |
|
122 |
subsection {* even and odd for nats *} |
|
123 |
||
124 |
lemma pos_int_even_equiv_nat_even: "0 \<le> x ==> even x = even (nat x)" |
|
31148 | 125 |
by (simp add: even_nat_def) |
21256 | 126 |
|
31148 | 127 |
lemma even_product_nat[simp,presburger,algebra]: |
128 |
"even((x::nat) * y) = (even x | even y)" |
|
129 |
by (simp add: even_nat_def int_mult) |
|
21256 | 130 |
|
31148 | 131 |
lemma even_sum_nat[simp,presburger,algebra]: |
132 |
"even ((x::nat) + y) = ((even x & even y) | (odd x & odd y))" |
|
23522 | 133 |
by presburger |
21256 | 134 |
|
31148 | 135 |
lemma even_difference_nat[simp,presburger,algebra]: |
136 |
"even ((x::nat) - y) = (x < y | (even x & even y) | (odd x & odd y))" |
|
137 |
by presburger |
|
21256 | 138 |
|
31148 | 139 |
lemma even_Suc[simp,presburger,algebra]: "even (Suc x) = odd x" |
140 |
by presburger |
|
21256 | 141 |
|
31148 | 142 |
lemma even_power_nat[simp,presburger,algebra]: |
143 |
"even ((x::nat)^y) = (even x & 0 < y)" |
|
144 |
by (simp add: even_nat_def int_power) |
|
21256 | 145 |
|
146 |
||
147 |
subsection {* Equivalent definitions *} |
|
148 |
||
31148 | 149 |
lemma nat_lt_two_imp_zero_or_one: |
150 |
"(x::nat) < Suc (Suc 0) ==> x = 0 | x = Suc 0" |
|
151 |
by presburger |
|
21256 | 152 |
|
153 |
lemma even_nat_mod_two_eq_zero: "even (x::nat) ==> x mod (Suc (Suc 0)) = 0" |
|
31148 | 154 |
by presburger |
21256 | 155 |
|
156 |
lemma odd_nat_mod_two_eq_one: "odd (x::nat) ==> x mod (Suc (Suc 0)) = Suc 0" |
|
23522 | 157 |
by presburger |
21256 | 158 |
|
21263 | 159 |
lemma even_nat_equiv_def: "even (x::nat) = (x mod Suc (Suc 0) = 0)" |
31148 | 160 |
by presburger |
21256 | 161 |
|
162 |
lemma odd_nat_equiv_def: "odd (x::nat) = (x mod Suc (Suc 0) = Suc 0)" |
|
31148 | 163 |
by presburger |
21256 | 164 |
|
21263 | 165 |
lemma even_nat_div_two_times_two: "even (x::nat) ==> |
23522 | 166 |
Suc (Suc 0) * (x div Suc (Suc 0)) = x" by presburger |
21256 | 167 |
|
21263 | 168 |
lemma odd_nat_div_two_times_two_plus_one: "odd (x::nat) ==> |
23522 | 169 |
Suc( Suc (Suc 0) * (x div Suc (Suc 0))) = x" by presburger |
21256 | 170 |
|
171 |
lemma even_nat_equiv_def2: "even (x::nat) = (EX y. x = Suc (Suc 0) * y)" |
|
31148 | 172 |
by presburger |
21256 | 173 |
|
174 |
lemma odd_nat_equiv_def2: "odd (x::nat) = (EX y. x = Suc(Suc (Suc 0) * y))" |
|
31148 | 175 |
by presburger |
21256 | 176 |
|
25600 | 177 |
|
21256 | 178 |
subsection {* Parity and powers *} |
179 |
||
21263 | 180 |
lemma minus_one_even_odd_power: |
31017 | 181 |
"(even x --> (- 1::'a::{comm_ring_1})^x = 1) & |
21256 | 182 |
(odd x --> (- 1::'a)^x = - 1)" |
183 |
apply (induct x) |
|
184 |
apply (rule conjI) |
|
185 |
apply simp |
|
31148 | 186 |
apply (insert even_zero_nat, blast) |
35216 | 187 |
apply simp |
21263 | 188 |
done |
21256 | 189 |
|
190 |
lemma minus_one_even_power [simp]: |
|
31017 | 191 |
"even x ==> (- 1::'a::{comm_ring_1})^x = 1" |
21263 | 192 |
using minus_one_even_odd_power by blast |
21256 | 193 |
|
194 |
lemma minus_one_odd_power [simp]: |
|
31017 | 195 |
"odd x ==> (- 1::'a::{comm_ring_1})^x = - 1" |
21263 | 196 |
using minus_one_even_odd_power by blast |
21256 | 197 |
|
198 |
lemma neg_one_even_odd_power: |
|
31017 | 199 |
"(even x --> (-1::'a::{number_ring})^x = 1) & |
21256 | 200 |
(odd x --> (-1::'a)^x = -1)" |
201 |
apply (induct x) |
|
35216 | 202 |
apply (simp, simp) |
21256 | 203 |
done |
204 |
||
205 |
lemma neg_one_even_power [simp]: |
|
31017 | 206 |
"even x ==> (-1::'a::{number_ring})^x = 1" |
21263 | 207 |
using neg_one_even_odd_power by blast |
21256 | 208 |
|
209 |
lemma neg_one_odd_power [simp]: |
|
31017 | 210 |
"odd x ==> (-1::'a::{number_ring})^x = -1" |
21263 | 211 |
using neg_one_even_odd_power by blast |
21256 | 212 |
|
213 |
lemma neg_power_if: |
|
31017 | 214 |
"(-x::'a::{comm_ring_1}) ^ n = |
21256 | 215 |
(if even n then (x ^ n) else -(x ^ n))" |
21263 | 216 |
apply (induct n) |
35216 | 217 |
apply simp_all |
21263 | 218 |
done |
21256 | 219 |
|
21263 | 220 |
lemma zero_le_even_power: "even n ==> |
35631
0b8a5fd339ab
generalize some lemmas from class linordered_ring_strict to linordered_ring
huffman
parents:
35216
diff
changeset
|
221 |
0 <= (x::'a::{linordered_ring,monoid_mult}) ^ n" |
21256 | 222 |
apply (simp add: even_nat_equiv_def2) |
223 |
apply (erule exE) |
|
224 |
apply (erule ssubst) |
|
225 |
apply (subst power_add) |
|
226 |
apply (rule zero_le_square) |
|
227 |
done |
|
228 |
||
21263 | 229 |
lemma zero_le_odd_power: "odd n ==> |
35028
108662d50512
more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
haftmann
parents:
33358
diff
changeset
|
230 |
(0 <= (x::'a::{linordered_idom}) ^ n) = (0 <= x)" |
35216 | 231 |
apply (auto simp: odd_nat_equiv_def2 power_add zero_le_mult_iff) |
36722 | 232 |
apply (metis field_power_not_zero divisors_zero order_antisym_conv zero_le_square) |
30056 | 233 |
done |
21256 | 234 |
|
35028
108662d50512
more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
haftmann
parents:
33358
diff
changeset
|
235 |
lemma zero_le_power_eq[presburger]: "(0 <= (x::'a::{linordered_idom}) ^ n) = |
21256 | 236 |
(even n | (odd n & 0 <= x))" |
237 |
apply auto |
|
21263 | 238 |
apply (subst zero_le_odd_power [symmetric]) |
21256 | 239 |
apply assumption+ |
240 |
apply (erule zero_le_even_power) |
|
21263 | 241 |
done |
21256 | 242 |
|
35028
108662d50512
more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
haftmann
parents:
33358
diff
changeset
|
243 |
lemma zero_less_power_eq[presburger]: "(0 < (x::'a::{linordered_idom}) ^ n) = |
21256 | 244 |
(n = 0 | (even n & x ~= 0) | (odd n & 0 < x))" |
27668 | 245 |
|
246 |
unfolding order_less_le zero_le_power_eq by auto |
|
21256 | 247 |
|
35028
108662d50512
more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
haftmann
parents:
33358
diff
changeset
|
248 |
lemma power_less_zero_eq[presburger]: "((x::'a::{linordered_idom}) ^ n < 0) = |
27668 | 249 |
(odd n & x < 0)" |
21263 | 250 |
apply (subst linorder_not_le [symmetric])+ |
21256 | 251 |
apply (subst zero_le_power_eq) |
252 |
apply auto |
|
21263 | 253 |
done |
21256 | 254 |
|
35028
108662d50512
more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
haftmann
parents:
33358
diff
changeset
|
255 |
lemma power_le_zero_eq[presburger]: "((x::'a::{linordered_idom}) ^ n <= 0) = |
21256 | 256 |
(n ~= 0 & ((odd n & x <= 0) | (even n & x = 0)))" |
21263 | 257 |
apply (subst linorder_not_less [symmetric])+ |
21256 | 258 |
apply (subst zero_less_power_eq) |
259 |
apply auto |
|
21263 | 260 |
done |
21256 | 261 |
|
21263 | 262 |
lemma power_even_abs: "even n ==> |
35028
108662d50512
more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
haftmann
parents:
33358
diff
changeset
|
263 |
(abs (x::'a::{linordered_idom}))^n = x^n" |
21263 | 264 |
apply (subst power_abs [symmetric]) |
21256 | 265 |
apply (simp add: zero_le_even_power) |
21263 | 266 |
done |
21256 | 267 |
|
23522 | 268 |
lemma zero_less_power_nat_eq[presburger]: "(0 < (x::nat) ^ n) = (n = 0 | 0 < x)" |
21263 | 269 |
by (induct n) auto |
21256 | 270 |
|
21263 | 271 |
lemma power_minus_even [simp]: "even n ==> |
31017 | 272 |
(- x)^n = (x^n::'a::{comm_ring_1})" |
21256 | 273 |
apply (subst power_minus) |
274 |
apply simp |
|
21263 | 275 |
done |
21256 | 276 |
|
21263 | 277 |
lemma power_minus_odd [simp]: "odd n ==> |
31017 | 278 |
(- x)^n = - (x^n::'a::{comm_ring_1})" |
21256 | 279 |
apply (subst power_minus) |
280 |
apply simp |
|
21263 | 281 |
done |
21256 | 282 |
|
35028
108662d50512
more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
haftmann
parents:
33358
diff
changeset
|
283 |
lemma power_mono_even: fixes x y :: "'a :: {linordered_idom}" |
29803
c56a5571f60a
Added derivation lemmas for power series and theorems for the pi, arcus tangens and logarithm series
hoelzl
parents:
29654
diff
changeset
|
284 |
assumes "even n" and "\<bar>x\<bar> \<le> \<bar>y\<bar>" |
c56a5571f60a
Added derivation lemmas for power series and theorems for the pi, arcus tangens and logarithm series
hoelzl
parents:
29654
diff
changeset
|
285 |
shows "x^n \<le> y^n" |
c56a5571f60a
Added derivation lemmas for power series and theorems for the pi, arcus tangens and logarithm series
hoelzl
parents:
29654
diff
changeset
|
286 |
proof - |
c56a5571f60a
Added derivation lemmas for power series and theorems for the pi, arcus tangens and logarithm series
hoelzl
parents:
29654
diff
changeset
|
287 |
have "0 \<le> \<bar>x\<bar>" by auto |
c56a5571f60a
Added derivation lemmas for power series and theorems for the pi, arcus tangens and logarithm series
hoelzl
parents:
29654
diff
changeset
|
288 |
with `\<bar>x\<bar> \<le> \<bar>y\<bar>` |
c56a5571f60a
Added derivation lemmas for power series and theorems for the pi, arcus tangens and logarithm series
hoelzl
parents:
29654
diff
changeset
|
289 |
have "\<bar>x\<bar>^n \<le> \<bar>y\<bar>^n" by (rule power_mono) |
c56a5571f60a
Added derivation lemmas for power series and theorems for the pi, arcus tangens and logarithm series
hoelzl
parents:
29654
diff
changeset
|
290 |
thus ?thesis unfolding power_even_abs[OF `even n`] . |
c56a5571f60a
Added derivation lemmas for power series and theorems for the pi, arcus tangens and logarithm series
hoelzl
parents:
29654
diff
changeset
|
291 |
qed |
c56a5571f60a
Added derivation lemmas for power series and theorems for the pi, arcus tangens and logarithm series
hoelzl
parents:
29654
diff
changeset
|
292 |
|
c56a5571f60a
Added derivation lemmas for power series and theorems for the pi, arcus tangens and logarithm series
hoelzl
parents:
29654
diff
changeset
|
293 |
lemma odd_pos: "odd (n::nat) \<Longrightarrow> 0 < n" by presburger |
c56a5571f60a
Added derivation lemmas for power series and theorems for the pi, arcus tangens and logarithm series
hoelzl
parents:
29654
diff
changeset
|
294 |
|
35028
108662d50512
more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
haftmann
parents:
33358
diff
changeset
|
295 |
lemma power_mono_odd: fixes x y :: "'a :: {linordered_idom}" |
29803
c56a5571f60a
Added derivation lemmas for power series and theorems for the pi, arcus tangens and logarithm series
hoelzl
parents:
29654
diff
changeset
|
296 |
assumes "odd n" and "x \<le> y" |
c56a5571f60a
Added derivation lemmas for power series and theorems for the pi, arcus tangens and logarithm series
hoelzl
parents:
29654
diff
changeset
|
297 |
shows "x^n \<le> y^n" |
c56a5571f60a
Added derivation lemmas for power series and theorems for the pi, arcus tangens and logarithm series
hoelzl
parents:
29654
diff
changeset
|
298 |
proof (cases "y < 0") |
c56a5571f60a
Added derivation lemmas for power series and theorems for the pi, arcus tangens and logarithm series
hoelzl
parents:
29654
diff
changeset
|
299 |
case True with `x \<le> y` have "-y \<le> -x" and "0 \<le> -y" by auto |
c56a5571f60a
Added derivation lemmas for power series and theorems for the pi, arcus tangens and logarithm series
hoelzl
parents:
29654
diff
changeset
|
300 |
hence "(-y)^n \<le> (-x)^n" by (rule power_mono) |
c56a5571f60a
Added derivation lemmas for power series and theorems for the pi, arcus tangens and logarithm series
hoelzl
parents:
29654
diff
changeset
|
301 |
thus ?thesis unfolding power_minus_odd[OF `odd n`] by auto |
c56a5571f60a
Added derivation lemmas for power series and theorems for the pi, arcus tangens and logarithm series
hoelzl
parents:
29654
diff
changeset
|
302 |
next |
c56a5571f60a
Added derivation lemmas for power series and theorems for the pi, arcus tangens and logarithm series
hoelzl
parents:
29654
diff
changeset
|
303 |
case False |
c56a5571f60a
Added derivation lemmas for power series and theorems for the pi, arcus tangens and logarithm series
hoelzl
parents:
29654
diff
changeset
|
304 |
show ?thesis |
c56a5571f60a
Added derivation lemmas for power series and theorems for the pi, arcus tangens and logarithm series
hoelzl
parents:
29654
diff
changeset
|
305 |
proof (cases "x < 0") |
c56a5571f60a
Added derivation lemmas for power series and theorems for the pi, arcus tangens and logarithm series
hoelzl
parents:
29654
diff
changeset
|
306 |
case True hence "n \<noteq> 0" and "x \<le> 0" using `odd n`[THEN odd_pos] by auto |
c56a5571f60a
Added derivation lemmas for power series and theorems for the pi, arcus tangens and logarithm series
hoelzl
parents:
29654
diff
changeset
|
307 |
hence "x^n \<le> 0" unfolding power_le_zero_eq using `odd n` by auto |
c56a5571f60a
Added derivation lemmas for power series and theorems for the pi, arcus tangens and logarithm series
hoelzl
parents:
29654
diff
changeset
|
308 |
moreover |
c56a5571f60a
Added derivation lemmas for power series and theorems for the pi, arcus tangens and logarithm series
hoelzl
parents:
29654
diff
changeset
|
309 |
from `\<not> y < 0` have "0 \<le> y" by auto |
c56a5571f60a
Added derivation lemmas for power series and theorems for the pi, arcus tangens and logarithm series
hoelzl
parents:
29654
diff
changeset
|
310 |
hence "0 \<le> y^n" by auto |
c56a5571f60a
Added derivation lemmas for power series and theorems for the pi, arcus tangens and logarithm series
hoelzl
parents:
29654
diff
changeset
|
311 |
ultimately show ?thesis by auto |
c56a5571f60a
Added derivation lemmas for power series and theorems for the pi, arcus tangens and logarithm series
hoelzl
parents:
29654
diff
changeset
|
312 |
next |
c56a5571f60a
Added derivation lemmas for power series and theorems for the pi, arcus tangens and logarithm series
hoelzl
parents:
29654
diff
changeset
|
313 |
case False hence "0 \<le> x" by auto |
c56a5571f60a
Added derivation lemmas for power series and theorems for the pi, arcus tangens and logarithm series
hoelzl
parents:
29654
diff
changeset
|
314 |
with `x \<le> y` show ?thesis using power_mono by auto |
c56a5571f60a
Added derivation lemmas for power series and theorems for the pi, arcus tangens and logarithm series
hoelzl
parents:
29654
diff
changeset
|
315 |
qed |
c56a5571f60a
Added derivation lemmas for power series and theorems for the pi, arcus tangens and logarithm series
hoelzl
parents:
29654
diff
changeset
|
316 |
qed |
21263 | 317 |
|
25600 | 318 |
|
319 |
subsection {* More Even/Odd Results *} |
|
320 |
||
27668 | 321 |
lemma even_mult_two_ex: "even(n) = (\<exists>m::nat. n = 2*m)" by presburger |
322 |
lemma odd_Suc_mult_two_ex: "odd(n) = (\<exists>m. n = Suc (2*m))" by presburger |
|
323 |
lemma even_add [simp]: "even(m + n::nat) = (even m = even n)" by presburger |
|
25600 | 324 |
|
27668 | 325 |
lemma odd_add [simp]: "odd(m + n::nat) = (odd m \<noteq> odd n)" by presburger |
25600 | 326 |
|
327 |
lemma div_Suc: "Suc a div c = a div c + Suc 0 div c + |
|
328 |
(a mod c + Suc 0 mod c) div c" |
|
329 |
apply (subgoal_tac "Suc a = a + Suc 0") |
|
330 |
apply (erule ssubst) |
|
331 |
apply (rule div_add1_eq, simp) |
|
332 |
done |
|
333 |
||
27668 | 334 |
lemma lemma_even_div2 [simp]: "even (n::nat) ==> (n + 1) div 2 = n div 2" by presburger |
25600 | 335 |
|
336 |
lemma lemma_not_even_div2 [simp]: "~even n ==> (n + 1) div 2 = Suc (n div 2)" |
|
27668 | 337 |
by presburger |
25600 | 338 |
|
27668 | 339 |
lemma even_num_iff: "0 < n ==> even n = (~ even(n - 1 :: nat))" by presburger |
340 |
lemma even_even_mod_4_iff: "even (n::nat) = even (n mod 4)" by presburger |
|
25600 | 341 |
|
27668 | 342 |
lemma lemma_odd_mod_4_div_2: "n mod 4 = (3::nat) ==> odd((n - 1) div 2)" by presburger |
25600 | 343 |
|
344 |
lemma lemma_even_mod_4_div_2: "n mod 4 = (1::nat) ==> even ((n - 1) div 2)" |
|
27668 | 345 |
by presburger |
25600 | 346 |
|
21263 | 347 |
text {* Simplify, when the exponent is a numeral *} |
21256 | 348 |
|
349 |
lemmas power_0_left_number_of = power_0_left [of "number_of w", standard] |
|
350 |
declare power_0_left_number_of [simp] |
|
351 |
||
21263 | 352 |
lemmas zero_le_power_eq_number_of [simp] = |
21256 | 353 |
zero_le_power_eq [of _ "number_of w", standard] |
354 |
||
21263 | 355 |
lemmas zero_less_power_eq_number_of [simp] = |
21256 | 356 |
zero_less_power_eq [of _ "number_of w", standard] |
357 |
||
21263 | 358 |
lemmas power_le_zero_eq_number_of [simp] = |
21256 | 359 |
power_le_zero_eq [of _ "number_of w", standard] |
360 |
||
21263 | 361 |
lemmas power_less_zero_eq_number_of [simp] = |
21256 | 362 |
power_less_zero_eq [of _ "number_of w", standard] |
363 |
||
21263 | 364 |
lemmas zero_less_power_nat_eq_number_of [simp] = |
21256 | 365 |
zero_less_power_nat_eq [of _ "number_of w", standard] |
366 |
||
21263 | 367 |
lemmas power_eq_0_iff_number_of [simp] = power_eq_0_iff [of _ "number_of w", standard] |
21256 | 368 |
|
21263 | 369 |
lemmas power_even_abs_number_of [simp] = power_even_abs [of "number_of w" _, standard] |
21256 | 370 |
|
371 |
||
372 |
subsection {* An Equivalence for @{term [source] "0 \<le> a^n"} *} |
|
373 |
||
374 |
lemma even_power_le_0_imp_0: |
|
35028
108662d50512
more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
haftmann
parents:
33358
diff
changeset
|
375 |
"a ^ (2*k) \<le> (0::'a::{linordered_idom}) ==> a=0" |
35216 | 376 |
by (induct k) (auto simp add: zero_le_mult_iff mult_le_0_iff) |
21256 | 377 |
|
23522 | 378 |
lemma zero_le_power_iff[presburger]: |
35028
108662d50512
more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
haftmann
parents:
33358
diff
changeset
|
379 |
"(0 \<le> a^n) = (0 \<le> (a::'a::{linordered_idom}) | even n)" |
21256 | 380 |
proof cases |
381 |
assume even: "even n" |
|
382 |
then obtain k where "n = 2*k" |
|
383 |
by (auto simp add: even_nat_equiv_def2 numeral_2_eq_2) |
|
21263 | 384 |
thus ?thesis by (simp add: zero_le_even_power even) |
21256 | 385 |
next |
386 |
assume odd: "odd n" |
|
387 |
then obtain k where "n = Suc(2*k)" |
|
388 |
by (auto simp add: odd_nat_equiv_def2 numeral_2_eq_2) |
|
389 |
thus ?thesis |
|
35216 | 390 |
by (auto simp add: zero_le_mult_iff zero_le_even_power |
21263 | 391 |
dest!: even_power_le_0_imp_0) |
392 |
qed |
|
393 |
||
21256 | 394 |
|
395 |
subsection {* Miscellaneous *} |
|
396 |
||
23522 | 397 |
lemma [presburger]:"(x + 1) div 2 = x div 2 \<longleftrightarrow> even (x::int)" by presburger |
398 |
lemma [presburger]: "(x + 1) div 2 = x div 2 + 1 \<longleftrightarrow> odd (x::int)" by presburger |
|
399 |
lemma even_plus_one_div_two: "even (x::int) ==> (x + 1) div 2 = x div 2" by presburger |
|
400 |
lemma odd_plus_one_div_two: "odd (x::int) ==> (x + 1) div 2 = x div 2 + 1" by presburger |
|
21256 | 401 |
|
23522 | 402 |
lemma [presburger]: "(Suc x) div Suc (Suc 0) = x div Suc (Suc 0) \<longleftrightarrow> even x" by presburger |
403 |
lemma [presburger]: "(Suc x) div Suc (Suc 0) = x div Suc (Suc 0) \<longleftrightarrow> even x" by presburger |
|
21263 | 404 |
lemma even_nat_plus_one_div_two: "even (x::nat) ==> |
23522 | 405 |
(Suc x) div Suc (Suc 0) = x div Suc (Suc 0)" by presburger |
21256 | 406 |
|
21263 | 407 |
lemma odd_nat_plus_one_div_two: "odd (x::nat) ==> |
23522 | 408 |
(Suc x) div Suc (Suc 0) = Suc (x div Suc (Suc 0))" by presburger |
21256 | 409 |
|
410 |
end |