src/HOL/Parity.thy
author haftmann
Thu Oct 23 19:40:41 2014 +0200 (2014-10-23)
changeset 58778 e29cae8eab1f
parent 58777 6ba2f1fa243b
child 58787 af9eb5e566dd
permissions -rw-r--r--
even further downshift of theory Parity in the hierarchy
wenzelm@41959
     1
(*  Title:      HOL/Parity.thy
wenzelm@41959
     2
    Author:     Jeremy Avigad
wenzelm@41959
     3
    Author:     Jacques D. Fleuriot
wenzelm@21256
     4
*)
wenzelm@21256
     5
wenzelm@21256
     6
header {* Even and Odd for int and nat *}
wenzelm@21256
     7
wenzelm@21256
     8
theory Parity
haftmann@58778
     9
imports Nat_Transfer
wenzelm@21256
    10
begin
wenzelm@21256
    11
haftmann@58678
    12
subsection {* Preliminaries about divisibility on @{typ nat} and @{typ int} *}
haftmann@58678
    13
haftmann@58678
    14
lemma two_dvd_Suc_Suc_iff [simp]:
haftmann@58678
    15
  "2 dvd Suc (Suc n) \<longleftrightarrow> 2 dvd n"
haftmann@58678
    16
  using dvd_add_triv_right_iff [of 2 n] by simp
haftmann@58678
    17
haftmann@58678
    18
lemma two_dvd_Suc_iff:
haftmann@58678
    19
  "2 dvd Suc n \<longleftrightarrow> \<not> 2 dvd n"
haftmann@58678
    20
  by (induct n) auto
haftmann@58678
    21
haftmann@58687
    22
lemma two_dvd_diff_nat_iff:
haftmann@58687
    23
  fixes m n :: nat
haftmann@58687
    24
  shows "2 dvd m - n \<longleftrightarrow> m < n \<or> 2 dvd m + n"
haftmann@58687
    25
proof (cases "n \<le> m")
haftmann@58687
    26
  case True
haftmann@58770
    27
  then have "m - n + n * 2 = m + n" by (simp add: mult_2_right)
haftmann@58687
    28
  moreover have "2 dvd m - n \<longleftrightarrow> 2 dvd m - n + n * 2" by simp
haftmann@58687
    29
  ultimately have "2 dvd m - n \<longleftrightarrow> 2 dvd m + n" by (simp only:)
haftmann@58687
    30
  then show ?thesis by auto
haftmann@58687
    31
next
haftmann@58687
    32
  case False
haftmann@58687
    33
  then show ?thesis by simp
haftmann@58687
    34
qed 
haftmann@58687
    35
  
haftmann@58678
    36
lemma two_dvd_diff_iff:
haftmann@58678
    37
  fixes k l :: int
haftmann@58678
    38
  shows "2 dvd k - l \<longleftrightarrow> 2 dvd k + l"
haftmann@58777
    39
  using dvd_add_times_triv_right_iff [of 2 "k - l" l] by (simp add: mult_2_right)
haftmann@58678
    40
haftmann@58678
    41
lemma two_dvd_abs_add_iff:
haftmann@58678
    42
  fixes k l :: int
haftmann@58678
    43
  shows "2 dvd \<bar>k\<bar> + l \<longleftrightarrow> 2 dvd k + l"
haftmann@58678
    44
  by (cases "k \<ge> 0") (simp_all add: two_dvd_diff_iff ac_simps)
haftmann@58678
    45
haftmann@58678
    46
lemma two_dvd_add_abs_iff:
haftmann@58678
    47
  fixes k l :: int
haftmann@58678
    48
  shows "2 dvd k + \<bar>l\<bar> \<longleftrightarrow> 2 dvd k + l"
haftmann@58678
    49
  using two_dvd_abs_add_iff [of l k] by (simp add: ac_simps)
haftmann@58678
    50
haftmann@58678
    51
haftmann@58678
    52
subsection {* Ring structures with parity *}
haftmann@58678
    53
haftmann@58678
    54
class semiring_parity = semiring_dvd + semiring_numeral +
haftmann@58678
    55
  assumes two_not_dvd_one [simp]: "\<not> 2 dvd 1"
