src/HOL/Parity.thy
author paulson <lp15@cam.ac.uk>
Mon, 28 Aug 2017 20:33:08 +0100
changeset 66537 e2249cd6df67
parent 64785 ae0bbc8e45ad
child 66582 2b49d4888cb8
permissions -rw-r--r--
sorted out cases in negligible_standard_hyperplane
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
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60562
diff changeset
     6
section \<open>Parity in rings and semirings\<close>
21256
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
64785
ae0bbc8e45ad moved euclidean ring to HOL
haftmann
parents: 63654
diff changeset
     9
  imports Nat_Transfer Euclidean_Division
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
61799
4cf66f21b764 isabelle update_cartouches -c -t;
wenzelm
parents: 61531
diff changeset
    12
subsection \<open>Ring structures with parity and \<open>even\<close>/\<open>odd\<close> predicates\<close>
58678
398e05aa84d4 purely algebraic characterization of even and odd
haftmann
parents: 58645
diff changeset
    13
60562
24af00b010cf Amalgamation of the class comm_semiring_1_diff_distrib into comm_semiring_1_cancel. Moving axiom le_add_diff_inverse2 from semiring_numeral_div to linordered_semidom.
paulson <lp15@cam.ac.uk>
parents: 60343
diff changeset
    14
class semiring_parity = comm_semiring_1_cancel + numeral +
58787
af9eb5e566dd eliminated redundancies;
haftmann
parents: 58778
diff changeset
    15
  assumes odd_one [simp]: "\<not> 2 dvd 1"
af9eb5e566dd eliminated redundancies;
haftmann
parents: 58778
diff changeset
    16
  assumes odd_even_add: "\<not> 2 dvd a \<Longrightarrow> \<not> 2 dvd b \<Longrightarrow> 2 dvd a + b"
af9eb5e566dd eliminated redundancies;
haftmann
parents: 58778
diff changeset
    17
  assumes even_multD: "2 dvd a * b \<Longrightarrow> 2 dvd a \<or> 2 dvd b"
af9eb5e566dd eliminated redundancies;
haftmann
parents: 58778
diff changeset
    18
  assumes odd_ex_decrement: "\<not> 2 dvd a \<Longrightarrow> \<exists>b. a = b + 1"
54227
63b441f49645 moving generic lemmas out of theory parity, disregarding some unused auxiliary lemmas;
haftmann
parents: 47225
diff changeset
    19
begin
21256
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
    20
59816
034b13f4efae distributivity of partial minus establishes desired properties of dvd in semirings
haftmann
parents: 58889
diff changeset
    21
subclass semiring_numeral ..
034b13f4efae distributivity of partial minus establishes desired properties of dvd in semirings
haftmann
parents: 58889
diff changeset
    22
58740
cb9d84d3e7f2 turn even into an abbreviation
haftmann
parents: 58718
diff changeset
    23
abbreviation even :: "'a \<Rightarrow> bool"
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
    24
  where "even a \<equiv> 2 dvd a"
54228
229282d53781 purely algebraic foundation for even/odd
haftmann
parents: 54227
diff changeset
    25
58678
398e05aa84d4 purely algebraic characterization of even and odd
haftmann
parents: 58645
diff changeset
    26
abbreviation odd :: "'a \<Rightarrow> bool"
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
    27
  where "odd a \<equiv> \<not> 2 dvd a"
58678
398e05aa84d4 purely algebraic characterization of even and odd
haftmann
parents: 58645
diff changeset
    28
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
    29
lemma even_zero [simp]: "even 0"
58787
af9eb5e566dd eliminated redundancies;
haftmann
parents: 58778
diff changeset
    30
  by (fact dvd_0_right)
af9eb5e566dd eliminated redundancies;
haftmann
parents: 58778
diff changeset
    31
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
    32
lemma even_plus_one_iff [simp]: "even (a + 1) \<longleftrightarrow> odd a"
58787
af9eb5e566dd eliminated redundancies;
haftmann
parents: 58778
diff changeset
    33
  by (auto simp add: dvd_add_right_iff intro: odd_even_add)
af9eb5e566dd eliminated redundancies;
haftmann
parents: 58778
diff changeset
    34
58690
5c5c14844738 standard elimination rule for even
haftmann
parents: 58689
diff changeset
    35
lemma evenE [elim?]:
5c5c14844738 standard elimination rule for even
haftmann
parents: 58689
diff changeset
    36
  assumes "even a"
5c5c14844738 standard elimination rule for even
haftmann
parents: 58689
diff changeset
    37
  obtains b where "a = 2 * b"
58740
cb9d84d3e7f2 turn even into an abbreviation
haftmann
parents: 58718
diff changeset
    38
  using assms by (rule dvdE)
58690
5c5c14844738 standard elimination rule for even
haftmann
parents: 58689
diff changeset
    39
58681
a478a0742a8e legacy cleanup
haftmann
parents: 58680
diff changeset
    40
lemma oddE [elim?]:
58680
6b2fa479945f more algebraic deductions for facts on even/odd
haftmann
parents: 58679
diff changeset
    41
  assumes "odd a"
6b2fa479945f more algebraic deductions for facts on even/odd
haftmann
parents: 58679
diff changeset
    42
  obtains b where "a = 2 * b + 1"
58787
af9eb5e566dd eliminated redundancies;
haftmann
parents: 58778
diff changeset
    43
proof -
af9eb5e566dd eliminated redundancies;
haftmann
parents: 58778
diff changeset
    44
  from assms obtain b where *: "a = b + 1"
