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