haftmann@58678
    56
  assumes not_dvd_not_dvd_dvd_add: "\<not> 2 dvd a \<Longrightarrow> \<not> 2 dvd b \<Longrightarrow> 2 dvd a + b"
haftmann@58678
    57
  assumes two_is_prime: "2 dvd a * b \<Longrightarrow> 2 dvd a \<or> 2 dvd b"
haftmann@58680
    58
  assumes not_dvd_ex_decrement: "\<not> 2 dvd a \<Longrightarrow> \<exists>b. a = b + 1"
haftmann@58678
    59
begin
haftmann@58678
    60
haftmann@58678
    61
lemma two_dvd_plus_one_iff [simp]:
haftmann@58678
    62
  "2 dvd a + 1 \<longleftrightarrow> \<not> 2 dvd a"
haftmann@58678
    63
  by (auto simp add: dvd_add_right_iff intro: not_dvd_not_dvd_dvd_add)
haftmann@58678
    64
haftmann@58680
    65
lemma not_two_dvdE [elim?]:
haftmann@58680
    66
  assumes "\<not> 2 dvd a"
haftmann@58680
    67
  obtains b where "a = 2 * b + 1"
haftmann@58680
    68
proof -
haftmann@58680
    69
  from assms obtain b where *: "a = b + 1"
haftmann@58680
    70
    by (blast dest: not_dvd_ex_decrement)
haftmann@58680
    71
  with assms have "2 dvd b + 2" by simp
haftmann@58680
    72
  then have "2 dvd b" by simp
haftmann@58680
    73
  then obtain c where "b = 2 * c" ..
haftmann@58680
    74
  with * have "a = 2 * c + 1" by simp
haftmann@58680
    75
  with that show thesis .
haftmann@58680
    76
qed
haftmann@58680
    77
haftmann@58678
    78
end
haftmann@58678
    79
haftmann@58678
    80
instance nat :: semiring_parity
haftmann@58678
    81
proof
haftmann@58678
    82
  show "\<not> (2 :: nat) dvd 1"
haftmann@58678
    83
    by (rule notI, erule dvdE) simp
haftmann@58678
    84
next
haftmann@58678
    85
  fix m n :: nat
haftmann@58678
    86
  assume "\<not> 2 dvd m"
haftmann@58678
    87
  moreover assume "\<not> 2 dvd n"
haftmann@58678
    88
  ultimately have *: "2 dvd Suc m \<and> 2 dvd Suc n"
haftmann@58678
    89
    by (simp add: two_dvd_Suc_iff)
haftmann@58678
    90
  then have "2 dvd Suc m + Suc n"
haftmann@58678
    91
    by (blast intro: dvd_add)
haftmann@58678
    92
  also have "Suc m + Suc n = m + n + 2"
haftmann@58678
    93
    by simp
haftmann@58678
    94
  finally show "2 dvd m + n"
haftmann@58678
    95
    using dvd_add_triv_right_iff [of 2 "m + n"] by simp
haftmann@58678
    96
next
haftmann@58678
    97
  fix m n :: nat
haftmann@58678
    98
  assume *: "2 dvd m * n"
haftmann@58678
    99
  show "2 dvd m \<or> 2 dvd n"
haftmann@58678
   100
  proof (rule disjCI)
haftmann@58678
   101
    assume "\<not> 2 dvd n"
haftmann@58678
   102
    then have "2 dvd Suc n" by (simp add: two_dvd_Suc_iff)
haftmann@58678
   103
    then obtain r where "Suc n = 2 * r" ..
haftmann@58678
   104
    moreover from * obtain s where "m * n = 2 * s" ..
haftmann@58678
   105
    then have "2 * s + m = m * Suc n" by simp
haftmann@58770
   106
    ultimately have " 2 * s + m = 2 * (m * r)" by (simp add: algebra_simps)
haftmann@58678
   107
    then have "m = 2 * (m * r - s)" by simp
haftmann@58678
   108
    then show "2 dvd m" ..
haftmann@58678
   109
  qed
haftmann@58680
   110
next
haftmann@58680
   111
  fix n :: nat
haftmann@58680
   112
  assume "\<not> 2 dvd n"
haftmann@58680
   113
  then show "\<exists>m. n = m + 1"