af9eb5e566dd eliminated redundancies;
haftmann
parents: 58778
diff changeset
    45
    by (blast dest: odd_ex_decrement)
af9eb5e566dd eliminated redundancies;
haftmann
parents: 58778
diff changeset
    46
  with assms have "even (b + 2)" by simp
af9eb5e566dd eliminated redundancies;
haftmann
parents: 58778
diff changeset
    47
  then have "even b" by simp
af9eb5e566dd eliminated redundancies;
haftmann
parents: 58778
diff changeset
    48
  then obtain c where "b = 2 * c" ..
af9eb5e566dd eliminated redundancies;
haftmann
parents: 58778
diff changeset
    49
  with * have "a = 2 * c + 1" by simp
af9eb5e566dd eliminated redundancies;
haftmann
parents: 58778
diff changeset
    50
  with that show thesis .
af9eb5e566dd eliminated redundancies;
haftmann
parents: 58778
diff changeset
    51
qed
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
    52
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
    53
lemma even_times_iff [simp]: "even (a * b) \<longleftrightarrow> even a \<or> even b"
58787
af9eb5e566dd eliminated redundancies;
haftmann
parents: 58778
diff changeset
    54
  by (auto dest: even_multD)
58678
398e05aa84d4 purely algebraic characterization of even and odd
haftmann
parents: 58645
diff changeset
    55
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
    56
lemma even_numeral [simp]: "even (numeral (Num.Bit0 n))"
58678
398e05aa84d4 purely algebraic characterization of even and odd
haftmann
parents: 58645
diff changeset
    57
proof -
398e05aa84d4 purely algebraic characterization of even and odd
haftmann
parents: 58645
diff changeset
    58
  have "even (2 * numeral n)"
58740
cb9d84d3e7f2 turn even into an abbreviation
haftmann
parents: 58718
diff changeset
    59
    unfolding even_times_iff by simp
58678
398e05aa84d4 purely algebraic characterization of even and odd
haftmann
parents: 58645
diff changeset
    60
  then have "even (numeral n + numeral n)"
398e05aa84d4 purely algebraic characterization of even and odd
haftmann
parents: 58645
diff changeset
    61
    unfolding mult_2 .
398e05aa84d4 purely algebraic characterization of even and odd
haftmann
parents: 58645
diff changeset
    62
  then show ?thesis
398e05aa84d4 purely algebraic characterization of even and odd
haftmann
parents: 58645
diff changeset
    63
    unfolding numeral.simps .
398e05aa84d4 purely algebraic characterization of even and odd
haftmann
parents: 58645
diff changeset
    64
qed
398e05aa84d4 purely algebraic characterization of even and odd
haftmann
parents: 58645
diff changeset
    65
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
    66
lemma odd_numeral [simp]: "odd (numeral (Num.Bit1 n))"
58678
398e05aa84d4 purely algebraic characterization of even and odd
haftmann
parents: 58645
diff changeset
    67
proof
398e05aa84d4 purely algebraic characterization of even and odd
haftmann
parents: 58645
diff changeset
    68
  assume "even (numeral (num.Bit1 n))"
398e05aa84d4 purely algebraic characterization of even and odd
haftmann
parents: 58645
diff changeset
    69
  then have "even (numeral n + numeral n + 1)"
398e05aa84d4 purely algebraic characterization of even and odd
haftmann
parents: 58645
diff changeset
    70
    unfolding numeral.simps .
398e05aa84d4 purely algebraic characterization of even and odd
haftmann
parents: 58645
diff changeset
    71
  then have "even (2 * numeral n + 1)"
398e05aa84d4 purely algebraic characterization of even and odd
haftmann
parents: 58645
diff changeset
    72
    unfolding mult_2 .
398e05aa84d4 purely algebraic characterization of even and odd
haftmann
parents: 58645
diff changeset
    73
  then have "2 dvd numeral n * 2 + 1"
58740
cb9d84d3e7f2 turn even into an abbreviation
haftmann
parents: 58718
diff changeset
    74
    by (simp add: ac_simps)
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
    75
  then have "2 dvd 1"
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
    76
    using dvd_add_times_triv_left_iff [of 2 "numeral n" 1] by simp
58678
398e05aa84d4 purely algebraic characterization of even and odd
haftmann
parents: 58645
diff changeset
    77
  then show False by simp
398e05aa84d4 purely algebraic characterization of even and odd
haftmann
parents: 58645
diff changeset
    78
qed
398e05aa84d4 purely algebraic characterization of even and odd
haftmann
parents: 58645
diff changeset
    79
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
    80
lemma even_add [simp]: "even (a + b) \<longleftrightarrow> (even a \<longleftrightarrow> even b)"
58787
af9eb5e566dd eliminated redundancies;
haftmann
parents: 58778
diff changeset
    81
  by (auto simp add: dvd_add_right_iff dvd_add_left_iff odd_even_add)
58680
6b2fa479945f more algebraic deductions for facts on even/odd
haftmann
parents: 58679
diff changeset
    82
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
    83
lemma odd_add [simp]: "odd (a + b) \<longleftrightarrow> (\<not> (odd a \<longleftrightarrow> odd b))"
58680
6b2fa479945f more algebraic deductions for facts on even/odd
haftmann
parents: 58679
diff changeset
    84
  by simp
6b2fa479945f more algebraic deductions for facts on even/odd
haftmann
parents: 58679
diff changeset
    85
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
    86
