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