haftmann@58680
   114
    by (cases n) simp_all
haftmann@58678
   115
qed
haftmann@58678
   116
haftmann@58678
   117
class ring_parity = comm_ring_1 + semiring_parity
haftmann@58678
   118
haftmann@58678
   119
instance int :: ring_parity
haftmann@58678
   120
proof
haftmann@58678
   121
  show "\<not> (2 :: int) dvd 1" by (simp add: dvd_int_unfold_dvd_nat)
haftmann@58678
   122
  fix k l :: int
haftmann@58678
   123
  assume "\<not> 2 dvd k"
haftmann@58678
   124
  moreover assume "\<not> 2 dvd l"
haftmann@58678
   125
  ultimately have "2 dvd nat \<bar>k\<bar> + nat \<bar>l\<bar>" 
haftmann@58678
   126
    by (auto simp add: dvd_int_unfold_dvd_nat intro: not_dvd_not_dvd_dvd_add)
haftmann@58678
   127
  then have "2 dvd \<bar>k\<bar> + \<bar>l\<bar>"
haftmann@58678
   128
    by (simp add: dvd_int_unfold_dvd_nat nat_add_distrib)
haftmann@58678
   129
  then show "2 dvd k + l"
haftmann@58678
   130
    by (simp add: two_dvd_abs_add_iff two_dvd_add_abs_iff)
haftmann@58680
   131
next
haftmann@58680
   132
  fix k l :: int
haftmann@58680
   133
  assume "2 dvd k * l"
haftmann@58680
   134
  then show "2 dvd k \<or> 2 dvd l"
haftmann@58680
   135
    by (simp add: dvd_int_unfold_dvd_nat two_is_prime nat_abs_mult_distrib)
haftmann@58680
   136
next
haftmann@58680
   137
  fix k :: int
haftmann@58680
   138
  have "k = (k - 1) + 1" by simp
haftmann@58680
   139
  then show "\<exists>l. k = l + 1" ..
haftmann@58680
   140
qed
haftmann@58678
   141
haftmann@58678
   142
haftmann@58678
   143
subsection {* Dedicated @{text even}/@{text odd} predicate *}
haftmann@58678
   144
haftmann@58680
   145
subsubsection {* Properties *}
haftmann@58680
   146
haftmann@58678
   147
context semiring_parity
haftmann@54227
   148
begin
wenzelm@21256
   149
haftmann@58740
   150
abbreviation even :: "'a \<Rightarrow> bool"
haftmann@54228
   151
where
haftmann@58740
   152
  "even a \<equiv> 2 dvd a"
haftmann@54228
   153
haftmann@58678
   154
abbreviation odd :: "'a \<Rightarrow> bool"
haftmann@58678
   155
where
haftmann@58740
   156
  "odd a \<equiv> \<not> 2 dvd a"
haftmann@58678
   157
haftmann@58690
   158
lemma evenE [elim?]:
haftmann@58690
   159
  assumes "even a"
haftmann@58690
   160
  obtains b where "a = 2 * b"
haftmann@58740
   161
  using assms by (rule dvdE)
haftmann@58690
   162
haftmann@58681
   163
lemma oddE [elim?]:
haftmann@58680
   164
  assumes "odd a"
haftmann@58680
   165
  obtains b where "a = 2 * b + 1"
haftmann@58740
   166
  using assms by (rule not_two_dvdE)
haftmann@58680
   167
  
haftmann@58770
   168
lemma even_times_iff [simp]:
haftmann@58678
   169
  "even (a * b) \<longleftrightarrow> even a \<or> even b"
haftmann@58740
   170
  by (auto simp add: dest: two_is_prime)
haftmann@58678
   171
haftmann@58678
   172
lemma even_zero [simp]:
haftmann@58678
   173
  "even 0"
haftmann@58740
   174
  by simp
haftmann@58678
   175
haftmann@58678
   176
lemma odd_one [simp]:
haftmann@58678
   177
  "odd 1"
haftmann@58740
   178
  by simp
haftmann@58678
   179
haftmann@58678
   180
lemma even_numeral [simp]:
haftmann@58678
   181
  "even (numeral (Num.Bit0 n))"
haftmann@58678
   182
proof -
haftmann@58678
   183
  have "even (2 * numeral n)"
