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