lemma even_power [simp]: "even (a ^ n) \<longleftrightarrow> even a \<and> n > 0"
58680
6b2fa479945f more algebraic deductions for facts on even/odd
haftmann
parents: 58679
diff changeset
    87
  by (induct n) auto
6b2fa479945f more algebraic deductions for facts on even/odd
haftmann
parents: 58679
diff changeset
    88
58678
398e05aa84d4 purely algebraic characterization of even and odd
haftmann
parents: 58645
diff changeset
    89
end
398e05aa84d4 purely algebraic characterization of even and odd
haftmann
parents: 58645
diff changeset
    90
59816
034b13f4efae distributivity of partial minus establishes desired properties of dvd in semirings
haftmann
parents: 58889
diff changeset
    91
class ring_parity = ring + semiring_parity
58679
33c90658448a more algebraic deductions for facts on even/odd
haftmann
parents: 58678
diff changeset
    92
begin
33c90658448a more algebraic deductions for facts on even/odd
haftmann
parents: 58678
diff changeset
    93
59816
034b13f4efae distributivity of partial minus establishes desired properties of dvd in semirings
haftmann
parents: 58889
diff changeset
    94
subclass comm_ring_1 ..
034b13f4efae distributivity of partial minus establishes desired properties of dvd in semirings
haftmann
parents: 58889
diff changeset
    95
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
    96
lemma even_minus [simp]: "even (- a) \<longleftrightarrow> even a"
58740
cb9d84d3e7f2 turn even into an abbreviation
haftmann
parents: 58718
diff changeset
    97
  by (fact dvd_minus_iff)
58679
33c90658448a more algebraic deductions for facts on even/odd
haftmann
parents: 58678
diff changeset
    98
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
    99
lemma even_diff [simp]: "even (a - b) \<longleftrightarrow> even (a + b)"
58680
6b2fa479945f more algebraic deductions for facts on even/odd
haftmann
parents: 58679
diff changeset
   100
  using even_add [of a "- b"] by simp
6b2fa479945f more algebraic deductions for facts on even/odd
haftmann
parents: 58679
diff changeset
   101
58679
33c90658448a more algebraic deductions for facts on even/odd
haftmann
parents: 58678
diff changeset
   102
end
33c90658448a more algebraic deductions for facts on even/odd
haftmann
parents: 58678
diff changeset
   103
58710
7216a10d69ba augmented and tuned facts on even/odd and division
haftmann
parents: 58709
diff changeset
   104
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60562
diff changeset
   105
subsection \<open>Instances for @{typ nat} and @{typ int}\<close>
58787
af9eb5e566dd eliminated redundancies;
haftmann
parents: 58778
diff changeset
   106
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   107
lemma even_Suc_Suc_iff [simp]: "2 dvd Suc (Suc n) \<longleftrightarrow> 2 dvd n"
58787
af9eb5e566dd eliminated redundancies;
haftmann
parents: 58778
diff changeset
   108
  using dvd_add_triv_right_iff [of 2 n] by simp
58687
5469874b0228 even more cleanup
haftmann
parents: 58681
diff changeset
   109
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   110
lemma even_Suc [simp]: "2 dvd Suc n \<longleftrightarrow> \<not> 2 dvd n"
58787
af9eb5e566dd eliminated redundancies;
haftmann
parents: 58778
diff changeset
   111
  by (induct n) auto
af9eb5e566dd eliminated redundancies;
haftmann
parents: 58778
diff changeset
   112
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   113
lemma even_diff_nat [simp]: "2 dvd (m - n) \<longleftrightarrow> m < n \<or> 2 dvd (m + n)"
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   114
  for m n :: nat
58787
af9eb5e566dd eliminated redundancies;
haftmann
parents: 58778
diff changeset
   115
proof (cases "n \<le> m")
af9eb5e566dd eliminated redundancies;
haftmann
parents: 58778
diff changeset
   116
  case True
af9eb5e566dd eliminated redundancies;
haftmann
parents: 58778
diff changeset
   117
  then have "m - n + n * 2 = m + n" by (simp add: mult_2_right)
60343
063698416239 correct sort constraints for abbreviations in type classes
haftmann
parents: 59816
diff changeset
   118
  moreover have "2 dvd (m - n) \<longleftrightarrow> 2 dvd (m - n + n * 2)" by simp
063698416239 correct sort constraints for abbreviations in type classes
haftmann
parents: 59816
diff changeset
   119
  ultimately have "2 dvd (m - n) \<longleftrightarrow> 2 dvd (m + n)" by (simp only:)
58787
af9eb5e566dd eliminated redundancies;
haftmann
parents: 58778
diff changeset
   120
  then show ?thesis by auto
af9eb5e566dd eliminated redundancies;
haftmann
parents: 58778
diff changeset
   121
next
af9eb5e566dd eliminated redundancies;
haftmann
parents: 58778
diff changeset
   122
  case False
af9eb5e566dd eliminated redundancies;
haftmann
parents: 58778
diff changeset
   123
  then show ?thesis by simp
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   124
qed
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   125
58787
af9eb5e566dd eliminated redundancies;
haftmann
parents: 58778
diff changeset
   126
instance nat :: semiring_parity
af9eb5e566dd eliminated redundancies;
haftmann
parents: 58778
diff changeset
   127
proof
60343
063698416239 correct sort constraints for abbreviations in type classes
haftmann
parents: 59816
diff changeset
   128
  show "\<not> 2 dvd (1 :: nat)"