haftmann@58740
   184
    unfolding even_times_iff by simp
haftmann@58678
   185
  then have "even (numeral n + numeral n)"
haftmann@58678
   186
    unfolding mult_2 .
haftmann@58678
   187
  then show ?thesis
haftmann@58678
   188
    unfolding numeral.simps .
haftmann@58678
   189
qed
haftmann@58678
   190
haftmann@58678
   191
lemma odd_numeral [simp]:
haftmann@58678
   192
  "odd (numeral (Num.Bit1 n))"
haftmann@58678
   193
proof
haftmann@58678
   194
  assume "even (numeral (num.Bit1 n))"
haftmann@58678
   195
  then have "even (numeral n + numeral n + 1)"
haftmann@58678
   196
    unfolding numeral.simps .
haftmann@58678
   197
  then have "even (2 * numeral n + 1)"
haftmann@58678
   198
    unfolding mult_2 .
haftmann@58678
   199
  then have "2 dvd numeral n * 2 + 1"
haftmann@58740
   200
    by (simp add: ac_simps)
haftmann@58678
   201
  with dvd_add_times_triv_left_iff [of 2 "numeral n" 1]
haftmann@58678
   202
    have "2 dvd 1"
haftmann@58678
   203
    by simp
haftmann@58678
   204
  then show False by simp
haftmann@58678
   205
qed
haftmann@58678
   206
haftmann@58680
   207
lemma even_add [simp]:
haftmann@58680
   208
  "even (a + b) \<longleftrightarrow> (even a \<longleftrightarrow> even b)"
haftmann@58740
   209
  by (auto simp add: dvd_add_right_iff dvd_add_left_iff not_dvd_not_dvd_dvd_add)
haftmann@58680
   210
haftmann@58680
   211
lemma odd_add [simp]:
haftmann@58680
   212
  "odd (a + b) \<longleftrightarrow> (\<not> (odd a \<longleftrightarrow> odd b))"
haftmann@58680
   213
  by simp
haftmann@58680
   214
haftmann@58770
   215
lemma even_power [simp]:
haftmann@58771
   216
  "even (a ^ n) \<longleftrightarrow> even a \<and> n > 0"
haftmann@58680
   217
  by (induct n) auto
haftmann@58680
   218
haftmann@58678
   219
end
haftmann@58678
   220
haftmann@58679
   221
context ring_parity
haftmann@58679
   222
begin
haftmann@58679
   223
haftmann@58770
   224
lemma even_minus [simp]:
haftmann@58679
   225
  "even (- a) \<longleftrightarrow> even a"
haftmann@58740
   226
  by (fact dvd_minus_iff)
haftmann@58679
   227
haftmann@58680
   228
lemma even_diff [simp]:
haftmann@58680
   229
  "even (a - b) \<longleftrightarrow> even (a + b)"
haftmann@58680
   230
  using even_add [of a "- b"] by simp
haftmann@58680
   231
haftmann@58679
   232
end
haftmann@58679
   233
haftmann@58710
   234
haftmann@58687
   235
subsubsection {* Particularities for @{typ nat} and @{typ int} *}
haftmann@58687
   236
haftmann@58770
   237
lemma even_Suc [simp]:
haftmann@58687
   238
  "even (Suc n) = odd n"
haftmann@58740
   239
  by (fact two_dvd_Suc_iff)
haftmann@58687
   240
haftmann@58689
   241
lemma odd_pos: 
haftmann@58689
   242
  "odd (n :: nat) \<Longrightarrow> 0 < n"
haftmann@58690
   243
  by (auto elim: oddE)
haftmann@58689
   244
  
haftmann@58687
   245
lemma even_diff_nat [simp]:
haftmann@58687
   246
  fixes m n :: nat
haftmann@58687
   247
  shows "even (m - n) \<longleftrightarrow> m < n \<or> even (m + n)"
haftmann@58740
   248
  by (fact two_dvd_diff_nat_iff)
haftmann@58680
   249
haftmann@58679
   250
lemma even_int_iff:
haftmann@58679
   251
  "even (int n) \<longleftrightarrow> even n"
haftmann@58740
   252
  by (simp add: dvd_int_iff)
