src/HOL/Integ/Parity.thy
author wenzelm
Sun Apr 09 18:51:13 2006 +0200 (2006-04-09)
changeset 19380 b808efaa5828
parent 18648 22f96cd085d5
permissions -rw-r--r--
tuned syntax/abbreviations;
paulson@14430
     1
(*  Title:      Parity.thy
paulson@14450
     2
    ID:         $Id$
paulson@14430
     3
    Author:     Jeremy Avigad
paulson@14430
     4
*)
paulson@14430
     5
wenzelm@17472
     6
header {* Even and Odd for ints and nats*}
paulson@14430
     7
nipkow@15131
     8
theory Parity
nipkow@15140
     9
imports Divides IntDiv NatSimprocs
nipkow@15131
    10
begin
paulson@14430
    11
paulson@14430
    12
axclass even_odd < type
paulson@14430
    13
paulson@14430
    14
consts
paulson@14430
    15
  even :: "'a::even_odd => bool"
paulson@14430
    16
wenzelm@19380
    17
instance int :: even_odd ..
wenzelm@19380
    18
instance nat :: even_odd ..
paulson@14430
    19
paulson@14430
    20
defs (overloaded)
paulson@14430
    21
  even_def: "even (x::int) == x mod 2 = 0"
paulson@14430
    22
  even_nat_def: "even (x::nat) == even (int x)"
paulson@14430
    23
wenzelm@19380
    24
abbreviation
wenzelm@19380
    25
  odd :: "'a::even_odd => bool"
wenzelm@19380
    26
  "odd x == \<not> even x"
wenzelm@19380
    27
paulson@14430
    28
paulson@14430
    29
subsection {* Even and odd are mutually exclusive *}
paulson@14430
    30
paulson@14430
    31
lemma int_pos_lt_two_imp_zero_or_one: 
paulson@14430
    32
    "0 <= x ==> (x::int) < 2 ==> x = 0 | x = 1"
paulson@14430
    33
  by auto
paulson@14430
    34
paulson@14430
    35
lemma neq_one_mod_two [simp]: "((x::int) mod 2 ~= 0) = (x mod 2 = 1)"
paulson@14430
    36
  apply (subgoal_tac "x mod 2 = 0 | x mod 2 = 1", force)
paulson@14430
    37
  apply (rule int_pos_lt_two_imp_zero_or_one, auto)
paulson@14430
    38
  done
paulson@14430
    39
paulson@14430
    40
subsection {* Behavior under integer arithmetic operations *}
paulson@14430
    41
paulson@14430
    42