58787
af9eb5e566dd eliminated redundancies;
haftmann
parents: 58778
diff changeset
   129
    by (rule notI, erule dvdE) simp
af9eb5e566dd eliminated redundancies;
haftmann
parents: 58778
diff changeset
   130
next
af9eb5e566dd eliminated redundancies;
haftmann
parents: 58778
diff changeset
   131
  fix m n :: nat
60343
063698416239 correct sort constraints for abbreviations in type classes
haftmann
parents: 59816
diff changeset
   132
  assume "\<not> 2 dvd m"
063698416239 correct sort constraints for abbreviations in type classes
haftmann
parents: 59816
diff changeset
   133
  moreover assume "\<not> 2 dvd n"
063698416239 correct sort constraints for abbreviations in type classes
haftmann
parents: 59816
diff changeset
   134
  ultimately have *: "2 dvd Suc m \<and> 2 dvd Suc n"
58787
af9eb5e566dd eliminated redundancies;
haftmann
parents: 58778
diff changeset
   135
    by simp
60343
063698416239 correct sort constraints for abbreviations in type classes
haftmann
parents: 59816
diff changeset
   136
  then have "2 dvd (Suc m + Suc n)"
58787
af9eb5e566dd eliminated redundancies;
haftmann
parents: 58778
diff changeset
   137
    by (blast intro: dvd_add)
af9eb5e566dd eliminated redundancies;
haftmann
parents: 58778
diff changeset
   138
  also have "Suc m + Suc n = m + n + 2"
af9eb5e566dd eliminated redundancies;
haftmann
parents: 58778
diff changeset
   139
    by simp
60343
063698416239 correct sort constraints for abbreviations in type classes
haftmann
parents: 59816
diff changeset
   140
  finally show "2 dvd (m + n)"
58787
af9eb5e566dd eliminated redundancies;
haftmann
parents: 58778
diff changeset
   141
    using dvd_add_triv_right_iff [of 2 "m + n"] by simp
af9eb5e566dd eliminated redundancies;
haftmann
parents: 58778
diff changeset
   142
next
af9eb5e566dd eliminated redundancies;
haftmann
parents: 58778
diff changeset
   143
  fix m n :: nat
60343
063698416239 correct sort constraints for abbreviations in type classes
haftmann
parents: 59816
diff changeset
   144
  assume *: "2 dvd (m * n)"
063698416239 correct sort constraints for abbreviations in type classes
haftmann
parents: 59816
diff changeset
   145
  show "2 dvd m \<or> 2 dvd n"
58787
af9eb5e566dd eliminated redundancies;
haftmann
parents: 58778
diff changeset
   146
  proof (rule disjCI)
60343
063698416239 correct sort constraints for abbreviations in type classes
haftmann
parents: 59816
diff changeset
   147
    assume "\<not> 2 dvd n"
063698416239 correct sort constraints for abbreviations in type classes
haftmann
parents: 59816
diff changeset
   148
    then have "2 dvd (Suc n)" by simp
58787
af9eb5e566dd eliminated redundancies;
haftmann
parents: 58778
diff changeset
   149
    then obtain r where "Suc n = 2 * r" ..
af9eb5e566dd eliminated redundancies;
haftmann
parents: 58778
diff changeset
   150
    moreover from * obtain s where "m * n = 2 * s" ..
af9eb5e566dd eliminated redundancies;
haftmann
parents: 58778
diff changeset
   151
    then have "2 * s + m = m * Suc n" by simp
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   152
    ultimately have " 2 * s + m = 2 * (m * r)"
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   153
      by (simp add: algebra_simps)
58787
af9eb5e566dd eliminated redundancies;
haftmann
parents: 58778
diff changeset
   154
    then have "m = 2 * (m * r - s)" by simp
60343
063698416239 correct sort constraints for abbreviations in type classes
haftmann
parents: 59816
diff changeset
   155
    then show "2 dvd m" ..
58787
af9eb5e566dd eliminated redundancies;
haftmann
parents: 58778
diff changeset
   156
  qed
af9eb5e566dd eliminated redundancies;
haftmann
parents: 58778
diff changeset
   157
next
af9eb5e566dd eliminated redundancies;
haftmann
parents: 58778
diff changeset
   158
  fix n :: nat
60343
063698416239 correct sort constraints for abbreviations in type classes
haftmann
parents: 59816
diff changeset
   159
  assume "\<not> 2 dvd n"
58787
af9eb5e566dd eliminated redundancies;
haftmann
parents: 58778
diff changeset
   160
  then show "\<exists>m. n = m + 1"
af9eb5e566dd eliminated redundancies;
haftmann
parents: 58778
diff changeset
   161
    by (cases n) simp_all
af9eb5e566dd eliminated redundancies;
haftmann
parents: 58778
diff changeset
   162
qed
58687
5469874b0228 even more cleanup
haftmann
parents: 58681
diff changeset
   163
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   164
lemma odd_pos: "odd n \<Longrightarrow> 0 < n"
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   165
  for n :: nat
58690
5c5c14844738 standard elimination rule for even
haftmann
parents: 58689
diff changeset
   166
  by (auto elim: oddE)
60343
063698416239 correct sort constraints for abbreviations in type classes
haftmann
parents: 59816
diff changeset
   167
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   168
lemma Suc_double_not_eq_double: "Suc (2 * m) \<noteq> 2 * n"
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   169
  for m n :: nat
62597
b3f2b8c906a6 model characters directly as range 0..255
haftmann
parents: 62083
diff changeset
   170