haftmann@33318
   253
haftmann@58687
   254
lemma even_nat_iff:
haftmann@58687
   255
  "0 \<le> k \<Longrightarrow> even (nat k) \<longleftrightarrow> even k"
haftmann@58687
   256
  by (simp add: even_int_iff [symmetric])
haftmann@58687
   257
haftmann@58710
   258
lemma even_num_iff:
haftmann@58710
   259
  "0 < n \<Longrightarrow> even n = odd (n - 1 :: nat)"
haftmann@58710
   260
  by simp
haftmann@58687
   261
haftmann@58710
   262
text {* Parity and powers *}
haftmann@58689
   263
haftmann@58689
   264
context comm_ring_1
haftmann@58689
   265
begin
haftmann@58689
   266
haftmann@58689
   267
lemma power_minus_even [simp]:
haftmann@58689
   268
  "even n \<Longrightarrow> (- a) ^ n = a ^ n"
haftmann@58690
   269
  by (auto elim: evenE)
haftmann@58689
   270
haftmann@58689
   271
lemma power_minus_odd [simp]:
haftmann@58689
   272
  "odd n \<Longrightarrow> (- a) ^ n = - (a ^ n)"
haftmann@58690
   273
  by (auto elim: oddE)
haftmann@58690
   274
haftmann@58690
   275
lemma neg_power_if:
haftmann@58690
   276
  "(- a) ^ n = (if even n then a ^ n else - (a ^ n))"
haftmann@58690
   277
  by simp
haftmann@58689
   278
haftmann@58689
   279
lemma neg_one_even_power [simp]:
haftmann@58689
   280
  "even n \<Longrightarrow> (- 1) ^ n = 1"
haftmann@58690
   281
  by simp
haftmann@58689
   282
haftmann@58689
   283
lemma neg_one_odd_power [simp]:
haftmann@58689
   284
  "odd n \<Longrightarrow> (- 1) ^ n = - 1"
haftmann@58690
   285
  by simp
haftmann@58689
   286
haftmann@58689
   287
end  
haftmann@58689
   288
haftmann@58689
   289
lemma zero_less_power_nat_eq_numeral [simp]: -- \<open>FIXME move\<close>
haftmann@58689
   290
  "0 < (n :: nat) ^ numeral w \<longleftrightarrow> 0 < n \<or> numeral w = (0 :: nat)"
haftmann@58689
   291
  by (fact nat_zero_less_power_iff)
haftmann@58689
   292
haftmann@58689
   293
context linordered_idom
haftmann@58689
   294
begin
haftmann@58689
   295
haftmann@58689
   296
lemma power_eq_0_iff' [simp]: -- \<open>FIXME move\<close>
haftmann@58689
   297
  "a ^ n = 0 \<longleftrightarrow> a = 0 \<and> n > 0"
haftmann@58689
   298
  by (induct n) auto
haftmann@58689
   299
haftmann@58689
   300
lemma power2_less_eq_zero_iff [simp]: -- \<open>FIXME move\<close>
haftmann@58689
   301
  "a\<^sup>2 \<le> 0 \<longleftrightarrow> a = 0"
haftmann@58689
   302
proof (cases "a = 0")
haftmann@58689
   303
  case True then show ?thesis by simp
haftmann@58689
   304
next
haftmann@58689
   305
  case False then have "a < 0 \<or> a > 0" by auto
haftmann@58689
   306
  then have "a\<^sup>2 > 0" by auto
haftmann@58689
   307
  then have "\<not> a\<^sup>2 \<le> 0" by (simp add: not_le)
haftmann@58689
   308
  with False show ?thesis by simp
haftmann@58689
   309
qed
haftmann@58689
   310
haftmann@58689
   311
lemma zero_le_even_power:
haftmann@58689
   312
  "even n \<Longrightarrow> 0 \<le> a ^ n"
haftmann@58690
   313
  by (auto elim: evenE)
haftmann@58689
   314
haftmann@58689
   315
lemma zero_le_odd_power:
haftmann@58689
   316
  "odd n \<Longrightarrow> 0 \<le> a ^ n \<longleftrightarrow> 0 \<le> a"
haftmann@58689
   317
  by (auto simp add: power_even_eq zero_le_mult_iff elim: oddE)