lemma even_times_anything: "even (x::int) ==> even (x * y)"
paulson@14430
    43
  by (simp add: even_def zmod_zmult1_eq')
paulson@14430
    44
paulson@14430
    45
lemma anything_times_even: "even (y::int) ==> even (x * y)"
paulson@14430
    46
  by (simp add: even_def zmod_zmult1_eq)
paulson@14430
    47
paulson@14430
    48
lemma odd_times_odd: "odd (x::int) ==> odd y ==> odd (x * y)"
paulson@14430
    49
  by (simp add: even_def zmod_zmult1_eq)
paulson@14430
    50
paulson@14430
    51
lemma even_product: "even((x::int) * y) = (even x | even y)"
paulson@14430
    52
  apply (auto simp add: even_times_anything anything_times_even) 
paulson@14430
    53
  apply (rule ccontr)
paulson@14430
    54
  apply (auto simp add: odd_times_odd)
paulson@14430
    55
  done
paulson@14430
    56
paulson@14430
    57
lemma even_plus_even: "even (x::int) ==> even y ==> even (x + y)"
paulson@14430
    58
  by (simp add: even_def zmod_zadd1_eq)
paulson@14430
    59
paulson@14430
    60
lemma even_plus_odd: "even (x::int) ==> odd y ==> odd (x + y)"
paulson@14430
    61
  by (simp add: even_def zmod_zadd1_eq)
paulson@14430
    62
paulson@14430
    63
lemma odd_plus_even: "odd (x::int) ==> even y ==> odd (x + y)"
paulson@14430
    64
  by (simp add: even_def zmod_zadd1_eq)
paulson@14430
    65
paulson@14430
    66
lemma odd_plus_odd: "odd (x::int) ==> odd y ==> even (x + y)"
paulson@14430
    67
  by (simp add: even_def zmod_zadd1_eq)
paulson@14430
    68
paulson@14430
    69
lemma even_sum: "even ((x::int) + y) = ((even x & even y) | (odd x & odd y))"
paulson@14430
    70
  apply (auto intro: even_plus_even odd_plus_odd)
paulson@14430
    71
  apply (rule ccontr, simp add: even_plus_odd)
paulson@14430
    72
  apply (rule ccontr, simp add: odd_plus_even)
paulson@14430
    73
  done
paulson@14430
    74
paulson@14430
    75
lemma even_neg: "even (-(x::int)) = even x"
paulson@14430
    76
  by (auto simp add: even_def zmod_zminus1_eq_if)
paulson@14430
    77
paulson@14430
    78
lemma even_difference: 
paulson@14430
    79
  "even ((x::int) - y) = ((even x & even y) | (odd x & odd y))"
paulson@14430
    80
  by (simp only: diff_minus even_sum even_neg)
paulson@14430
    81
paulson@14430
    82
lemma even_pow_gt_zero [rule_format]: 
paulson@14430
    83
    "even (x::int) ==> 0 < n --> even (x^n)"
paulson@15251
    84
  apply (induct n)
paulson@14430
    85
  apply (auto simp add: even_product)
paulson@14430
    86
  done
paulson@14430
    87
paulson@14430
    88
lemma odd_pow: "odd x ==> odd((x::int)^n)"
paulson@15251
    89
  apply (induct n)
paulson@14430
    90
  apply (simp add: even_def)
paulson@14430
    91
  apply (simp add: even_product)
paulson@14430
    92
  done
paulson@14430
    93
paulson@14430
    94
lemma even_power: "even ((x::int)^n) = (even x & 0 < n)"
paulson@14430
    95
  apply (auto simp add: even_pow_gt_zero) 
paulson@14430
    96
  apply (erule contrapos_pp, erule odd_pow)
paulson@14430
    97
  apply (erule contrapos_pp, simp add: even_def)
paulson@14430
    98
  done
paulson@14430
    99
paulson@14430
   100
lemma even_zero: "even (0::int)"
paulson@14430
   101
  by (simp add: even_def)
paulson@14430
   102
paulson@14430
   103
lemma odd_one: "odd (1::int)"
paulson@14430
   104
  by (simp add: even_def)
paulson@14430
   105
paulson@14430
   106
lemmas even_odd_simps [simp] = even_def[of "number_of v",standard] even_zero 
paulson@14430
   107
  odd_one even_product even_sum even_neg even_difference even_power
paulson@14430
   108
paulson@14430
   109
paulson@14430
   110
subsection {* Equivalent definitions *}
paulson@14430
   111
paulson@14430
   112
lemma two_times_even_div_two: "even (x::int) ==> 2 * (x div 2) = x" 
paulson@14430
   113
  by (auto simp add: even_def)
paulson@14430
   114
paulson@14430
   115
lemma two_times_odd_div_two_plus_one: "odd (x::int) ==> 
paulson@14430
   116
    2 * (x div 2) + 1 = x"
paulson@14430
   117
  apply (insert zmod_zdiv_equality [of x 2, THEN sym])
paulson@14430
   118
  by (simp add: even_def)
paulson@14430
   119
paulson@14430
   120
lemma even_equiv_def: "even (x::int) = (EX y. x = 2 * y)"
paulson@14430
   121
  apply auto
paulson@14430
   122
  apply (rule exI)
paulson@14430
   123
  by (erule two_times_even_div_two [THEN sym])
paulson@14430
   124
paulson@14430
   125
lemma odd_equiv_def: "odd (x::int) = (EX y. x = 2 * y + 1)"
paulson@14430
   126
  apply auto
paulson@14430
   127
  apply (rule exI)
paulson@14430
   128
  by (erule two_times_odd_div_two_plus_one [THEN sym])
paulson@14430
   129
paulson@14430
   130
paulson@14430
   131
subsection {* even and odd for nats *}
paulson@14430
   132
paulson@14430
   133
lemma pos_int_even_equiv_nat_even: "0 \<le> x ==> even x = even (nat x)"
paulson@14430
   134
  by (simp add: even_nat_def)
paulson@14430
   135
paulson@14430
   136
lemma even_nat_product: "even((x::nat) * y) = (even x | even y)"
paulson@16413
   137
  by (simp add: even_nat_def int_mult)
paulson@14430
   138
paulson@14430
   139
lemma even_nat_sum: "even ((x::nat) + y) = 
paulson@14430
   140
    ((even x & even y) | (odd x & odd y))"
paulson@14430
   141
  by (unfold even_nat_def, simp)
paulson@14430
   142
paulson@14430
   143
lemma even_nat_difference: 
paulson@14430
   144
    "even ((x::nat) - y) = (x < y | (even x & even y) | (odd x & odd y))"
paulson@14430
   145
  apply (auto simp add: even_nat_def zdiff_int [THEN sym])
paulson@14430
   146
  apply (case_tac "x < y", auto simp add: zdiff_int [THEN sym])
paulson@14430
   147
  apply (case_tac "x < y", auto simp add: zdiff_int [THEN sym])
paulson@14430
   148
  done
paulson@14430
   149
paulson@14436
   150
lemma even_nat_Suc: "even (Suc x) = odd x"
paulson@14430
   151
  by (simp add: even_nat_def)
paulson@14430
   152
paulson@14430
   153
lemma even_nat_power: "even ((x::nat)^y) = (even x & 0 < y)"
paulson@16413
   154
  by (simp add: even_nat_def int_power)
paulson@14430
   155
paulson@14430
   156
lemma even_nat_zero: "even (0::nat)"
paulson@14430
   157
  by (simp add: even_nat_def)
paulson@14430
   158
paulson@14430
   159
lemmas even_odd_nat_simps [simp] = even_nat_def[of "number_of v",standard] 
paulson@14436
   160
  even_nat_zero even_nat_Suc even_nat_product even_nat_sum even_nat_power
paulson@14430
   161
paulson@14430
   162
paulson@14430
   163
subsection {* Equivalent definitions *}
paulson@14430
   164
paulson@14430
   165
lemma nat_lt_two_imp_zero_or_one: "(x::nat) < Suc (Suc 0) ==> 
paulson@14430
   166
    x = 0 | x = Suc 0"
paulson@14430
   167
  by auto
paulson@14430
   168
paulson@14430
   169
lemma even_nat_mod_two_eq_zero: "even (x::nat) ==> x mod (Suc (Suc 0)) = 0"
paulson@14430
   170
  apply (insert mod_div_equality [of x "Suc (Suc 0)", THEN sym])
paulson@14430
   171
  apply (drule subst, assumption)
paulson@14430
   172
  apply (subgoal_tac "x mod Suc (Suc 0) = 0 | x mod Suc (Suc 0) = Suc 0")
paulson@14430
   173
  apply force
paulson@14430
   174
  apply (subgoal_tac "0 < Suc (Suc 0)")
paulson@14430
   175
  apply (frule mod_less_divisor [of "Suc (Suc 0)" x])
paulson@14430
   176
  apply (erule nat_lt_two_imp_zero_or_one, auto)
paulson@14430
   177
  done
paulson@14430
   178
paulson@14430
   179
lemma odd_nat_mod_two_eq_one: "odd (x::nat) ==> x mod (Suc (Suc 0)) = Suc 0"
paulson@14430
   180
  apply (insert mod_div_equality [of x "Suc (Suc 0)", THEN sym])
paulson@14430
   181
  apply (drule subst, assumption)
paulson@14430
   182
  apply (subgoal_tac "x mod Suc (Suc 0) = 0 | x mod Suc (Suc 0) = Suc 0")
paulson@14430
   183
  apply force 
paulson@14430
   184
  apply (subgoal_tac "0 < Suc (Suc 0)")
paulson@14430
   185
  apply (frule mod_less_divisor [of "Suc (Suc 0)" x])
paulson@14430
   186
  apply (erule nat_lt_two_imp_zero_or_one, auto)
paulson@14430
   187
  done
paulson@14430
   188
paulson@14430
   189
lemma even_nat_equiv_def: "even (x::nat) = (x mod Suc (Suc 0) = 0)" 
paulson@14430
   190
  apply (rule iffI)
paulson@14430
   191
  apply (erule even_nat_mod_two_eq_zero)
paulson@14430
   192
  apply (insert odd_nat_mod_two_eq_one [of x], auto)
paulson@14430
   193
  done
paulson@14430
   194
paulson@14430
   195
lemma odd_nat_equiv_def: "odd (x::nat) = (x mod Suc (Suc 0) = Suc 0)"
paulson@14430
   196
  apply (auto simp add: even_nat_equiv_def)
paulson@14430
   197
  apply (subgoal_tac "x mod (Suc (Suc 0)) < Suc (Suc 0)")
paulson@14430
   198
  apply (frule nat_lt_two_imp_zero_or_one, auto)
paulson@14430
   199
  done
paulson@14430
   200
paulson@14430
   201
lemma even_nat_div_two_times_two: "even (x::nat) ==> 
paulson@14430
   202
    Suc (Suc 0) * (x div Suc (Suc 0)) = x"
paulson@14430
   203
  apply (insert mod_div_equality [of x "Suc (Suc 0)", THEN sym])
paulson@14430
   204
  apply (drule even_nat_mod_two_eq_zero, simp)
paulson@14430
   205
  done
paulson@14430
   206
paulson@14430
   207
lemma odd_nat_div_two_times_two_plus_one: "odd (x::nat) ==> 
paulson@14430
   208
    Suc( Suc (Suc 0) * (x div Suc (Suc 0))) = x"  
paulson@14430
   209
  apply (insert mod_div_equality [of x "Suc (Suc 0)", THEN sym])
paulson@14430
   210
  apply (drule odd_nat_mod_two_eq_one, simp)
paulson@14430
   211
  done
paulson@14430
   212
paulson@14430
   213
lemma even_nat_equiv_def2: "even (x::nat) = (EX y. x = Suc (Suc 0) * y)"
paulson@14430
   214
  apply (rule iffI, rule exI)
paulson@14430
   215
  apply (erule even_nat_div_two_times_two [THEN sym], auto)
paulson@14430
   216
  done
paulson@14430
   217
paulson@14430
   218
lemma odd_nat_equiv_def2: "odd (x::nat) = (EX y. x = Suc(Suc (Suc 0) * y))"
paulson@14430
   219
  apply (rule iffI, rule exI)
paulson@14430
   220
  apply (erule odd_nat_div_two_times_two_plus_one [THEN sym], auto)
paulson@14430
   221
  done
paulson@14430
   222
avigad@16775
   223
subsection {* Parity and powers *}
avigad@16775
   224
avigad@16775
   225
lemma minus_one_even_odd_power:
avigad@16775
   226
     "(even x --> (- 1::'a::{comm_ring_1,recpower})^x = 1) & 
avigad@16775
   227
      (odd x --> (- 1::'a)^x = - 1)"
avigad@16775
   228
  apply (induct x)
avigad@16775
   229
  apply (rule conjI)
avigad@16775
   230
  apply simp
avigad@16775
   231
  apply (insert even_nat_zero, blast)
avigad@16775
   232
  apply (simp add: power_Suc)
avigad@16775
   233
done
avigad@16775
   234
avigad@16775
   235
lemma minus_one_even_power [simp]:
avigad@16775
   236
     "even x ==> (- 1::'a::{comm_ring_1,recpower})^x = 1"
avigad@16775
   237
  by (rule minus_one_even_odd_power [THEN conjunct1, THEN mp], assumption)
avigad@16775
   238
avigad@16775
   239
lemma minus_one_odd_power [simp]:
avigad@16775
   240
     "odd x ==> (- 1::'a::{comm_ring_1,recpower})^x = - 1"
avigad@16775
   241
  by (rule minus_one_even_odd_power [THEN conjunct2, THEN mp], assumption)
paulson@14430
   242
paulson@14430
   243
lemma neg_one_even_odd_power:
paulson@15003
   244
     "(even x --> (-1::'a::{number_ring,recpower})^x = 1) & 
paulson@14430
   245
      (odd x --> (-1::'a)^x = -1)"
paulson@15251
   246
  apply (induct x)
paulson@14430
   247
  apply (simp, simp add: power_Suc)
paulson@14430
   248
  done
paulson@14430
   249
paulson@14436
   250
lemma neg_one_even_power [simp]:
paulson@15003
   251
     "even x ==> (-1::'a::{number_ring,recpower})^x = 1"
paulson@14430
   252
  by (rule neg_one_even_odd_power [THEN conjunct1, THEN mp], assumption)
paulson@14430
   253
paulson@14436
   254
lemma neg_one_odd_power [simp]:
paulson@15003
   255
     "odd x ==> (-1::'a::{number_ring,recpower})^x = -1"
paulson@14430
   256
  by (rule neg_one_even_odd_power [THEN conjunct2, THEN mp], assumption)
paulson@14430
   257
paulson@14443
   258
lemma neg_power_if:
paulson@15003
   259
     "(-x::'a::{comm_ring_1,recpower}) ^ n = 
paulson@14443
   260
      (if even n then (x ^ n) else -(x ^ n))"
paulson@14443
   261
  by (induct n, simp_all split: split_if_asm add: power_Suc) 
paulson@14443
   262
avigad@16775
   263
lemma zero_le_even_power: "even n ==> 
avigad@16775
   264
    0 <= (x::'a::{recpower,ordered_ring_strict}) ^ n"
avigad@16775
   265
  apply (simp add: even_nat_equiv_def2)
avigad@16775
   266
  apply (erule exE)
avigad@16775
   267
  apply (erule ssubst)
avigad@16775
   268
  apply (subst power_add)
avigad@16775
   269
  apply (rule zero_le_square)
avigad@16775
   270
  done
avigad@16775
   271
avigad@16775
   272
lemma zero_le_odd_power: "odd n ==> 
avigad@16775
   273
    (0 <= (x::'a::{recpower,ordered_idom}) ^ n) = (0 <= x)"
avigad@16775
   274
  apply (simp add: odd_nat_equiv_def2)
avigad@16775
   275
  apply (erule exE)
avigad@16775
   276
  apply (erule ssubst)
avigad@16775
   277
  apply (subst power_Suc)
avigad@16775
   278
  apply (subst power_add)
avigad@16775
   279
  apply (subst zero_le_mult_iff)
avigad@16775
   280
  apply auto
avigad@16775
   281
  apply (subgoal_tac "x = 0 & 0 < y")
avigad@16775
   282
  apply (erule conjE, assumption)
avigad@16775
   283
  apply (subst power_eq_0_iff [THEN sym])
avigad@16775
   284
  apply (subgoal_tac "0 <= x^y * x^y")
avigad@16775
   285
  apply simp
avigad@16775
   286
  apply (rule zero_le_square)+
avigad@16775
   287
done
avigad@16775
   288
avigad@16775
   289
lemma zero_le_power_eq: "(0 <= (x::'a::{recpower,ordered_idom}) ^ n) = 
avigad@16775
   290
    (even n | (odd n & 0 <= x))"
avigad@16775
   291
  apply auto
avigad@16775
   292
  apply (subst zero_le_odd_power [THEN sym])
avigad@16775
   293
  apply assumption+
avigad@16775
   294
  apply (erule zero_le_even_power)
avigad@16775
   295
  apply (subst zero_le_odd_power) 
avigad@16775
   296
  apply assumption+
avigad@16775
   297
done
avigad@16775
   298
avigad@16775
   299
lemma zero_less_power_eq: "(0 < (x::'a::{recpower,ordered_idom}) ^ n) = 
avigad@16775
   300
    (n = 0 | (even n & x ~= 0) | (odd n & 0 < x))"
avigad@16775
   301
  apply (rule iffI)
avigad@16775
   302
  apply clarsimp
avigad@16775
   303
  apply (rule conjI)
avigad@16775
   304
  apply clarsimp
avigad@16775
   305
  apply (rule ccontr)
avigad@16775
   306
  apply (subgoal_tac "~ (0 <= x^n)")
avigad@16775
   307
  apply simp
avigad@16775
   308
  apply (subst zero_le_odd_power)
avigad@16775
   309
  apply assumption 
avigad@16775
   310
  apply simp
avigad@16775
   311
  apply (rule notI)
avigad@16775
   312
  apply (simp add: power_0_left)
avigad@16775
   313
  apply (rule notI)
avigad@16775
   314
  apply (simp add: power_0_left)
avigad@16775
   315
  apply auto
avigad@16775
   316
  apply (subgoal_tac "0 <= x^n")
avigad@16775
   317
  apply (frule order_le_imp_less_or_eq)
avigad@16775
   318
  apply simp
avigad@16775
   319
  apply (erule zero_le_even_power)
avigad@16775
   320
  apply (subgoal_tac "0 <= x^n")
avigad@16775
   321
  apply (frule order_le_imp_less_or_eq)
avigad@16775
   322
  apply auto
avigad@16775
   323
  apply (subst zero_le_odd_power)
avigad@16775
   324
  apply assumption
avigad@16775
   325
  apply (erule order_less_imp_le)
avigad@16775
   326
done
avigad@16775
   327
avigad@16775
   328
lemma power_less_zero_eq: "((x::'a::{recpower,ordered_idom}) ^ n < 0) =
avigad@16775
   329
    (odd n & x < 0)" 
avigad@16775
   330
  apply (subst linorder_not_le [THEN sym])+
avigad@16775
   331
  apply (subst zero_le_power_eq)
avigad@16775
   332
  apply auto
avigad@16775
   333
done
avigad@16775
   334
avigad@16775
   335
lemma power_le_zero_eq: "((x::'a::{recpower,ordered_idom}) ^ n <= 0) =
avigad@16775
   336
    (n ~= 0 & ((odd n & x <= 0) | (even n & x = 0)))"
avigad@16775
   337
  apply (subst linorder_not_less [THEN sym])+
avigad@16775
   338
  apply (subst zero_less_power_eq)
avigad@16775
   339
  apply auto
avigad@16775
   340
done
avigad@16775
   341
avigad@16775
   342
lemma power_even_abs: "even n ==> 
avigad@16775
   343
    (abs (x::'a::{recpower,ordered_idom}))^n = x^n"
avigad@16775
   344
  apply (subst power_abs [THEN sym])
avigad@16775
   345
  apply (simp add: zero_le_even_power)
avigad@16775
   346
done
avigad@16775
   347
avigad@16775
   348
lemma zero_less_power_nat_eq: "(0 < (x::nat) ^ n) = (n = 0 | 0 < x)"
paulson@18648
   349
  by (induct n, auto)
avigad@16775
   350
avigad@16775
   351
lemma power_minus_even [simp]: "even n ==> 
avigad@16775
   352
    (- x)^n = (x^n::'a::{recpower,comm_ring_1})"
avigad@16775
   353
  apply (subst power_minus)
avigad@16775
   354
  apply simp
avigad@16775
   355
done
avigad@16775
   356
avigad@16775
   357
lemma power_minus_odd [simp]: "odd n ==> 
avigad@16775
   358
    (- x)^n = - (x^n::'a::{recpower,comm_ring_1})"
avigad@16775
   359
  apply (subst power_minus)
avigad@16775
   360
  apply simp
avigad@16775
   361
done
avigad@16775
   362
avigad@16775
   363
(* Simplify, when the exponent is a numeral *)
avigad@16775
   364
paulson@17085
   365
lemmas power_0_left_number_of = power_0_left [of "number_of w", standard]
paulson@17085
   366
declare power_0_left_number_of [simp]
paulson@17085
   367
paulson@17085
   368
lemmas zero_le_power_eq_number_of =
paulson@17085
   369
    zero_le_power_eq [of _ "number_of w", standard]
paulson@17085
   370
declare zero_le_power_eq_number_of [simp]
paulson@17085
   371
paulson@17085
   372
lemmas zero_less_power_eq_number_of =
paulson@17085
   373
    zero_less_power_eq [of _ "number_of w", standard]
paulson@17085
   374
declare zero_less_power_eq_number_of [simp]
paulson@17085
   375
paulson@17085
   376
lemmas power_le_zero_eq_number_of =
paulson@17085
   377
    power_le_zero_eq [of _ "number_of w", standard]
paulson@17085
   378
declare power_le_zero_eq_number_of [simp]
paulson@17085
   379
paulson@17085
   380
lemmas power_less_zero_eq_number_of =
paulson@17085
   381
    power_less_zero_eq [of _ "number_of w", standard]
paulson@17085
   382
declare power_less_zero_eq_number_of [simp]
paulson@17085
   383
paulson@17085
   384
lemmas zero_less_power_nat_eq_number_of =
paulson@17085
   385
    zero_less_power_nat_eq [of _ "number_of w", standard]
paulson@17085
   386
declare zero_less_power_nat_eq_number_of [simp]
paulson@17085
   387
paulson@17085
   388
lemmas power_eq_0_iff_number_of = power_eq_0_iff [of _ "number_of w", standard]
paulson@17085
   389
declare power_eq_0_iff_number_of [simp]
paulson@17085
   390
paulson@17085
   391
lemmas power_even_abs_number_of = power_even_abs [of "number_of w" _, standard]
paulson@17085
   392
declare power_even_abs_number_of [simp]
paulson@17085
   393
paulson@14430
   394
wenzelm@17472
   395
subsection {* An Equivalence for @{term [source] "0 \<le> a^n"} *}
paulson@14450
   396
paulson@14450
   397
lemma even_power_le_0_imp_0:
paulson@15003
   398
     "a ^ (2*k) \<le> (0::'a::{ordered_idom,recpower}) ==> a=0"
paulson@14450
   399
apply (induct k) 
paulson@14450
   400
apply (auto simp add: zero_le_mult_iff mult_le_0_iff power_Suc)  
paulson@14450
   401
done
paulson@14450
   402
paulson@14450
   403
lemma zero_le_power_iff:
paulson@15003
   404
     "(0 \<le> a^n) = (0 \<le> (a::'a::{ordered_idom,recpower}) | even n)"
paulson@14450
   405
      (is "?P n")
paulson@14450
   406
proof cases
paulson@14450
   407
  assume even: "even n"
paulson@14473
   408
  then obtain k where "n = 2*k"
paulson@14450
   409
    by (auto simp add: even_nat_equiv_def2 numeral_2_eq_2)
paulson@14450
   410
  thus ?thesis by (simp add: zero_le_even_power even) 
paulson@14450
   411
next
paulson@14450
   412
  assume odd: "odd n"
paulson@14473
   413
  then obtain k where "n = Suc(2*k)"
paulson@14450
   414
    by (auto simp add: odd_nat_equiv_def2 numeral_2_eq_2)
paulson@14450
   415
  thus ?thesis
paulson@14450
   416
    by (auto simp add: power_Suc zero_le_mult_iff zero_le_even_power 
paulson@14450
   417
             dest!: even_power_le_0_imp_0) 
paulson@14450
   418
qed 
paulson@14450
   419
paulson@14430
   420
subsection {* Miscellaneous *}
paulson@14430
   421
paulson@14430
   422
lemma even_plus_one_div_two: "even (x::int) ==> (x + 1) div 2 = x div 2"
paulson@14430
   423
  apply (subst zdiv_zadd1_eq)
paulson@14430
   424
  apply (simp add: even_def)
paulson@14430
   425
  done
paulson@14430
   426
paulson@14430
   427
lemma odd_plus_one_div_two: "odd (x::int) ==> (x + 1) div 2 = x div 2 + 1"
paulson@14430
   428
  apply (subst zdiv_zadd1_eq)
paulson@14430
   429
  apply (simp add: even_def)
paulson@14430
   430
  done
paulson@14430
   431
paulson@14430
   432
lemma div_Suc: "Suc a div c = a div c + Suc 0 div c + 
paulson@14430
   433
    (a mod c + Suc 0 mod c) div c"
paulson@14430
   434
  apply (subgoal_tac "Suc a = a + Suc 0")
paulson@14430
   435
  apply (erule ssubst)
paulson@14430
   436
  apply (rule div_add1_eq, simp)
paulson@14430
   437
  done
paulson@14430
   438
paulson@14430
   439
lemma even_nat_plus_one_div_two: "even (x::nat) ==> 
paulson@14430
   440
   (Suc x) div Suc (Suc 0) = x div Suc (Suc 0)"
paulson@14430
   441
  apply (subst div_Suc)
paulson@14430
   442
  apply (simp add: even_nat_equiv_def)
paulson@14430
   443
  done
paulson@14430
   444
paulson@14430
   445
lemma odd_nat_plus_one_div_two: "odd (x::nat) ==> 
paulson@14430
   446
    (Suc x) div Suc (Suc 0) = Suc (x div Suc (Suc 0))"
paulson@14430
   447
  apply (subst div_Suc)
paulson@14430
   448
  apply (simp add: odd_nat_equiv_def)
paulson@14430
   449
  done
paulson@14430
   450
paulson@14430
   451
end