proof
b3f2b8c906a6 model characters directly as range 0..255
haftmann
parents: 62083
diff changeset
   171
  assume "Suc (2 * m) = 2 * n"
b3f2b8c906a6 model characters directly as range 0..255
haftmann
parents: 62083
diff changeset
   172
  moreover have "odd (Suc (2 * m))" and "even (2 * n)"
b3f2b8c906a6 model characters directly as range 0..255
haftmann
parents: 62083
diff changeset
   173
    by simp_all
b3f2b8c906a6 model characters directly as range 0..255
haftmann
parents: 62083
diff changeset
   174
  ultimately show False by simp
b3f2b8c906a6 model characters directly as range 0..255
haftmann
parents: 62083
diff changeset
   175
qed
b3f2b8c906a6 model characters directly as range 0..255
haftmann
parents: 62083
diff changeset
   176
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   177
lemma double_not_eq_Suc_double: "2 * m \<noteq> Suc (2 * n)"
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   178
  for m n :: nat
62597
b3f2b8c906a6 model characters directly as range 0..255
haftmann
parents: 62083
diff changeset
   179
  using Suc_double_not_eq_double [of n m] by simp
b3f2b8c906a6 model characters directly as range 0..255
haftmann
parents: 62083
diff changeset
   180
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   181
lemma even_diff_iff [simp]: "2 dvd (k - l) \<longleftrightarrow> 2 dvd (k + l)"
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   182
  for k l :: int
60343
063698416239 correct sort constraints for abbreviations in type classes
haftmann
parents: 59816
diff changeset
   183
  using dvd_add_times_triv_right_iff [of 2 "k - l" l] by (simp add: mult_2_right)
063698416239 correct sort constraints for abbreviations in type classes
haftmann
parents: 59816
diff changeset
   184
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   185
lemma even_abs_add_iff [simp]: "2 dvd (\<bar>k\<bar> + l) \<longleftrightarrow> 2 dvd (k + l)"
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   186
  for k l :: int
60343
063698416239 correct sort constraints for abbreviations in type classes
haftmann
parents: 59816
diff changeset
   187
  by (cases "k \<ge> 0") (simp_all add: ac_simps)
063698416239 correct sort constraints for abbreviations in type classes
haftmann
parents: 59816
diff changeset
   188
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   189
lemma even_add_abs_iff [simp]: "2 dvd (k + \<bar>l\<bar>) \<longleftrightarrow> 2 dvd (k + l)"
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   190
  for k l :: int
60343
063698416239 correct sort constraints for abbreviations in type classes
haftmann
parents: 59816
diff changeset
   191
  using even_abs_add_iff [of l k] by (simp add: ac_simps)
063698416239 correct sort constraints for abbreviations in type classes
haftmann
parents: 59816
diff changeset
   192
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   193
lemma odd_Suc_minus_one [simp]: "odd n \<Longrightarrow> Suc (n - Suc 0) = n"
60867
86e7560e07d0 slight cleanup of lemmas
haftmann
parents: 60758
diff changeset
   194
  by (auto elim: oddE)
86e7560e07d0 slight cleanup of lemmas
haftmann
parents: 60758
diff changeset
   195
58787
af9eb5e566dd eliminated redundancies;
haftmann
parents: 58778
diff changeset
   196
instance int :: ring_parity
af9eb5e566dd eliminated redundancies;
haftmann
parents: 58778
diff changeset
   197
proof
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   198
  show "\<not> 2 dvd (1 :: int)"
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   199
    by (simp add: dvd_int_unfold_dvd_nat)
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   200
next
58787
af9eb5e566dd eliminated redundancies;
haftmann
parents: 58778
diff changeset
   201
  fix k l :: int
60343
063698416239 correct sort constraints for abbreviations in type classes
haftmann
parents: 59816
diff changeset
   202
  assume "\<not> 2 dvd k"
063698416239 correct sort constraints for abbreviations in type classes
haftmann
parents: 59816
diff changeset
   203
  moreover assume "\<not> 2 dvd l"
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   204
  ultimately have "2 dvd (nat \<bar>k\<bar> + nat \<bar>l\<bar>)"
58787
af9eb5e566dd eliminated redundancies;
haftmann
parents: 58778
diff changeset
   205
    by (auto simp add: dvd_int_unfold_dvd_nat intro: odd_even_add)
60343
063698416239 correct sort constraints for abbreviations in type classes
haftmann
parents: 59816
diff changeset
   206
  then have "2 dvd (\<bar>k\<bar> + \<bar>l\<bar>)"
58787
af9eb5e566dd eliminated redundancies;
haftmann
parents: 58778
diff changeset
   207
    by (simp add: dvd_int_unfold_dvd_nat nat_add_distrib)
60343
063698416239 correct sort constraints for abbreviations in type classes
haftmann
parents: 59816
diff changeset
   208
  then show "2 dvd (k + l)"
58787
af9eb5e566dd eliminated redundancies;
haftmann
parents: 58778
diff changeset
   209
    by simp
af9eb5e566dd eliminated redundancies;
haftmann
parents: 58778
diff changeset
   210
next
af9eb5e566dd eliminated redundancies;
haftmann
parents: 58778
diff changeset
   211
  fix k l :: int
60343
063698416239 correct sort constraints for abbreviations in type classes
haftmann
parents: 59816
diff changeset
   212
  assume "2 dvd (k * l)"
