src/HOL/Parity.thy
author blanchet
Sun, 12 Oct 2014 21:52:45 +0200
changeset 58654 3e1cad27fc2f
parent 58645 94bef115c08f
child 58678 398e05aa84d4
permissions -rw-r--r--
special treatment of extensionality in minimizer
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
41959
b460124855b8 tuned headers;
wenzelm
parents: 36840
diff changeset
     1
(*  Title:      HOL/Parity.thy
b460124855b8 tuned headers;
wenzelm
parents: 36840
diff changeset
     2
    Author:     Jeremy Avigad
b460124855b8 tuned headers;
wenzelm
parents: 36840
diff changeset
     3
    Author:     Jacques D. Fleuriot
21256
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
     4
*)
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
     5
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
     6
header {* Even and Odd for int and nat *}
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
     7
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
     8
theory Parity
30738
0842e906300c normalized imports
haftmann
parents: 30056
diff changeset
     9
imports Main
21256
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
    10
begin
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
    11
54228
229282d53781 purely algebraic foundation for even/odd
haftmann
parents: 54227
diff changeset
    12
class even_odd = semiring_div_parity
54227
63b441f49645 moving generic lemmas out of theory parity, disregarding some unused auxiliary lemmas;
haftmann
parents: 47225
diff changeset
    13
begin
21256
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
    14
54228
229282d53781 purely algebraic foundation for even/odd
haftmann
parents: 54227
diff changeset
    15
definition even :: "'a \<Rightarrow> bool"
229282d53781 purely algebraic foundation for even/odd
haftmann
parents: 54227
diff changeset
    16
where
58645
94bef115c08f more foundational definition for predicate even
haftmann
parents: 54489
diff changeset
    17
  [algebra]: "even a \<longleftrightarrow> 2 dvd a"
54228
229282d53781 purely algebraic foundation for even/odd
haftmann
parents: 54227
diff changeset
    18
58645
94bef115c08f more foundational definition for predicate even
haftmann
parents: 54489
diff changeset
    19
lemmas even_iff_2_dvd = even_def
94bef115c08f more foundational definition for predicate even
haftmann
parents: 54489
diff changeset
    20
94bef115c08f more foundational definition for predicate even
haftmann
parents: 54489
diff changeset
    21
lemma even_iff_mod_2_eq_zero [presburger]:
94bef115c08f more foundational definition for predicate even
haftmann
parents: 54489
diff changeset
    22
  "even a \<longleftrightarrow> a mod 2 = 0"
54228
229282d53781 purely algebraic foundation for even/odd
haftmann
parents: 54227
diff changeset
    23
  by (simp add: even_def dvd_eq_mod_eq_0)
229282d53781 purely algebraic foundation for even/odd
haftmann
parents: 54227
diff changeset
    24
229282d53781 purely algebraic foundation for even/odd
haftmann
parents: 54227
diff changeset
    25
lemma even_zero [simp]:
229282d53781 purely algebraic foundation for even/odd
haftmann
parents: 54227
diff changeset
    26
  "even 0"
58645
94bef115c08f more foundational definition for predicate even
haftmann
parents: 54489
diff changeset
    27
  by (simp add: even_iff_mod_2_eq_zero)
54228
229282d53781 purely algebraic foundation for even/odd
haftmann
parents: 54227
diff changeset
    28
229282d53781 purely algebraic foundation for even/odd
haftmann
parents: 54227
diff changeset
    29
lemma even_times_anything:
229282d53781 purely algebraic foundation for even/odd
haftmann
parents: 54227
diff changeset
    30
  "even a \<Longrightarrow> even (a * b)"
229282d53781 purely algebraic foundation for even/odd
haftmann
parents: 54227
diff changeset
    31
  by (simp add: even_iff_2_dvd)
229282d53781 purely algebraic foundation for even/odd
haftmann
parents: 54227
diff changeset
    32
229282d53781 purely algebraic foundation for even/odd
haftmann
parents: 54227
diff changeset
    33
lemma anything_times_even:
229282d53781 purely algebraic foundation for even/odd
haftmann
parents: 54227
diff changeset
    34
  "even a \<Longrightarrow> even (b * a)"
229282d53781 purely algebraic foundation for even/odd
haftmann
parents: 54227
diff changeset
    35
  by (simp add: even_iff_2_dvd)
229282d53781 purely algebraic foundation for even/odd
haftmann
parents: 54227
diff changeset
    36
54227
63b441f49645 moving generic lemmas out of theory parity, disregarding some unused auxiliary lemmas;
haftmann
parents: 47225
diff changeset
    37
abbreviation odd :: "'a \<Rightarrow> bool"
63b441f49645 moving generic lemmas out of theory parity, disregarding some unused auxiliary lemmas;
haftmann
parents: 47225
diff changeset
    38
where
54228
229282d53781 purely algebraic foundation for even/odd
haftmann
parents: 54227
diff changeset
    39
  "odd a \<equiv> \<not> even a"
229282d53781 purely algebraic foundation for even/odd
haftmann
parents: 54227
diff changeset
    40
