move many lemmas from Nat_Numeral.thy to Power.thy or Num.thy
authorhuffman
Thu Mar 29 14:09:10 2012 +0200 (2012-03-29)
changeset 471920c0501cb6da6
parent 47191 ebd8c46d156b
child 47193 9ae03b37b4f6
move many lemmas from Nat_Numeral.thy to Power.thy or Num.thy
src/HOL/Int.thy
src/HOL/Nat_Numeral.thy
src/HOL/Num.thy
src/HOL/Power.thy
     1.1 --- a/src/HOL/Int.thy	Thu Mar 29 11:47:30 2012 +0200
     1.2 +++ b/src/HOL/Int.thy	Thu Mar 29 14:09:10 2012 +0200
     1.3 @@ -857,14 +857,6 @@
     1.4    "abs(-1 ^ n) = (1::'a::linordered_idom)"
     1.5  by (simp add: power_abs)
     1.6  
     1.7 -text{*Lemmas for specialist use, NOT as default simprules*}
     1.8 -(* TODO: see if semiring duplication can be removed without breaking proofs *)
     1.9 -lemma mult_2: "2 * z = (z+z::'a::semiring_1)"
    1.10 -unfolding one_add_one [symmetric] left_distrib by simp
    1.11 -
    1.12 -lemma mult_2_right: "z * 2 = (z+z::'a::semiring_1)"
    1.13 -unfolding one_add_one [symmetric] right_distrib by simp
    1.14 -
    1.15  
    1.16  subsection{*More Inequality Reasoning*}
    1.17  
     2.1 --- a/src/HOL/Nat_Numeral.thy	Thu Mar 29 11:47:30 2012 +0200
     2.2 +++ b/src/HOL/Nat_Numeral.thy	Thu Mar 29 14:09:10 2012 +0200
     2.3 @@ -9,245 +9,6 @@
     2.4  imports Int
     2.5  begin
     2.6  
     2.7 -subsection {* Numerals for natural numbers *}
     2.8 -
     2.9 -text {*
    2.10 -  Arithmetic for naturals is reduced to that for the non-negative integers.
    2.11 -*}
    2.12 -
    2.13 -subsection {* Special case: squares and cubes *}
    2.14 -
    2.15 -lemma numeral_2_eq_2: "2 = Suc (Suc 0)"
    2.16 -  by (simp add: nat_number(2-4))
    2.17 -
    2.18 -lemma numeral_3_eq_3: "3 = Suc (Suc (Suc 0))"
    2.19 -  by (simp add: nat_number(2-4))
    2.20 -
    2.21 -context power
    2.22 -begin
    2.23 -
    2.24 -abbreviation (xsymbols)
    2.25 -  power2 :: "'a \<Rightarrow> 'a"  ("(_\<twosuperior>)" [1000] 999) where
    2.26 -  "x\<twosuperior> \<equiv> x ^ 2"
    2.27 -
    2.28 -notation (latex output)
    2.29 -  power2  ("(_\<twosuperior>)" [1000] 999)
    2.30 -
    2.31 -notation (HTML output)
    2.32 -  power2  ("(_\<twosuperior>)" [1000] 999)
    2.33 -
    2.34 -end
    2.35 -
    2.36 -context monoid_mult
    2.37 -begin
    2.38 -
    2.39 -lemma power2_eq_square: "a\<twosuperior> = a * a"
    2.40 -  by (simp add: numeral_2_eq_2)
    2.41 -
    2.42 -lemma power3_eq_cube: "a ^ 3 = a * a * a"
    2.43 -  by (simp add: numeral_3_eq_3 mult_assoc)
    2.44 -
    2.45 -lemma power_even_eq:
    2.46 -  "a ^ (2*n) = (a ^ n) ^ 2"
    2.47 -  by (subst mult_commute) (simp add: power_mult)
    2.48 -
    2.49 -lemma power_odd_eq:
    2.50 -  "a ^ Suc (2*n) = a * (a ^ n) ^ 2"
    2.51 -  by (simp add: power_even_eq)
    2.52 -
    2.53 -end
    2.54 -
    2.55 -context semiring_1
    2.56 -begin
    2.57 -
    2.58 -lemma zero_power2 [simp]: "0\<twosuperior> = 0"
    2.59 -  by (simp add: power2_eq_square)
    2.60 -
    2.61 -lemma one_power2 [simp]: "1\<twosuperior> = 1"
    2.62 -  by (simp add: power2_eq_square)
    2.63 -
    2.64 -end
    2.65 -
    2.66 -context ring_1
    2.67 -begin
    2.68 -
    2.69 -lemma power2_minus [simp]:
    2.70 -  "(- a)\<twosuperior> = a\<twosuperior>"
    2.71 -  by (simp add: power2_eq_square)
    2.72 -
    2.73 -lemma power_minus1_even [simp]:
    2.74 -  "-1 ^ (2*n) = 1"
    2.75 -proof (induct n)
    2.76 -  case 0 show ?case by simp
    2.77 -next
    2.78 -  case (Suc n) then show ?case by (simp add: power_add power2_eq_square)
    2.79 -qed
    2.80 -
    2.81 -lemma power_minus1_odd:
    2.82 -  "-1 ^ Suc (2*n) = -1"
    2.83 -  by simp
    2.84 -
    2.85 -lemma power_minus_even [simp]:
    2.86 -  "(-a) ^ (2*n) = a ^ (2*n)"
    2.87 -  by (simp add: power_minus [of a])
    2.88 -
    2.89 -end
    2.90 -
    2.91 -context ring_1_no_zero_divisors
    2.92 -begin
    2.93 -
    2.94 -lemma zero_eq_power2 [simp]:
    2.95 -  "a\<twosuperior> = 0 \<longleftrightarrow> a = 0"
    2.96 -  unfolding power2_eq_square by simp
    2.97 -
    2.98 -lemma power2_eq_1_iff:
    2.99 -  "a\<twosuperior> = 1 \<longleftrightarrow> a = 1 \<or> a = - 1"
   2.100 -  unfolding power2_eq_square by (rule square_eq_1_iff)
   2.101 -
   2.102 -end
   2.103 -
   2.104 -context idom
   2.105 -begin
   2.106 -
   2.107 -lemma power2_eq_iff: "x\<twosuperior> = y\<twosuperior> \<longleftrightarrow> x = y \<or> x = - y"
   2.108 -  unfolding power2_eq_square by (rule square_eq_iff)
   2.109 -
   2.110 -end
   2.111 -
   2.112 -context linordered_ring
   2.113 -begin
   2.114 -
   2.115 -lemma sum_squares_ge_zero:
   2.116 -  "0 \<le> x * x + y * y"
   2.117 -  by (intro add_nonneg_nonneg zero_le_square)
   2.118 -
   2.119 -lemma not_sum_squares_lt_zero:
   2.120 -  "\<not> x * x + y * y < 0"
   2.121 -  by (simp add: not_less sum_squares_ge_zero)
   2.122 -
   2.123 -end
   2.124 -
   2.125 -context linordered_ring_strict
   2.126 -begin
   2.127 -
   2.128 -lemma sum_squares_eq_zero_iff:
   2.129 -  "x * x + y * y = 0 \<longleftrightarrow> x = 0 \<and> y = 0"
   2.130 -  by (simp add: add_nonneg_eq_0_iff)
   2.131 -
   2.132 -lemma sum_squares_le_zero_iff:
   2.133 -  "x * x + y * y \<le> 0 \<longleftrightarrow> x = 0 \<and> y = 0"
   2.134 -  by (simp add: le_less not_sum_squares_lt_zero sum_squares_eq_zero_iff)
   2.135 -
   2.136 -lemma sum_squares_gt_zero_iff:
   2.137 -  "0 < x * x + y * y \<longleftrightarrow> x \<noteq> 0 \<or> y \<noteq> 0"
   2.138 -  by (simp add: not_le [symmetric] sum_squares_le_zero_iff)
   2.139 -
   2.140 -end
   2.141 -
   2.142 -context linordered_semidom
   2.143 -begin
   2.144 -
   2.145 -lemma power2_le_imp_le:
   2.146 -  "x\<twosuperior> \<le> y\<twosuperior> \<Longrightarrow> 0 \<le> y \<Longrightarrow> x \<le> y"
   2.147 -  unfolding numeral_2_eq_2 by (rule power_le_imp_le_base)
   2.148 -
   2.149 -lemma power2_less_imp_less:
   2.150 -  "x\<twosuperior> < y\<twosuperior> \<Longrightarrow> 0 \<le> y \<Longrightarrow> x < y"
   2.151 -  by (rule power_less_imp_less_base)
   2.152 -
   2.153 -lemma power2_eq_imp_eq:
   2.154 -  "x\<twosuperior> = y\<twosuperior> \<Longrightarrow> 0 \<le> x \<Longrightarrow> 0 \<le> y \<Longrightarrow> x = y"
   2.155 -  unfolding numeral_2_eq_2 by (erule (2) power_eq_imp_eq_base) simp
   2.156 -
   2.157 -end
   2.158 -
   2.159 -context linordered_idom
   2.160 -begin
   2.161 -
   2.162 -lemma zero_le_power2 [simp]:
   2.163 -  "0 \<le> a\<twosuperior>"
   2.164 -  by (simp add: power2_eq_square)
   2.165 -
   2.166 -lemma zero_less_power2 [simp]:
   2.167 -  "0 < a\<twosuperior> \<longleftrightarrow> a \<noteq> 0"
   2.168 -  by (force simp add: power2_eq_square zero_less_mult_iff linorder_neq_iff)
   2.169 -
   2.170 -lemma power2_less_0 [simp]:
   2.171 -  "\<not> a\<twosuperior> < 0"
   2.172 -  by (force simp add: power2_eq_square mult_less_0_iff) 
   2.173 -
   2.174 -lemma abs_power2 [simp]:
   2.175 -  "abs (a\<twosuperior>) = a\<twosuperior>"
   2.176 -  by (simp add: power2_eq_square abs_mult abs_mult_self)
   2.177 -
   2.178 -lemma power2_abs [simp]:
   2.179 -  "(abs a)\<twosuperior> = a\<twosuperior>"
   2.180 -  by (simp add: power2_eq_square abs_mult_self)
   2.181 -
   2.182 -lemma odd_power_less_zero:
   2.183 -  "a < 0 \<Longrightarrow> a ^ Suc (2*n) < 0"
   2.184 -proof (induct n)
   2.185 -  case 0
   2.186 -  then show ?case by simp
   2.187 -next
   2.188 -  case (Suc n)
   2.189 -  have "a ^ Suc (2 * Suc n) = (a*a) * a ^ Suc(2*n)"
   2.190 -    by (simp add: mult_ac power_add power2_eq_square)
   2.191 -  thus ?case
   2.192 -    by (simp del: power_Suc add: Suc mult_less_0_iff mult_neg_neg)
   2.193 -qed
   2.194 -
   2.195 -lemma odd_0_le_power_imp_0_le:
   2.196 -  "0 \<le> a ^ Suc (2*n) \<Longrightarrow> 0 \<le> a"
   2.197 -  using odd_power_less_zero [of a n]
   2.198 -    by (force simp add: linorder_not_less [symmetric]) 
   2.199 -
   2.200 -lemma zero_le_even_power'[simp]:
   2.201 -  "0 \<le> a ^ (2*n)"
   2.202 -proof (induct n)
   2.203 -  case 0
   2.204 -    show ?case by simp
   2.205 -next
   2.206 -  case (Suc n)
   2.207 -    have "a ^ (2 * Suc n) = (a*a) * a ^ (2*n)" 
   2.208 -      by (simp add: mult_ac power_add power2_eq_square)
   2.209 -    thus ?case
   2.210 -      by (simp add: Suc zero_le_mult_iff)
   2.211 -qed
   2.212 -
   2.213 -lemma sum_power2_ge_zero:
   2.214 -  "0 \<le> x\<twosuperior> + y\<twosuperior>"
   2.215 -  unfolding power2_eq_square by (rule sum_squares_ge_zero)
   2.216 -
   2.217 -lemma not_sum_power2_lt_zero:
   2.218 -  "\<not> x\<twosuperior> + y\<twosuperior> < 0"
   2.219 -  unfolding power2_eq_square by (rule not_sum_squares_lt_zero)
   2.220 -
   2.221 -lemma sum_power2_eq_zero_iff:
   2.222 -  "x\<twosuperior> + y\<twosuperior> = 0 \<longleftrightarrow> x = 0 \<and> y = 0"
   2.223 -  unfolding power2_eq_square by (rule sum_squares_eq_zero_iff)
   2.224 -
   2.225 -lemma sum_power2_le_zero_iff:
   2.226 -  "x\<twosuperior> + y\<twosuperior> \<le> 0 \<longleftrightarrow> x = 0 \<and> y = 0"
   2.227 -  unfolding power2_eq_square by (rule sum_squares_le_zero_iff)
   2.228 -
   2.229 -lemma sum_power2_gt_zero_iff:
   2.230 -  "0 < x\<twosuperior> + y\<twosuperior> \<longleftrightarrow> x \<noteq> 0 \<or> y \<noteq> 0"
   2.231 -  unfolding power2_eq_square by (rule sum_squares_gt_zero_iff)
   2.232 -
   2.233 -end
   2.234 -
   2.235 -lemma power2_sum:
   2.236 -  fixes x y :: "'a::comm_semiring_1"
   2.237 -  shows "(x + y)\<twosuperior> = x\<twosuperior> + y\<twosuperior> + 2 * x * y"
   2.238 -  by (simp add: algebra_simps power2_eq_square mult_2_right)
   2.239 -
   2.240 -lemma power2_diff:
   2.241 -  fixes x y :: "'a::comm_ring_1"
   2.242 -  shows "(x - y)\<twosuperior> = x\<twosuperior> + y\<twosuperior> - 2 * x * y"
   2.243 -  by (simp add: ring_distribs power2_eq_square mult_2) (rule mult_commute)
   2.244 -
   2.245 -
   2.246  subsection{*Function @{term nat}: Coercion from Type @{typ int} to @{typ nat}*}
   2.247  
   2.248  declare nat_1 [simp]
     3.1 --- a/src/HOL/Num.thy	Thu Mar 29 11:47:30 2012 +0200
     3.2 +++ b/src/HOL/Num.thy	Thu Mar 29 14:09:10 2012 +0200
     3.3 @@ -528,6 +528,12 @@
     3.4    by (induct n,
     3.5      simp_all only: numeral.simps numeral_class.numeral.simps of_nat_add of_nat_1)
     3.6  
     3.7 +lemma mult_2: "2 * z = z + z"
     3.8 +  unfolding one_add_one [symmetric] left_distrib by simp
     3.9 +
    3.10 +lemma mult_2_right: "z * 2 = z + z"
    3.11 +  unfolding one_add_one [symmetric] right_distrib by simp
    3.12 +
    3.13  end
    3.14  
    3.15  lemma nat_of_num_numeral: "nat_of_num = numeral"
    3.16 @@ -864,6 +870,12 @@
    3.17    "numeral (Bit1 n) = Suc (numeral (Bit0 n))"
    3.18    by (simp_all add: numeral.simps BitM_plus_one)
    3.19  
    3.20 +lemma numeral_2_eq_2: "2 = Suc (Suc 0)"
    3.21 +  by (simp add: nat_number(2-4))
    3.22 +
    3.23 +lemma numeral_3_eq_3: "3 = Suc (Suc (Suc 0))"
    3.24 +  by (simp add: nat_number(2-4))
    3.25 +
    3.26  
    3.27  subsection {* Numeral equations as default simplification rules *}
    3.28  
     4.1 --- a/src/HOL/Power.thy	Thu Mar 29 11:47:30 2012 +0200
     4.2 +++ b/src/HOL/Power.thy	Thu Mar 29 14:09:10 2012 +0200
     4.3 @@ -24,6 +24,18 @@
     4.4  notation (HTML output)
     4.5    power ("(_\<^bsup>_\<^esup>)" [1000] 1000)
     4.6  
     4.7 +text {* Special syntax for squares. *}
     4.8 +
     4.9 +abbreviation (xsymbols)
    4.10 +  power2 :: "'a \<Rightarrow> 'a"  ("(_\<twosuperior>)" [1000] 999) where
    4.11 +  "x\<twosuperior> \<equiv> x ^ 2"
    4.12 +
    4.13 +notation (latex output)
    4.14 +  power2  ("(_\<twosuperior>)" [1000] 999)
    4.15 +
    4.16 +notation (HTML output)
    4.17 +  power2  ("(_\<twosuperior>)" [1000] 999)
    4.18 +
    4.19  end
    4.20  
    4.21  context monoid_mult
    4.22 @@ -55,6 +67,20 @@
    4.23    "a ^ (m * n) = (a ^ m) ^ n"
    4.24    by (induct n) (simp_all add: power_add)
    4.25  
    4.26 +lemma power2_eq_square: "a\<twosuperior> = a * a"
    4.27 +  by (simp add: numeral_2_eq_2)
    4.28 +
    4.29 +lemma power3_eq_cube: "a ^ 3 = a * a * a"
    4.30 +  by (simp add: numeral_3_eq_3 mult_assoc)
    4.31 +
    4.32 +lemma power_even_eq:
    4.33 +  "a ^ (2*n) = (a ^ n) ^ 2"
    4.34 +  by (subst mult_commute) (simp add: power_mult)
    4.35 +
    4.36 +lemma power_odd_eq:
    4.37 +  "a ^ Suc (2*n) = a * (a ^ n) ^ 2"
    4.38 +  by (simp add: power_even_eq)
    4.39 +
    4.40  end
    4.41  
    4.42  context comm_monoid_mult
    4.43 @@ -91,6 +117,12 @@
    4.44  lemma power_zero_numeral [simp]: "(0::'a) ^ numeral k = 0"
    4.45    by (cases "numeral k :: nat", simp_all)
    4.46  
    4.47 +lemma zero_power2: "0\<twosuperior> = 0" (* delete? *)
    4.48 +  by (rule power_zero_numeral)
    4.49 +
    4.50 +lemma one_power2: "1\<twosuperior> = 1" (* delete? *)
    4.51 +  by (rule power_one)
    4.52 +
    4.53  end
    4.54  
    4.55  context comm_semiring_1
    4.56 @@ -163,6 +195,87 @@
    4.57    "neg_numeral k ^ numeral (Num.Bit1 l) = neg_numeral (Num.pow k (Num.Bit1 l))"
    4.58    by (simp only: neg_numeral_def power_minus_Bit1 power_numeral pow.simps)
    4.59  
    4.60 +lemma power2_minus [simp]:
    4.61 +  "(- a)\<twosuperior> = a\<twosuperior>"
    4.62 +  by (rule power_minus_Bit0)
    4.63 +
    4.64 +lemma power_minus1_even [simp]:
    4.65 +  "-1 ^ (2*n) = 1"
    4.66 +proof (induct n)
    4.67 +  case 0 show ?case by simp
    4.68 +next
    4.69 +  case (Suc n) then show ?case by (simp add: power_add power2_eq_square)
    4.70 +qed
    4.71 +
    4.72 +lemma power_minus1_odd:
    4.73 +  "-1 ^ Suc (2*n) = -1"
    4.74 +  by simp
    4.75 +
    4.76 +lemma power_minus_even [simp]:
    4.77 +  "(-a) ^ (2*n) = a ^ (2*n)"
    4.78 +  by (simp add: power_minus [of a])
    4.79 +
    4.80 +end
    4.81 +
    4.82 +context ring_1_no_zero_divisors
    4.83 +begin
    4.84 +
    4.85 +lemma field_power_not_zero:
    4.86 +  "a \<noteq> 0 \<Longrightarrow> a ^ n \<noteq> 0"
    4.87 +  by (induct n) auto
    4.88 +
    4.89 +lemma zero_eq_power2 [simp]:
    4.90 +  "a\<twosuperior> = 0 \<longleftrightarrow> a = 0"
    4.91 +  unfolding power2_eq_square by simp
    4.92 +
    4.93 +lemma power2_eq_1_iff:
    4.94 +  "a\<twosuperior> = 1 \<longleftrightarrow> a = 1 \<or> a = - 1"
    4.95 +  unfolding power2_eq_square by (rule square_eq_1_iff)
    4.96 +
    4.97 +end
    4.98 +
    4.99 +context idom
   4.100 +begin
   4.101 +
   4.102 +lemma power2_eq_iff: "x\<twosuperior> = y\<twosuperior> \<longleftrightarrow> x = y \<or> x = - y"
   4.103 +  unfolding power2_eq_square by (rule square_eq_iff)
   4.104 +
   4.105 +end
   4.106 +
   4.107 +context division_ring
   4.108 +begin
   4.109 +
   4.110 +text {* FIXME reorient or rename to @{text nonzero_inverse_power} *}
   4.111 +lemma nonzero_power_inverse:
   4.112 +  "a \<noteq> 0 \<Longrightarrow> inverse (a ^ n) = (inverse a) ^ n"
   4.113 +  by (induct n)
   4.114 +    (simp_all add: nonzero_inverse_mult_distrib power_commutes field_power_not_zero)
   4.115 +
   4.116 +end
   4.117 +
   4.118 +context field
   4.119 +begin
   4.120 +
   4.121 +lemma nonzero_power_divide:
   4.122 +  "b \<noteq> 0 \<Longrightarrow> (a / b) ^ n = a ^ n / b ^ n"
   4.123 +  by (simp add: divide_inverse power_mult_distrib nonzero_power_inverse)
   4.124 +
   4.125 +end
   4.126 +
   4.127 +
   4.128 +subsection {* Exponentiation on ordered types *}
   4.129 +
   4.130 +context linordered_ring (* TODO: move *)
   4.131 +begin
   4.132 +
   4.133 +lemma sum_squares_ge_zero:
   4.134 +  "0 \<le> x * x + y * y"
   4.135 +  by (intro add_nonneg_nonneg zero_le_square)
   4.136 +
   4.137 +lemma not_sum_squares_lt_zero:
   4.138 +  "\<not> x * x + y * y < 0"
   4.139 +  by (simp add: not_less sum_squares_ge_zero)
   4.140 +
   4.141  end
   4.142  
   4.143  context linordered_semidom
   4.144 @@ -356,6 +469,35 @@
   4.145    "a ^ n = b ^ n \<Longrightarrow> 0 \<le> a \<Longrightarrow> 0 \<le> b \<Longrightarrow> 0 < n \<Longrightarrow> a = b"
   4.146    by (cases n) (simp_all del: power_Suc, rule power_inject_base)
   4.147  
   4.148 +lemma power2_le_imp_le:
   4.149 +  "x\<twosuperior> \<le> y\<twosuperior> \<Longrightarrow> 0 \<le> y \<Longrightarrow> x \<le> y"
   4.150 +  unfolding numeral_2_eq_2 by (rule power_le_imp_le_base)
   4.151 +
   4.152 +lemma power2_less_imp_less:
   4.153 +  "x\<twosuperior> < y\<twosuperior> \<Longrightarrow> 0 \<le> y \<Longrightarrow> x < y"
   4.154 +  by (rule power_less_imp_less_base)
   4.155 +
   4.156 +lemma power2_eq_imp_eq:
   4.157 +  "x\<twosuperior> = y\<twosuperior> \<Longrightarrow> 0 \<le> x \<Longrightarrow> 0 \<le> y \<Longrightarrow> x = y"
   4.158 +  unfolding numeral_2_eq_2 by (erule (2) power_eq_imp_eq_base) simp
   4.159 +
   4.160 +end
   4.161 +
   4.162 +context linordered_ring_strict
   4.163 +begin
   4.164 +
   4.165 +lemma sum_squares_eq_zero_iff:
   4.166 +  "x * x + y * y = 0 \<longleftrightarrow> x = 0 \<and> y = 0"
   4.167 +  by (simp add: add_nonneg_eq_0_iff)
   4.168 +
   4.169 +lemma sum_squares_le_zero_iff:
   4.170 +  "x * x + y * y \<le> 0 \<longleftrightarrow> x = 0 \<and> y = 0"
   4.171 +  by (simp add: le_less not_sum_squares_lt_zero sum_squares_eq_zero_iff)
   4.172 +
   4.173 +lemma sum_squares_gt_zero_iff:
   4.174 +  "0 < x * x + y * y \<longleftrightarrow> x \<noteq> 0 \<or> y \<noteq> 0"
   4.175 +  by (simp add: not_le [symmetric] sum_squares_le_zero_iff)
   4.176 +
   4.177  end
   4.178  
   4.179  context linordered_idom
   4.180 @@ -381,36 +523,91 @@
   4.181    "0 \<le> abs a ^ n"
   4.182    by (rule zero_le_power [OF abs_ge_zero])
   4.183  
   4.184 -end
   4.185 +lemma zero_le_power2 [simp]:
   4.186 +  "0 \<le> a\<twosuperior>"
   4.187 +  by (simp add: power2_eq_square)
   4.188 +
   4.189 +lemma zero_less_power2 [simp]:
   4.190 +  "0 < a\<twosuperior> \<longleftrightarrow> a \<noteq> 0"
   4.191 +  by (force simp add: power2_eq_square zero_less_mult_iff linorder_neq_iff)
   4.192 +
   4.193 +lemma power2_less_0 [simp]:
   4.194 +  "\<not> a\<twosuperior> < 0"
   4.195 +  by (force simp add: power2_eq_square mult_less_0_iff)
   4.196 +
   4.197 +lemma abs_power2 [simp]:
   4.198 +  "abs (a\<twosuperior>) = a\<twosuperior>"
   4.199 +  by (simp add: power2_eq_square abs_mult abs_mult_self)
   4.200 +
   4.201 +lemma power2_abs [simp]:
   4.202 +  "(abs a)\<twosuperior> = a\<twosuperior>"
   4.203 +  by (simp add: power2_eq_square abs_mult_self)
   4.204 +
   4.205 +lemma odd_power_less_zero:
   4.206 +  "a < 0 \<Longrightarrow> a ^ Suc (2*n) < 0"
   4.207 +proof (induct n)
   4.208 +  case 0
   4.209 +  then show ?case by simp
   4.210 +next
   4.211 +  case (Suc n)
   4.212 +  have "a ^ Suc (2 * Suc n) = (a*a) * a ^ Suc(2*n)"
   4.213 +    by (simp add: mult_ac power_add power2_eq_square)
   4.214 +  thus ?case
   4.215 +    by (simp del: power_Suc add: Suc mult_less_0_iff mult_neg_neg)
   4.216 +qed
   4.217  
   4.218 -context ring_1_no_zero_divisors
   4.219 -begin
   4.220 +lemma odd_0_le_power_imp_0_le:
   4.221 +  "0 \<le> a ^ Suc (2*n) \<Longrightarrow> 0 \<le> a"
   4.222 +  using odd_power_less_zero [of a n]
   4.223 +    by (force simp add: linorder_not_less [symmetric]) 
   4.224 +
   4.225 +lemma zero_le_even_power'[simp]:
   4.226 +  "0 \<le> a ^ (2*n)"
   4.227 +proof (induct n)
   4.228 +  case 0
   4.229 +    show ?case by simp
   4.230 +next
   4.231 +  case (Suc n)
   4.232 +    have "a ^ (2 * Suc n) = (a*a) * a ^ (2*n)" 
   4.233 +      by (simp add: mult_ac power_add power2_eq_square)
   4.234 +    thus ?case
   4.235 +      by (simp add: Suc zero_le_mult_iff)
   4.236 +qed
   4.237  
   4.238 -lemma field_power_not_zero:
   4.239 -  "a \<noteq> 0 \<Longrightarrow> a ^ n \<noteq> 0"
   4.240 -  by (induct n) auto
   4.241 +lemma sum_power2_ge_zero:
   4.242 +  "0 \<le> x\<twosuperior> + y\<twosuperior>"
   4.243 +  by (intro add_nonneg_nonneg zero_le_power2)
   4.244 +
   4.245 +lemma not_sum_power2_lt_zero:
   4.246 +  "\<not> x\<twosuperior> + y\<twosuperior> < 0"
   4.247 +  unfolding not_less by (rule sum_power2_ge_zero)
   4.248 +
   4.249 +lemma sum_power2_eq_zero_iff:
   4.250 +  "x\<twosuperior> + y\<twosuperior> = 0 \<longleftrightarrow> x = 0 \<and> y = 0"
   4.251 +  unfolding power2_eq_square by (simp add: add_nonneg_eq_0_iff)
   4.252 +
   4.253 +lemma sum_power2_le_zero_iff:
   4.254 +  "x\<twosuperior> + y\<twosuperior> \<le> 0 \<longleftrightarrow> x = 0 \<and> y = 0"
   4.255 +  by (simp add: le_less sum_power2_eq_zero_iff not_sum_power2_lt_zero)
   4.256 +
   4.257 +lemma sum_power2_gt_zero_iff:
   4.258 +  "0 < x\<twosuperior> + y\<twosuperior> \<longleftrightarrow> x \<noteq> 0 \<or> y \<noteq> 0"
   4.259 +  unfolding not_le [symmetric] by (simp add: sum_power2_le_zero_iff)
   4.260  
   4.261  end
   4.262  
   4.263 -context division_ring
   4.264 -begin
   4.265  
   4.266 -text {* FIXME reorient or rename to @{text nonzero_inverse_power} *}
   4.267 -lemma nonzero_power_inverse:
   4.268 -  "a \<noteq> 0 \<Longrightarrow> inverse (a ^ n) = (inverse a) ^ n"
   4.269 -  by (induct n)
   4.270 -    (simp_all add: nonzero_inverse_mult_distrib power_commutes field_power_not_zero)
   4.271 +subsection {* Miscellaneous rules *}
   4.272  
   4.273 -end
   4.274 -
   4.275 -context field
   4.276 -begin
   4.277 +lemma power2_sum:
   4.278 +  fixes x y :: "'a::comm_semiring_1"
   4.279 +  shows "(x + y)\<twosuperior> = x\<twosuperior> + y\<twosuperior> + 2 * x * y"
   4.280 +  by (simp add: algebra_simps power2_eq_square mult_2_right)
   4.281  
   4.282 -lemma nonzero_power_divide:
   4.283 -  "b \<noteq> 0 \<Longrightarrow> (a / b) ^ n = a ^ n / b ^ n"
   4.284 -  by (simp add: divide_inverse power_mult_distrib nonzero_power_inverse)
   4.285 -
   4.286 -end
   4.287 +lemma power2_diff:
   4.288 +  fixes x y :: "'a::comm_ring_1"
   4.289 +  shows "(x - y)\<twosuperior> = x\<twosuperior> + y\<twosuperior> - 2 * x * y"
   4.290 +  by (simp add: ring_distribs power2_eq_square mult_2) (rule mult_commute)
   4.291  
   4.292  lemma power_0_Suc [simp]:
   4.293    "(0::'a::{power, semiring_0}) ^ Suc n = 0"