haftmann@58689
   318
haftmann@58770
   319
lemma zero_le_power_iff: -- \<open>FIXME cf. @{text zero_le_power_eq}\<close>
haftmann@58689
   320
  "0 \<le> a ^ n \<longleftrightarrow> 0 \<le> a \<or> even n"
haftmann@58689
   321
proof (cases "even n")
haftmann@58689
   322
  case True
haftmann@58689
   323
  then obtain k where "n = 2 * k" ..
haftmann@58690
   324
  then show ?thesis by simp
haftmann@58689
   325
next
haftmann@58689
   326
  case False
haftmann@58689
   327
  then obtain k where "n = 2 * k + 1" ..
haftmann@58689
   328
  moreover have "a ^ (2 * k) \<le> 0 \<Longrightarrow> a = 0"
haftmann@58689
   329
    by (induct k) (auto simp add: zero_le_mult_iff mult_le_0_iff)
haftmann@58689
   330
  ultimately show ?thesis
haftmann@58689
   331
    by (auto simp add: zero_le_mult_iff zero_le_even_power)
haftmann@58689
   332
qed
haftmann@58689
   333
haftmann@58770
   334
lemma zero_le_power_eq:
haftmann@58689
   335
  "0 \<le> a ^ n \<longleftrightarrow> even n \<or> odd n \<and> 0 \<le> a"
haftmann@58689
   336
  using zero_le_power_iff [of a n] by auto
haftmann@58689
   337
haftmann@58770
   338
lemma zero_less_power_eq:
haftmann@58689
   339
  "0 < a ^ n \<longleftrightarrow> n = 0 \<or> even n \<and> a \<noteq> 0 \<or> odd n \<and> 0 < a"
haftmann@58689
   340
proof -
haftmann@58689
   341
  have [simp]: "0 = a ^ n \<longleftrightarrow> a = 0 \<and> n > 0"
haftmann@58689
   342
    unfolding power_eq_0_iff' [of a n, symmetric] by blast
haftmann@58689
   343
  show ?thesis
haftmann@58710
   344
  unfolding less_le zero_le_power_eq by auto
haftmann@58689
   345
qed
haftmann@58689
   346
haftmann@58770
   347
lemma power_less_zero_eq:
haftmann@58689
   348
  "a ^ n < 0 \<longleftrightarrow> odd n \<and> a < 0"
haftmann@58689
   349
  unfolding not_le [symmetric] zero_le_power_eq by auto
haftmann@58689
   350
  
haftmann@58770
   351
lemma power_le_zero_eq:
haftmann@58689
   352
  "a ^ n \<le> 0 \<longleftrightarrow> n > 0 \<and> (odd n \<and> a \<le> 0 \<or> even n \<and> a = 0)"
haftmann@58689
   353
  unfolding not_less [symmetric] zero_less_power_eq by auto 
haftmann@58689
   354
haftmann@58689
   355
lemma power_even_abs:
haftmann@58689
   356
  "even n \<Longrightarrow> \<bar>a\<bar> ^ n = a ^ n"
haftmann@58689
   357
  using power_abs [of a n] by (simp add: zero_le_even_power)
haftmann@58689
   358
haftmann@58689
   359
lemma power_mono_even:
haftmann@58689
   360
  assumes "even n" and "\<bar>a\<bar> \<le> \<bar>b\<bar>"
haftmann@58689
   361
  shows "a ^ n \<le> b ^ n"
haftmann@58689
   362
proof -
haftmann@58689
   363
  have "0 \<le> \<bar>a\<bar>" by auto
haftmann@58689
   364
  with `\<bar>a\<bar> \<le> \<bar>b\<bar>`
haftmann@58689
   365
  have "\<bar>a\<bar> ^ n \<le> \<bar>b\<bar> ^ n" by (rule power_mono)
haftmann@58689
   366
  with `even n` show ?thesis by (simp add: power_even_abs)  
haftmann@58689
   367
qed
haftmann@58689
   368
haftmann@58689
   369
lemma power_mono_odd:
haftmann@58689
   370
  assumes "odd n" and "a \<le> b"
haftmann@58689
   371
  shows "a ^ n \<le> b ^ n"
haftmann@58689
   372