063698416239 correct sort constraints for abbreviations in type classes
haftmann
parents: 59816
diff changeset
   213
  then show "2 dvd k \<or> 2 dvd l"
58787
af9eb5e566dd eliminated redundancies;
haftmann
parents: 58778
diff changeset
   214
    by (simp add: dvd_int_unfold_dvd_nat even_multD nat_abs_mult_distrib)
af9eb5e566dd eliminated redundancies;
haftmann
parents: 58778
diff changeset
   215
next
af9eb5e566dd eliminated redundancies;
haftmann
parents: 58778
diff changeset
   216
  fix k :: int
af9eb5e566dd eliminated redundancies;
haftmann
parents: 58778
diff changeset
   217
  have "k = (k - 1) + 1" by simp
af9eb5e566dd eliminated redundancies;
haftmann
parents: 58778
diff changeset
   218
  then show "\<exists>l. k = l + 1" ..
af9eb5e566dd eliminated redundancies;
haftmann
parents: 58778
diff changeset
   219
qed
58680
6b2fa479945f more algebraic deductions for facts on even/odd
haftmann
parents: 58679
diff changeset
   220
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   221
lemma even_int_iff [simp]: "even (int n) \<longleftrightarrow> even n"
58740
cb9d84d3e7f2 turn even into an abbreviation
haftmann
parents: 58718
diff changeset
   222
  by (simp add: dvd_int_iff)
33318
ddd97d9dfbfb moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents: 31718
diff changeset
   223
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   224
lemma even_nat_iff: "0 \<le> k \<Longrightarrow> even (nat k) \<longleftrightarrow> even k"
58687
5469874b0228 even more cleanup
haftmann
parents: 58681
diff changeset
   225
  by (simp add: even_int_iff [symmetric])
5469874b0228 even more cleanup
haftmann
parents: 58681
diff changeset
   226
5469874b0228 even more cleanup
haftmann
parents: 58681
diff changeset
   227
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60562
diff changeset
   228
subsection \<open>Parity and powers\<close>
58689
ee5bf401cfa7 tuned facts on even and power
haftmann
parents: 58688
diff changeset
   229
61531
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 60867
diff changeset
   230
context ring_1
58689
ee5bf401cfa7 tuned facts on even and power
haftmann
parents: 58688
diff changeset
   231
begin
ee5bf401cfa7 tuned facts on even and power
haftmann
parents: 58688
diff changeset
   232
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   233
lemma power_minus_even [simp]: "even n \<Longrightarrow> (- a) ^ n = a ^ n"
58690
5c5c14844738 standard elimination rule for even
haftmann
parents: 58689
diff changeset
   234
  by (auto elim: evenE)
58689
ee5bf401cfa7 tuned facts on even and power
haftmann
parents: 58688
diff changeset
   235
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   236
lemma power_minus_odd [simp]: "odd n \<Longrightarrow> (- a) ^ n = - (a ^ n)"
58690
5c5c14844738 standard elimination rule for even
haftmann
parents: 58689
diff changeset
   237
  by (auto elim: oddE)
5c5c14844738 standard elimination rule for even
haftmann
parents: 58689
diff changeset
   238
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   239
lemma neg_one_even_power [simp]: "even n \<Longrightarrow> (- 1) ^ n = 1"
58690
5c5c14844738 standard elimination rule for even
haftmann
parents: 58689
diff changeset
   240
  by simp
58689
ee5bf401cfa7 tuned facts on even and power
haftmann
parents: 58688
diff changeset
   241
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   242
lemma neg_one_odd_power [simp]: "odd n \<Longrightarrow> (- 1) ^ n = - 1"
58690
5c5c14844738 standard elimination rule for even
haftmann
parents: 58689
diff changeset
   243
  by simp
58689
ee5bf401cfa7 tuned facts on even and power
haftmann
parents: 58688
diff changeset
   244
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   245
end
58689
ee5bf401cfa7 tuned facts on even and power
haftmann
parents: 58688
diff changeset
   246
ee5bf401cfa7 tuned facts on even and power
haftmann
parents: 58688
diff changeset
   247
context linordered_idom
ee5bf401cfa7 tuned facts on even and power
haftmann
parents: 58688
diff changeset
   248
begin
ee5bf401cfa7 tuned facts on even and power
haftmann
parents: 58688
diff changeset
   249
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   250
lemma zero_le_even_power: "even n \<Longrightarrow> 0 \<le> a ^ n"
58690
5c5c14844738 standard elimination rule for even
haftmann
parents: 58689
diff changeset
   251
  by (auto elim: evenE)
58689
ee5bf401cfa7 tuned facts on even and power
haftmann
parents: 58688
diff changeset
   252
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   253
lemma zero_le_odd_power: "odd n \<Longrightarrow> 0 \<le> a ^ n \<longleftrightarrow> 0 \<le> a"
58689
ee5bf401cfa7 tuned facts on even and power
haftmann
parents: 58688
diff changeset
   254
  by (auto simp add: power_even_eq zero_le_mult_iff elim: oddE)
ee5bf401cfa7 tuned facts on even and power
haftmann
parents: 58688
diff changeset
   255
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   256
lemma zero_le_power_eq: "0 \<le> a ^ n \<longleftrightarrow> even n \<or> odd n \<and> 0 \<le> a"
58787
af9eb5e566dd eliminated redundancies;
haftmann
parents: 58778
diff changeset
   257
  by (auto simp add: zero_le_even_power zero_le_odd_power)
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   258
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   259
lemma zero_less_power_eq: "0 < a ^ n \<longleftrightarrow> n = 0 \<or> even n \<and> a \<noteq> 0 \<or> odd n \<and> 0 < a"
58689
ee5bf401cfa7 tuned facts on even and power
haftmann
parents: 58688
diff changeset
   260