229282d53781 purely algebraic foundation for even/odd
haftmann
parents: 54227
diff changeset
    41
lemma odd_times_odd:
229282d53781 purely algebraic foundation for even/odd
haftmann
parents: 54227
diff changeset
    42
  "odd a \<Longrightarrow> odd b \<Longrightarrow> odd (a * b)" 
58645
94bef115c08f more foundational definition for predicate even
haftmann
parents: 54489
diff changeset
    43
  by (auto simp add: even_iff_mod_2_eq_zero mod_mult_left_eq)
54228
229282d53781 purely algebraic foundation for even/odd
haftmann
parents: 54227
diff changeset
    44
229282d53781 purely algebraic foundation for even/odd
haftmann
parents: 54227
diff changeset
    45
lemma even_product [simp, presburger]:
229282d53781 purely algebraic foundation for even/odd
haftmann
parents: 54227
diff changeset
    46
  "even (a * b) \<longleftrightarrow> even a \<or> even b"
229282d53781 purely algebraic foundation for even/odd
haftmann
parents: 54227
diff changeset
    47
  apply (auto simp add: even_times_anything anything_times_even)
229282d53781 purely algebraic foundation for even/odd
haftmann
parents: 54227
diff changeset
    48
  apply (rule ccontr)
229282d53781 purely algebraic foundation for even/odd
haftmann
parents: 54227
diff changeset
    49
  apply (auto simp add: odd_times_odd)
229282d53781 purely algebraic foundation for even/odd
haftmann
parents: 54227
diff changeset
    50
  done
22390
378f34b1e380 now using "class"
haftmann
parents: 21404
diff changeset
    51
54227
63b441f49645 moving generic lemmas out of theory parity, disregarding some unused auxiliary lemmas;
haftmann
parents: 47225
diff changeset
    52
end
63b441f49645 moving generic lemmas out of theory parity, disregarding some unused auxiliary lemmas;
haftmann
parents: 47225
diff changeset
    53
54228
229282d53781 purely algebraic foundation for even/odd
haftmann
parents: 54227
diff changeset
    54
instance nat and int  :: even_odd ..
22390
378f34b1e380 now using "class"
haftmann
parents: 21404
diff changeset
    55
54228
229282d53781 purely algebraic foundation for even/odd
haftmann
parents: 54227
diff changeset
    56
lemma even_nat_def [presburger]:
229282d53781 purely algebraic foundation for even/odd
haftmann
parents: 54227
diff changeset
    57
  "even x \<longleftrightarrow> even (int x)"
58645
94bef115c08f more foundational definition for predicate even
haftmann
parents: 54489
diff changeset
    58
  by (auto simp add: even_iff_mod_2_eq_zero int_eq_iff int_mult nat_mult_distrib)
54228
229282d53781 purely algebraic foundation for even/odd
haftmann
parents: 54227
diff changeset
    59
  
33318
ddd97d9dfbfb moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents: 31718
diff changeset
    60
lemma transfer_int_nat_relations:
ddd97d9dfbfb moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents: 31718
diff changeset
    61
  "even (int x) \<longleftrightarrow> even x"
ddd97d9dfbfb moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents: 31718
diff changeset
    62
  by (simp add: even_nat_def)
ddd97d9dfbfb moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents: 31718
diff changeset
    63
35644
d20cf282342e transfer: avoid camel case
haftmann
parents: 35631
diff changeset
    64
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
    65
  transfer_int_nat_relations
ddd97d9dfbfb moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents: 31718
diff changeset
    66
]
21256
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
    67
54228
229282d53781 purely algebraic foundation for even/odd
haftmann
parents: 54227
diff changeset
    68
lemma odd_one_int [simp]:
229282d53781 purely algebraic foundation for even/odd
haftmann
parents: 54227
diff changeset
    69
  "odd (1::int)"
229282d53781 purely algebraic foundation for even/odd
haftmann
parents: 54227
diff changeset
    70
  by presburger
31148
7ba7c1f8bc22 Cleaned up Parity a little
nipkow
parents: 31017
diff changeset
    71
54228
229282d53781 purely algebraic foundation for even/odd
haftmann
parents: 54227
diff changeset
    72
lemma odd_1_nat [simp]:
229282d53781 purely algebraic foundation for even/odd
haftmann
parents: 54227
diff changeset
    73
  "odd (1::nat)"
229282d53781 purely algebraic foundation for even/odd
haftmann
parents: 54227
diff changeset
    74
  by presburger
31148
7ba7c1f8bc22 Cleaned up Parity a little
nipkow
parents: 31017
diff changeset
    75
47224
773fe2754b8c add simp rules for eve/odd on numerals
huffman
parents: 47163
diff changeset
    76
lemma even_numeral_int [simp]: "even (numeral (Num.Bit0 k) :: int)"
58645
94bef115c08f more foundational definition for predicate even
haftmann
parents: 54489
diff changeset
    77
  unfolding even_iff_mod_2_eq_zero by simp