proof (cases "b < 0")
haftmann@58689
   373
  case True with `a \<le> b` have "- b \<le> - a" and "0 \<le> - b" by auto
haftmann@58689
   374
  hence "(- b) ^ n \<le> (- a) ^ n" by (rule power_mono)
haftmann@58689
   375
  with `odd n` show ?thesis by simp
haftmann@58689
   376
next
haftmann@58689
   377
  case False then have "0 \<le> b" by auto
haftmann@58689
   378
  show ?thesis
haftmann@58689
   379
  proof (cases "a < 0")
haftmann@58689
   380
    case True then have "n \<noteq> 0" and "a \<le> 0" using `odd n` [THEN odd_pos] by auto
haftmann@58689
   381
    then have "a ^ n \<le> 0" unfolding power_le_zero_eq using `odd n` by auto
haftmann@58689
   382
    moreover
haftmann@58689
   383
    from `0 \<le> b` have "0 \<le> b ^ n" by auto
haftmann@58689
   384
    ultimately show ?thesis by auto
haftmann@58689
   385
  next
haftmann@58689
   386
    case False then have "0 \<le> a" by auto
haftmann@58689
   387
    with `a \<le> b` show ?thesis using power_mono by auto
haftmann@58689
   388
  qed
haftmann@58689
   389
qed
haftmann@58689
   390
 
haftmann@58689
   391
text {* Simplify, when the exponent is a numeral *}
haftmann@58689
   392
haftmann@58689
   393
lemma zero_le_power_eq_numeral [simp]:
haftmann@58689
   394
  "0 \<le> a ^ numeral w \<longleftrightarrow> even (numeral w :: nat) \<or> odd (numeral w :: nat) \<and> 0 \<le> a"
haftmann@58689
   395
  by (fact zero_le_power_eq)
haftmann@58689
   396
haftmann@58689
   397
lemma zero_less_power_eq_numeral [simp]:
haftmann@58689
   398
  "0 < a ^ numeral w \<longleftrightarrow> numeral w = (0 :: nat)
haftmann@58689
   399
    \<or> even (numeral w :: nat) \<and> a \<noteq> 0 \<or> odd (numeral w :: nat) \<and> 0 < a"
haftmann@58689
   400
  by (fact zero_less_power_eq)
haftmann@58689
   401
haftmann@58689
   402
lemma power_le_zero_eq_numeral [simp]:
haftmann@58689
   403
  "a ^ numeral w \<le> 0 \<longleftrightarrow> (0 :: nat) < numeral w
haftmann@58689
   404
    \<and> (odd (numeral w :: nat) \<and> a \<le> 0 \<or> even (numeral w :: nat) \<and> a = 0)"
haftmann@58689
   405
  by (fact power_le_zero_eq)
haftmann@58689
   406
haftmann@58689
   407
lemma power_less_zero_eq_numeral [simp]:
haftmann@58689
   408
  "a ^ numeral w < 0 \<longleftrightarrow> odd (numeral w :: nat) \<and> a < 0"
haftmann@58689
   409
  by (fact power_less_zero_eq)
haftmann@58689
   410
haftmann@58689
   411
lemma power_eq_0_iff_numeral [simp]:
haftmann@58689
   412
  "a ^ numeral w = (0 :: nat) \<longleftrightarrow> a = 0 \<and> numeral w \<noteq> (0 :: nat)"
haftmann@58689
   413
  by (fact power_eq_0_iff)
haftmann@58689
   414
haftmann@58689
   415
lemma power_even_abs_numeral [simp]:
haftmann@58689
   416
  "even (numeral w :: nat) \<Longrightarrow> \<bar>a\<bar> ^ numeral w = a ^ numeral w"
haftmann@58689
   417
  by (fact power_even_abs)
haftmann@58689
   418
haftmann@58689
   419
end
haftmann@58689
   420
haftmann@58689
   421
haftmann@58687
   422
subsubsection {* Tools setup *}
haftmann@58687
   423
haftmann@58679
   424
declare transfer_morphism_int_nat [transfer add return:
haftmann@58679
   425
  even_int_iff
haftmann@33318
   426
]
wenzelm@21256
   427
haftmann@58770
   428
end
haftmann@58770
   429