proof -
ee5bf401cfa7 tuned facts on even and power
haftmann
parents: 58688
diff changeset
   261
  have [simp]: "0 = a ^ n \<longleftrightarrow> a = 0 \<and> n > 0"
58787
af9eb5e566dd eliminated redundancies;
haftmann
parents: 58778
diff changeset
   262
    unfolding power_eq_0_iff [of a n, symmetric] by blast
58689
ee5bf401cfa7 tuned facts on even and power
haftmann
parents: 58688
diff changeset
   263
  show ?thesis
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   264
    unfolding less_le zero_le_power_eq by auto
58689
ee5bf401cfa7 tuned facts on even and power
haftmann
parents: 58688
diff changeset
   265
qed
ee5bf401cfa7 tuned facts on even and power
haftmann
parents: 58688
diff changeset
   266
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   267
lemma power_less_zero_eq [simp]: "a ^ n < 0 \<longleftrightarrow> odd n \<and> a < 0"
58689
ee5bf401cfa7 tuned facts on even and power
haftmann
parents: 58688
diff changeset
   268
  unfolding not_le [symmetric] zero_le_power_eq by auto
ee5bf401cfa7 tuned facts on even and power
haftmann
parents: 58688
diff changeset
   269
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   270
lemma power_le_zero_eq: "a ^ n \<le> 0 \<longleftrightarrow> n > 0 \<and> (odd n \<and> a \<le> 0 \<or> even n \<and> a = 0)"
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   271
  unfolding not_less [symmetric] zero_less_power_eq by auto
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   272
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   273
lemma power_even_abs: "even n \<Longrightarrow> \<bar>a\<bar> ^ n = a ^ n"
58689
ee5bf401cfa7 tuned facts on even and power
haftmann
parents: 58688
diff changeset
   274
  using power_abs [of a n] by (simp add: zero_le_even_power)
ee5bf401cfa7 tuned facts on even and power
haftmann
parents: 58688
diff changeset
   275
ee5bf401cfa7 tuned facts on even and power
haftmann
parents: 58688
diff changeset
   276
lemma power_mono_even:
ee5bf401cfa7 tuned facts on even and power
haftmann
parents: 58688
diff changeset
   277
  assumes "even n" and "\<bar>a\<bar> \<le> \<bar>b\<bar>"
ee5bf401cfa7 tuned facts on even and power
haftmann
parents: 58688
diff changeset
   278
  shows "a ^ n \<le> b ^ n"
ee5bf401cfa7 tuned facts on even and power
haftmann
parents: 58688
diff changeset
   279
proof -
ee5bf401cfa7 tuned facts on even and power
haftmann
parents: 58688
diff changeset
   280
  have "0 \<le> \<bar>a\<bar>" by auto
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   281
  with \<open>\<bar>a\<bar> \<le> \<bar>b\<bar>\<close> have "\<bar>a\<bar> ^ n \<le> \<bar>b\<bar> ^ n"
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   282
    by (rule power_mono)
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   283
  with \<open>even n\<close> show ?thesis
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   284
    by (simp add: power_even_abs)
58689
ee5bf401cfa7 tuned facts on even and power
haftmann
parents: 58688
diff changeset
   285
qed
ee5bf401cfa7 tuned facts on even and power
haftmann
parents: 58688
diff changeset
   286
ee5bf401cfa7 tuned facts on even and power
haftmann
parents: 58688
diff changeset
   287
lemma power_mono_odd:
ee5bf401cfa7 tuned facts on even and power
haftmann
parents: 58688
diff changeset
   288
  assumes "odd n" and "a \<le> b"
ee5bf401cfa7 tuned facts on even and power
haftmann
parents: 58688
diff changeset
   289
  shows "a ^ n \<le> b ^ n"
ee5bf401cfa7 tuned facts on even and power
haftmann
parents: 58688
diff changeset
   290
proof (cases "b < 0")
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   291
  case True
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   292
  with \<open>a \<le> b\<close> have "- b \<le> - a" and "0 \<le> - b" by auto
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   293
  then have "(- b) ^ n \<le> (- a) ^ n" by (rule power_mono)
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60562
diff changeset
   294
  with \<open>odd n\<close> show ?thesis by simp
58689
ee5bf401cfa7 tuned facts on even and power
haftmann
parents: 58688
diff changeset
   295
next
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   296
  case False
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   297
  then have "0 \<le> b" by auto
58689
ee5bf401cfa7 tuned facts on even and power
haftmann
parents: 58688
diff changeset
   298
  show ?thesis
ee5bf401cfa7 tuned facts on even and power
haftmann
parents: 58688
diff changeset
   299
  proof (cases "a < 0")
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   300
    case True
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   301
    then have "n \<noteq> 0" and "a \<le> 0" using \<open>odd n\<close> [THEN odd_pos] by auto
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60562
diff changeset
   302
    then have "a ^ n \<le> 0" unfolding power_le_zero_eq using \<open>odd n\<close> by auto
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   303
    moreover from \<open>0 \<le> b\<close> have "0 \<le> b ^ n" by auto
58689
ee5bf401cfa7 tuned facts on even and power
haftmann
parents: 58688
diff changeset
   304
    ultimately show ?thesis by auto