47224
773fe2754b8c add simp rules for eve/odd on numerals
huffman
parents: 47163
diff changeset
    78
773fe2754b8c add simp rules for eve/odd on numerals
huffman
parents: 47163
diff changeset
    79
lemma odd_numeral_int [simp]: "odd (numeral (Num.Bit1 k) :: int)"
58645
94bef115c08f more foundational definition for predicate even
haftmann
parents: 54489
diff changeset
    80
  unfolding even_iff_mod_2_eq_zero by simp
47224
773fe2754b8c add simp rules for eve/odd on numerals
huffman
parents: 47163
diff changeset
    81
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 45607
diff changeset
    82
(* TODO: proper simp rules for Num.Bit0, Num.Bit1 *)
58645
94bef115c08f more foundational definition for predicate even
haftmann
parents: 54489
diff changeset
    83
declare even_iff_mod_2_eq_zero [of "- numeral v", simp] for v
31148
7ba7c1f8bc22 Cleaned up Parity a little
nipkow
parents: 31017
diff changeset
    84
47224
773fe2754b8c add simp rules for eve/odd on numerals
huffman
parents: 47163
diff changeset
    85
lemma even_numeral_nat [simp]: "even (numeral (Num.Bit0 k) :: nat)"
773fe2754b8c add simp rules for eve/odd on numerals
huffman
parents: 47163
diff changeset
    86
  unfolding even_nat_def by simp
773fe2754b8c add simp rules for eve/odd on numerals
huffman
parents: 47163
diff changeset
    87
773fe2754b8c add simp rules for eve/odd on numerals
huffman
parents: 47163
diff changeset
    88
lemma odd_numeral_nat [simp]: "odd (numeral (Num.Bit1 k) :: nat)"
773fe2754b8c add simp rules for eve/odd on numerals
huffman
parents: 47163
diff changeset
    89
  unfolding even_nat_def by simp
31148
7ba7c1f8bc22 Cleaned up Parity a little
nipkow
parents: 31017
diff changeset
    90
21256
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
    91
subsection {* Even and odd are mutually exclusive *}
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
    92
25600
73431bd8c4c4 joined EvenOdd theory with Parity
haftmann
parents: 25594
diff changeset
    93
21256
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
    94
subsection {* Behavior under integer arithmetic operations *}
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
    95
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
    96
lemma even_plus_even: "even (x::int) ==> even y ==> even (x + y)"
31148
7ba7c1f8bc22 Cleaned up Parity a little
nipkow
parents: 31017
diff changeset
    97
by presburger
21256
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
    98
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
    99
lemma even_plus_odd: "even (x::int) ==> odd y ==> odd (x + y)"
31148
7ba7c1f8bc22 Cleaned up Parity a little
nipkow
parents: 31017
diff changeset
   100
by presburger
21256
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   101
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   102
lemma odd_plus_even: "odd (x::int) ==> even y ==> odd (x + y)"
31148
7ba7c1f8bc22 Cleaned up Parity a little
nipkow
parents: 31017
diff changeset
   103
by presburger
21256
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   104
23522
7e8255828502 Tuned proofs
chaieb
parents: 23438
diff changeset
   105
lemma odd_plus_odd: "odd (x::int) ==> odd y ==> even (x + y)" by presburger
21256
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   106
31148
7ba7c1f8bc22 Cleaned up Parity a little
nipkow
parents: 31017
diff changeset
   107
lemma even_sum[simp,presburger]:
7ba7c1f8bc22 Cleaned up Parity a little
nipkow
parents: 31017
diff changeset
   108
  "even ((x::int) + y) = ((even x & even y) | (odd x & odd y))"
7ba7c1f8bc22 Cleaned up Parity a little
nipkow
parents: 31017
diff changeset
   109
by presburger
21256
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   110
31148
7ba7c1f8bc22 Cleaned up Parity a little
nipkow
parents: 31017
diff changeset
   111
lemma even_neg[simp,presburger,algebra]: "even (-(x::int)) = even x"
7ba7c1f8bc22 Cleaned up Parity a little
nipkow
parents: 31017
diff changeset
   112
by presburger
21256
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   113
31148
7ba7c1f8bc22 Cleaned up Parity a little
nipkow
parents: 31017
diff changeset
   114
lemma even_difference[simp]:
23522
7e8255828502 Tuned proofs
chaieb
parents: 23438
diff changeset
   115
    "even ((x::int) - y) = ((even x & even y) | (odd x & odd y))" by presburger
21256
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   116
31148
7ba7c1f8bc22 Cleaned up Parity a little
nipkow
parents: 31017
diff changeset
   117
lemma even_power[simp,presburger]: "even ((x::int)^n) = (even x & n \<noteq> 0)"
7ba7c1f8bc22 Cleaned up Parity a little
nipkow
parents: 31017
diff changeset
   118
by (induct n) auto
21256
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   119
31148
7ba7c1f8bc22 Cleaned up Parity a little
nipkow
parents: 31017
diff changeset
   120
lemma odd_pow: "odd x ==> odd((x::int)^n)" by simp
21256
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   121
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   122
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   123
subsection {* Equivalent definitions *}
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   124
23522
7e8255828502 Tuned proofs
chaieb
parents: 23438
diff changeset
   125
lemma two_times_even_div_two: "even (x::int) ==> 2 * (x div 2) = x" 
31148
7ba7c1f8bc22 Cleaned up Parity a little
nipkow
parents: 31017
diff changeset
   126
by presburger
21256
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   127
31148
7ba7c1f8bc22 Cleaned up Parity a little
nipkow
parents: 31017
diff changeset
   128
lemma two_times_odd_div_two_plus_one:
7ba7c1f8bc22 Cleaned up Parity a little
nipkow
parents: 31017
diff changeset
   129
  "odd (x::int) ==> 2 * (x div 2) + 1 = x"
7ba7c1f8bc22 Cleaned up Parity a little
nipkow
parents: 31017
diff changeset
   130
by presburger
21256
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   131
23522
7e8255828502 Tuned proofs
chaieb
parents: 23438
diff changeset
   132
lemma even_equiv_def: "even (x::int) = (EX y. x = 2 * y)" by presburger
21256
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   133
23522
7e8255828502 Tuned proofs
chaieb
parents: 23438
diff changeset
   134
lemma odd_equiv_def: "odd (x::int) = (EX y. x = 2 * y + 1)" by presburger
21256
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   135
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   136
subsection {* even and odd for nats *}
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   137
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   138
lemma pos_int_even_equiv_nat_even: "0 \<le> x ==> even x = even (nat x)"
31148
7ba7c1f8bc22 Cleaned up Parity a little
nipkow
parents: 31017
diff changeset
   139
by (simp add: even_nat_def)
21256
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   140
31148
7ba7c1f8bc22 Cleaned up Parity a little
nipkow
parents: 31017
diff changeset
   141
lemma even_product_nat[simp,presburger,algebra]:
7ba7c1f8bc22 Cleaned up Parity a little
nipkow
parents: 31017
diff changeset
   142
  "even((x::nat) * y) = (even x | even y)"
7ba7c1f8bc22 Cleaned up Parity a little
nipkow
parents: 31017
diff changeset
   143
by (simp add: even_nat_def int_mult)
21256
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   144
31148
7ba7c1f8bc22 Cleaned up Parity a little
nipkow
parents: 31017
diff changeset
   145
lemma even_sum_nat[simp,presburger,algebra]:
7ba7c1f8bc22 Cleaned up Parity a little
nipkow
parents: 31017
diff changeset
   146
  "even ((x::nat) + y) = ((even x & even y) | (odd x & odd y))"
23522
7e8255828502 Tuned proofs
chaieb
parents: 23438
diff changeset
   147
by presburger
21256
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   148
31148
7ba7c1f8bc22 Cleaned up Parity a little
nipkow
parents: 31017
diff changeset
   149
lemma even_difference_nat[simp,presburger,algebra]:
7ba7c1f8bc22 Cleaned up Parity a little
nipkow
parents: 31017
diff changeset
   150
  "even ((x::nat) - y) = (x < y | (even x & even y) | (odd x & odd y))"
7ba7c1f8bc22 Cleaned up Parity a little
nipkow
parents: 31017
diff changeset
   151
by presburger
21256
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   152
31148
7ba7c1f8bc22 Cleaned up Parity a little
nipkow
parents: 31017
diff changeset
   153
lemma even_Suc[simp,presburger,algebra]: "even (Suc x) = odd x"
7ba7c1f8bc22 Cleaned up Parity a little
nipkow
parents: 31017
diff changeset
   154
by presburger
21256
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   155
31148
7ba7c1f8bc22 Cleaned up Parity a little
nipkow
parents: 31017
diff changeset
   156
lemma even_power_nat[simp,presburger,algebra]:
7ba7c1f8bc22 Cleaned up Parity a little
nipkow
parents: 31017
diff changeset
   157
  "even ((x::nat)^y) = (even x & 0 < y)"
7ba7c1f8bc22 Cleaned up Parity a little
nipkow
parents: 31017
diff changeset
   158
by (simp add: even_nat_def int_power)
21256
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   159
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   160
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   161
subsection {* Equivalent definitions *}
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   162
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   163
lemma even_nat_mod_two_eq_zero: "even (x::nat) ==> x mod (Suc (Suc 0)) = 0"
31148
7ba7c1f8bc22 Cleaned up Parity a little
nipkow
parents: 31017
diff changeset
   164
by presburger
21256
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   165
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   166
lemma odd_nat_mod_two_eq_one: "odd (x::nat) ==> x mod (Suc (Suc 0)) = Suc 0"
23522
7e8255828502 Tuned proofs
chaieb
parents: 23438
diff changeset
   167
by presburger
21256
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   168
21263
wenzelm
parents: 21256
diff changeset
   169
lemma even_nat_equiv_def: "even (x::nat) = (x mod Suc (Suc 0) = 0)"
31148
7ba7c1f8bc22 Cleaned up Parity a little
nipkow
parents: 31017
diff changeset
   170