ee5bf401cfa7 tuned facts on even and power
haftmann
parents: 58688
diff changeset
   305
  next
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   306
    case False
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   307
    then have "0 \<le> a" by auto
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   308
    with \<open>a \<le> b\<close> show ?thesis
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   309
      using power_mono by auto
58689
ee5bf401cfa7 tuned facts on even and power
haftmann
parents: 58688
diff changeset
   310
  qed
ee5bf401cfa7 tuned facts on even and power
haftmann
parents: 58688
diff changeset
   311
qed
62083
7582b39f51ed add the proof of the central limit theorem
hoelzl
parents: 61799
diff changeset
   312
7582b39f51ed add the proof of the central limit theorem
hoelzl
parents: 61799
diff changeset
   313
lemma (in comm_ring_1) uminus_power_if: "(- x) ^ n = (if even n then x^n else - (x ^ n))"
7582b39f51ed add the proof of the central limit theorem
hoelzl
parents: 61799
diff changeset
   314
  by auto
7582b39f51ed add the proof of the central limit theorem
hoelzl
parents: 61799
diff changeset
   315
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60562
diff changeset
   316
text \<open>Simplify, when the exponent is a numeral\<close>
58689
ee5bf401cfa7 tuned facts on even and power
haftmann
parents: 58688
diff changeset
   317
ee5bf401cfa7 tuned facts on even and power
haftmann
parents: 58688
diff changeset
   318
lemma zero_le_power_eq_numeral [simp]:
ee5bf401cfa7 tuned facts on even and power
haftmann
parents: 58688
diff changeset
   319
  "0 \<le> a ^ numeral w \<longleftrightarrow> even (numeral w :: nat) \<or> odd (numeral w :: nat) \<and> 0 \<le> a"
ee5bf401cfa7 tuned facts on even and power
haftmann
parents: 58688
diff changeset
   320
  by (fact zero_le_power_eq)
ee5bf401cfa7 tuned facts on even and power
haftmann
parents: 58688
diff changeset
   321
ee5bf401cfa7 tuned facts on even and power
haftmann
parents: 58688
diff changeset
   322
lemma zero_less_power_eq_numeral [simp]:
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   323
  "0 < a ^ numeral w \<longleftrightarrow>
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   324
    numeral w = (0 :: nat) \<or>
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   325
    even (numeral w :: nat) \<and> a \<noteq> 0 \<or>
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   326
    odd (numeral w :: nat) \<and> 0 < a"
58689
ee5bf401cfa7 tuned facts on even and power
haftmann
parents: 58688
diff changeset
   327
  by (fact zero_less_power_eq)
ee5bf401cfa7 tuned facts on even and power
haftmann
parents: 58688
diff changeset
   328
ee5bf401cfa7 tuned facts on even and power
haftmann
parents: 58688
diff changeset
   329
lemma power_le_zero_eq_numeral [simp]:
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   330
  "a ^ numeral w \<le> 0 \<longleftrightarrow>
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   331
    (0 :: nat) < numeral w \<and>
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   332
    (odd (numeral w :: nat) \<and> a \<le> 0 \<or> even (numeral w :: nat) \<and> a = 0)"
58689
ee5bf401cfa7 tuned facts on even and power
haftmann
parents: 58688
diff changeset
   333
  by (fact power_le_zero_eq)
ee5bf401cfa7 tuned facts on even and power
haftmann
parents: 58688
diff changeset
   334
ee5bf401cfa7 tuned facts on even and power
haftmann
parents: 58688
diff changeset
   335
lemma power_less_zero_eq_numeral [simp]:
ee5bf401cfa7 tuned facts on even and power
haftmann
parents: 58688
diff changeset
   336
  "a ^ numeral w < 0 \<longleftrightarrow> odd (numeral w :: nat) \<and> a < 0"
ee5bf401cfa7 tuned facts on even and power
haftmann
parents: 58688
diff changeset
   337
  by (fact power_less_zero_eq)
ee5bf401cfa7 tuned facts on even and power
haftmann
parents: 58688
diff changeset
   338
ee5bf401cfa7 tuned facts on even and power
haftmann
parents: 58688
diff changeset
   339
lemma power_even_abs_numeral [simp]:
ee5bf401cfa7 tuned facts on even and power
haftmann
parents: 58688
diff changeset
   340
  "even (numeral w :: nat) \<Longrightarrow> \<bar>a\<bar> ^ numeral w = a ^ numeral w"
ee5bf401cfa7 tuned facts on even and power
haftmann
parents: 58688
diff changeset
   341
  by (fact power_even_abs)
ee5bf401cfa7 tuned facts on even and power
haftmann
parents: 58688
diff changeset
   342
ee5bf401cfa7 tuned facts on even and power
haftmann
parents: 58688
diff changeset
   343
end
ee5bf401cfa7 tuned facts on even and power
haftmann
parents: 58688
diff changeset
   344
ee5bf401cfa7 tuned facts on even and power
haftmann
parents: 58688
diff changeset
   345
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   346
subsubsection \<open>Tool setup\<close>
58687
5469874b0228 even more cleanup
haftmann
parents: 58681
diff changeset
   347
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 62597
diff changeset
   348
declare transfer_morphism_int_nat [transfer add return: even_int_iff]
21256
47195501ecf7 moved theories Parity, GCD, Binomial to Library;
wenzelm
parents:
diff changeset
   349
58770
ae5e9b4f8daf downshift of theory Parity in the hierarchy
haftmann
parents: 58769
diff changeset
   350
end