by presburger
21256
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   171
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   172
lemma odd_nat_equiv_def: "odd (x::nat) = (x mod Suc (Suc 0) = Suc 0)"
31148
7ba7c1f8bc22 Cleaned up Parity a little
nipkow
parents: 31017
diff changeset
   173
by presburger
21256
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   174
21263
wenzelm
parents: 21256
diff changeset
   175
lemma even_nat_div_two_times_two: "even (x::nat) ==>
23522
7e8255828502 Tuned proofs
chaieb
parents: 23438
diff changeset
   176
    Suc (Suc 0) * (x div Suc (Suc 0)) = x" by presburger
21256
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   177
21263
wenzelm
parents: 21256
diff changeset
   178
lemma odd_nat_div_two_times_two_plus_one: "odd (x::nat) ==>
23522
7e8255828502 Tuned proofs
chaieb
parents: 23438
diff changeset
   179
    Suc( Suc (Suc 0) * (x div Suc (Suc 0))) = x" by presburger
21256
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   180
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   181
lemma even_nat_equiv_def2: "even (x::nat) = (EX y. x = Suc (Suc 0) * y)"
31148
7ba7c1f8bc22 Cleaned up Parity a little
nipkow
parents: 31017
diff changeset
   182
by presburger
21256
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   183
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   184
lemma odd_nat_equiv_def2: "odd (x::nat) = (EX y. x = Suc(Suc (Suc 0) * y))"
31148
7ba7c1f8bc22 Cleaned up Parity a little
nipkow
parents: 31017
diff changeset
   185
by presburger
21256
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   186
25600
73431bd8c4c4 joined EvenOdd theory with Parity
haftmann
parents: 25594
diff changeset
   187
21256
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   188
subsection {* Parity and powers *}
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   189
54228
229282d53781 purely algebraic foundation for even/odd
haftmann
parents: 54227
diff changeset
   190
lemma (in comm_ring_1) neg_power_if:
229282d53781 purely algebraic foundation for even/odd
haftmann
parents: 54227
diff changeset
   191
  "(- a) ^ n = (if even n then (a ^ n) else - (a ^ n))"
229282d53781 purely algebraic foundation for even/odd
haftmann
parents: 54227
diff changeset
   192
  by (induct n) simp_all
21256
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   193
54228
229282d53781 purely algebraic foundation for even/odd
haftmann
parents: 54227
diff changeset
   194
lemma (in comm_ring_1)
54489
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54228
diff changeset
   195
  shows neg_one_even_power [simp]: "even n \<Longrightarrow> (- 1) ^ n = 1"
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54228
diff changeset
   196
  and neg_one_odd_power [simp]: "odd n \<Longrightarrow> (- 1) ^ n = - 1"
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54228
diff changeset
   197
  by (simp_all add: neg_power_if)
21256
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   198
21263
wenzelm
parents: 21256
diff changeset
   199
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
   200
    0 <= (x::'a::{linordered_ring,monoid_mult}) ^ n"
21256
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   201
  apply (simp add: even_nat_equiv_def2)
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   202
  apply (erule exE)
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   203
  apply (erule ssubst)
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   204
  apply (subst power_add)
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   205
  apply (rule zero_le_square)
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   206
  done
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   207
21263
wenzelm
parents: 21256
diff changeset
   208
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
   209
    (0 <= (x::'a::{linordered_idom}) ^ n) = (0 <= x)"
35216
7641e8d831d2 get rid of many duplicate simp rule warnings
huffman
parents: 35043
diff changeset
   210
apply (auto simp: odd_nat_equiv_def2 power_add zero_le_mult_iff)
36722
c8ea75ea4a29 tuned proof
haftmann
parents: 35644
diff changeset
   211
apply (metis field_power_not_zero divisors_zero order_antisym_conv zero_le_square)
30056
0a35bee25c20 added lemmas
nipkow
parents: 29803
diff changeset
   212
done
21256
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   213
54227
63b441f49645 moving generic lemmas out of theory parity, disregarding some unused auxiliary lemmas;
haftmann
parents: 47225
diff changeset
   214
lemma zero_le_power_eq [presburger]: "(0 <= (x::'a::{linordered_idom}) ^ n) =
21256
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   215
    (even n | (odd n & 0 <= x))"
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   216
  apply auto
21263
wenzelm
parents: 21256
diff changeset
   217
  apply (subst zero_le_odd_power [symmetric])
21256
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   218
  apply assumption+
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   219
  apply (erule zero_le_even_power)
21263
wenzelm
parents: 21256
diff changeset
   220
  done
21256
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   221
35028
108662d50512 more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
haftmann
parents: 33358
diff changeset
   222
lemma zero_less_power_eq[presburger]: "(0 < (x::'a::{linordered_idom}) ^ n) =
21256
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   223
    (n = 0 | (even n & x ~= 0) | (odd n & 0 < x))"
27668
6eb20b2cecf8 Tuned and simplified proofs
chaieb
parents: 27651
diff changeset
   224
6eb20b2cecf8 Tuned and simplified proofs
chaieb
parents: 27651
diff changeset
   225
  unfolding order_less_le zero_le_power_eq by auto
21256
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   226
35028
108662d50512 more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
haftmann
parents: 33358
diff changeset
   227
lemma power_less_zero_eq[presburger]: "((x::'a::{linordered_idom}) ^ n < 0) =
27668
6eb20b2cecf8 Tuned and simplified proofs
chaieb
parents: 27651
diff changeset
   228
    (odd n & x < 0)"
21263
wenzelm
parents: 21256
diff changeset
   229
  apply (subst linorder_not_le [symmetric])+
21256
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   230
  apply (subst zero_le_power_eq)
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   231
  apply auto
21263
wenzelm
parents: 21256
diff changeset
   232
  done
21256
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   233
35028
108662d50512 more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
haftmann
parents: 33358
diff changeset
   234
lemma power_le_zero_eq[presburger]: "((x::'a::{linordered_idom}) ^ n <= 0) =
21256
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   235
    (n ~= 0 & ((odd n & x <= 0) | (even n & x = 0)))"
21263
wenzelm
parents: 21256
diff changeset
   236
  apply (subst linorder_not_less [symmetric])+
21256
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   237
  apply (subst zero_less_power_eq)
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   238
  apply auto
21263
wenzelm
parents: 21256
diff changeset
   239
  done
21256
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   240
21263
wenzelm
parents: 21256
diff changeset
   241
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
   242
    (abs (x::'a::{linordered_idom}))^n = x^n"
21263
wenzelm
parents: 21256
diff changeset
   243
  apply (subst power_abs [symmetric])
21256
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   244
  apply (simp add: zero_le_even_power)
21263
wenzelm
parents: 21256
diff changeset
   245
  done
21256
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   246
21263
wenzelm
parents: 21256
diff changeset
   247
lemma power_minus_even [simp]: "even n ==>
31017
2c227493ea56 stripped class recpower further
haftmann
parents: 30738
diff changeset
   248
    (- x)^n = (x^n::'a::{comm_ring_1})"
21256
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   249
  apply (subst power_minus)
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   250
  apply simp
21263
wenzelm
parents: 21256
diff changeset
   251
  done
21256
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   252
21263
wenzelm
parents: 21256
diff changeset
   253
lemma power_minus_odd [simp]: "odd n ==>
31017
2c227493ea56 stripped class recpower further
haftmann
parents: 30738
diff changeset
   254
    (- x)^n = - (x^n::'a::{comm_ring_1})"
21256
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   255
  apply (subst power_minus)
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   256
  apply simp
21263
wenzelm
parents: 21256
diff changeset
   257
  done
21256
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   258
35028
108662d50512 more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
haftmann
parents: 33358
diff changeset
   259
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
   260
  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
   261
  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
   262
proof -
c56a5571f60a Added derivation lemmas for power series and theorems for the pi, arcus tangens and logarithm series
hoelzl
parents: 29654
diff changeset
   263
  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
   264
  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
   265
  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
   266
  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
   267
qed
c56a5571f60a Added derivation lemmas for power series and theorems for the pi, arcus tangens and logarithm series
hoelzl
parents: 29654
diff changeset
   268
c56a5571f60a Added derivation lemmas for power series and theorems for the pi, arcus tangens and logarithm series
hoelzl
parents: 29654
diff changeset
   269
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
   270
35028
108662d50512 more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
haftmann
parents: 33358
diff changeset
   271
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
   272
  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
   273
  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
   274
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
   275
  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
   276
  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
   277
  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
   278
next
c56a5571f60a Added derivation lemmas for power series and theorems for the pi, arcus tangens and logarithm series
hoelzl
parents: 29654
diff changeset
   279
  case False
c56a5571f60a Added derivation lemmas for power series and theorems for the pi, arcus tangens and logarithm series
hoelzl
parents: 29654
diff changeset
   280
  show ?thesis
c56a5571f60a Added derivation lemmas for power series and theorems for the pi, arcus tangens and logarithm series
hoelzl
parents: 29654
diff changeset
   281
  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
   282
    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
   283
    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
   284
    moreover
c56a5571f60a Added derivation lemmas for power series and theorems for the pi, arcus tangens and logarithm series
hoelzl
parents: 29654
diff changeset
   285
    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
   286
    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
   287
    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
   288
  next
c56a5571f60a Added derivation lemmas for power series and theorems for the pi, arcus tangens and logarithm series
hoelzl
parents: 29654
diff changeset
   289
    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
   290
    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
   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
qed
21263
wenzelm
parents: 21256
diff changeset
   293
25600
73431bd8c4c4 joined EvenOdd theory with Parity
haftmann
parents: 25594
diff changeset
   294
73431bd8c4c4 joined EvenOdd theory with Parity
haftmann
parents: 25594
diff changeset
   295
subsection {* More Even/Odd Results *}
73431bd8c4c4 joined EvenOdd theory with Parity
haftmann
parents: 25594
diff changeset
   296
 
27668
6eb20b2cecf8 Tuned and simplified proofs
chaieb
parents: 27651
diff changeset
   297
lemma even_mult_two_ex: "even(n) = (\<exists>m::nat. n = 2*m)" by presburger
6eb20b2cecf8 Tuned and simplified proofs
chaieb
parents: 27651
diff changeset
   298
lemma odd_Suc_mult_two_ex: "odd(n) = (\<exists>m. n = Suc (2*m))" by presburger
6eb20b2cecf8 Tuned and simplified proofs
chaieb
parents: 27651
diff changeset
   299
lemma even_add [simp]: "even(m + n::nat) = (even m = even n)"  by presburger
25600
73431bd8c4c4 joined EvenOdd theory with Parity
haftmann
parents: 25594
diff changeset
   300
27668
6eb20b2cecf8 Tuned and simplified proofs
chaieb
parents: 27651
diff changeset
   301
lemma odd_add [simp]: "odd(m + n::nat) = (odd m \<noteq> odd n)" by presburger
25600
73431bd8c4c4 joined EvenOdd theory with Parity
haftmann
parents: 25594
diff changeset
   302
27668
6eb20b2cecf8 Tuned and simplified proofs
chaieb
parents: 27651
diff changeset
   303
lemma lemma_even_div2 [simp]: "even (n::nat) ==> (n + 1) div 2 = n div 2" by presburger
25600
73431bd8c4c4 joined EvenOdd theory with Parity
haftmann
parents: 25594
diff changeset
   304
73431bd8c4c4 joined EvenOdd theory with Parity
haftmann
parents: 25594
diff changeset
   305
lemma lemma_not_even_div2 [simp]: "~even n ==> (n + 1) div 2 = Suc (n div 2)"
27668
6eb20b2cecf8 Tuned and simplified proofs
chaieb
parents: 27651
diff changeset
   306
by presburger
25600
73431bd8c4c4 joined EvenOdd theory with Parity
haftmann
parents: 25594
diff changeset
   307
27668
6eb20b2cecf8 Tuned and simplified proofs
chaieb
parents: 27651
diff changeset
   308
lemma even_num_iff: "0 < n ==> even n = (~ even(n - 1 :: nat))"  by presburger
6eb20b2cecf8 Tuned and simplified proofs
chaieb
parents: 27651
diff changeset
   309
lemma even_even_mod_4_iff: "even (n::nat) = even (n mod 4)" by presburger
25600
73431bd8c4c4 joined EvenOdd theory with Parity
haftmann
parents: 25594
diff changeset
   310
27668
6eb20b2cecf8 Tuned and simplified proofs
chaieb
parents: 27651
diff changeset
   311
lemma lemma_odd_mod_4_div_2: "n mod 4 = (3::nat) ==> odd((n - 1) div 2)" by presburger
25600
73431bd8c4c4 joined EvenOdd theory with Parity
haftmann
parents: 25594
diff changeset
   312
73431bd8c4c4 joined EvenOdd theory with Parity
haftmann
parents: 25594
diff changeset
   313
lemma lemma_even_mod_4_div_2: "n mod 4 = (1::nat) ==> even ((n - 1) div 2)"
27668
6eb20b2cecf8 Tuned and simplified proofs
chaieb
parents: 27651
diff changeset
   314
  by presburger
25600
73431bd8c4c4 joined EvenOdd theory with Parity
haftmann
parents: 25594
diff changeset
   315
21263
wenzelm
parents: 21256
diff changeset
   316
text {* Simplify, when the exponent is a numeral *}
21256
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   317
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 45607
diff changeset
   318
lemmas zero_le_power_eq_numeral [simp] =
54227
63b441f49645 moving generic lemmas out of theory parity, disregarding some unused auxiliary lemmas;
haftmann
parents: 47225
diff changeset
   319
  zero_le_power_eq [of _ "numeral w"] for w
21256
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   320
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 45607
diff changeset
   321
lemmas zero_less_power_eq_numeral [simp] =
54227
63b441f49645 moving generic lemmas out of theory parity, disregarding some unused auxiliary lemmas;
haftmann
parents: 47225
diff changeset
   322
  zero_less_power_eq [of _ "numeral w"] for w
21256
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   323
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 45607
diff changeset
   324
lemmas power_le_zero_eq_numeral [simp] =
54227
63b441f49645 moving generic lemmas out of theory parity, disregarding some unused auxiliary lemmas;
haftmann
parents: 47225
diff changeset
   325
  power_le_zero_eq [of _ "numeral w"] for w
21256
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   326
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 45607
diff changeset
   327
lemmas power_less_zero_eq_numeral [simp] =
54227
63b441f49645 moving generic lemmas out of theory parity, disregarding some unused auxiliary lemmas;
haftmann
parents: 47225
diff changeset
   328
  power_less_zero_eq [of _ "numeral w"] for w
21256
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   329
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 45607
diff changeset
   330
lemmas zero_less_power_nat_eq_numeral [simp] =
54227
63b441f49645 moving generic lemmas out of theory parity, disregarding some unused auxiliary lemmas;
haftmann
parents: 47225
diff changeset
   331
  nat_zero_less_power_iff [of _ "numeral w"] for w
21256
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   332
54227
63b441f49645 moving generic lemmas out of theory parity, disregarding some unused auxiliary lemmas;
haftmann
parents: 47225
diff changeset
   333
lemmas power_eq_0_iff_numeral [simp] =
63b441f49645 moving generic lemmas out of theory parity, disregarding some unused auxiliary lemmas;
haftmann
parents: 47225
diff changeset
   334
  power_eq_0_iff [of _ "numeral w"] for w
21256
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   335
54227
63b441f49645 moving generic lemmas out of theory parity, disregarding some unused auxiliary lemmas;
haftmann
parents: 47225
diff changeset
   336
lemmas power_even_abs_numeral [simp] =
63b441f49645 moving generic lemmas out of theory parity, disregarding some unused auxiliary lemmas;
haftmann
parents: 47225
diff changeset
   337
  power_even_abs [of "numeral w" _] for w
21256
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   338
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   339
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   340
subsection {* An Equivalence for @{term [source] "0 \<le> a^n"} *}
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   341
23522
7e8255828502 Tuned proofs
chaieb
parents: 23438
diff changeset
   342
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
   343
  "(0 \<le> a^n) = (0 \<le> (a::'a::{linordered_idom}) | even n)"
21256
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   344
proof cases
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   345
  assume even: "even n"
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   346
  then obtain k where "n = 2*k"
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   347
    by (auto simp add: even_nat_equiv_def2 numeral_2_eq_2)
21263
wenzelm
parents: 21256
diff changeset
   348
  thus ?thesis by (simp add: zero_le_even_power even)
21256
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   349
next
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   350
  assume odd: "odd n"
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   351
  then obtain k where "n = Suc(2*k)"
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   352
    by (auto simp add: odd_nat_equiv_def2 numeral_2_eq_2)
54227
63b441f49645 moving generic lemmas out of theory parity, disregarding some unused auxiliary lemmas;
haftmann
parents: 47225
diff changeset
   353
  moreover have "a ^ (2 * k) \<le> 0 \<Longrightarrow> a = 0"
63b441f49645 moving generic lemmas out of theory parity, disregarding some unused auxiliary lemmas;
haftmann
parents: 47225
diff changeset
   354
    by (induct k) (auto simp add: zero_le_mult_iff mult_le_0_iff)
63b441f49645 moving generic lemmas out of theory parity, disregarding some unused auxiliary lemmas;
haftmann
parents: 47225
diff changeset
   355
  ultimately show ?thesis
63b441f49645 moving generic lemmas out of theory parity, disregarding some unused auxiliary lemmas;
haftmann
parents: 47225
diff changeset
   356
    by (auto simp add: zero_le_mult_iff zero_le_even_power)
21263
wenzelm
parents: 21256
diff changeset
   357
qed
wenzelm
parents: 21256
diff changeset
   358
21256
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   359
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   360
subsection {* Miscellaneous *}
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   361
23522
7e8255828502 Tuned proofs
chaieb
parents: 23438
diff changeset
   362
lemma [presburger]:"(x + 1) div 2 = x div 2 \<longleftrightarrow> even (x::int)" by presburger
7e8255828502 Tuned proofs
chaieb
parents: 23438
diff changeset
   363
lemma [presburger]: "(x + 1) div 2 = x div 2 + 1 \<longleftrightarrow> odd (x::int)" by presburger
7e8255828502 Tuned proofs
chaieb
parents: 23438
diff changeset
   364
lemma even_plus_one_div_two: "even (x::int) ==> (x + 1) div 2 = x div 2"  by presburger
7e8255828502 Tuned proofs
chaieb
parents: 23438
diff changeset
   365
lemma odd_plus_one_div_two: "odd (x::int) ==> (x + 1) div 2 = x div 2 + 1" by presburger
21256
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   366
23522
7e8255828502 Tuned proofs
chaieb
parents: 23438
diff changeset
   367
lemma [presburger]: "(Suc x) div Suc (Suc 0) = x div Suc (Suc 0) \<longleftrightarrow> even x" by presburger
21263
wenzelm
parents: 21256
diff changeset
   368
lemma even_nat_plus_one_div_two: "even (x::nat) ==>
23522
7e8255828502 Tuned proofs
chaieb
parents: 23438
diff changeset
   369
    (Suc x) div Suc (Suc 0) = x div Suc (Suc 0)" by presburger
21256
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   370
21263
wenzelm
parents: 21256
diff changeset
   371
lemma odd_nat_plus_one_div_two: "odd (x::nat) ==>
23522
7e8255828502 Tuned proofs
chaieb
parents: 23438
diff changeset
   372
    (Suc x) div Suc (Suc 0) = Suc (x div Suc (Suc 0))" by presburger
21256
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   373
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   374
end
54227
63b441f49645 moving generic lemmas out of theory parity, disregarding some unused auxiliary lemmas;
haftmann
parents: 47225
diff changeset
   375