src/HOL/Parity.thy
changeset 58679 33c90658448a
parent 58678 398e05aa84d4
child 58680 6b2fa479945f
equal deleted inserted replaced
58678:398e05aa84d4 58679:33c90658448a
   187   then show False by simp
   187   then show False by simp
   188 qed
   188 qed
   189 
   189 
   190 end
   190 end
   191 
   191 
       
   192 context ring_parity
       
   193 begin
       
   194 
       
   195 lemma even_minus [simp, presburger, algebra]:
       
   196   "even (- a) \<longleftrightarrow> even a"
       
   197   by (simp add: even_def)
       
   198 
       
   199 end
       
   200 
   192 context semiring_div_parity
   201 context semiring_div_parity
   193 begin
   202 begin
   194 
   203 
   195 lemma even_iff_mod_2_eq_zero [presburger]:
   204 lemma even_iff_mod_2_eq_zero [presburger]:
   196   "even a \<longleftrightarrow> a mod 2 = 0"
   205   "even a \<longleftrightarrow> a mod 2 = 0"
   197   by (simp add: even_def dvd_eq_mod_eq_0)
   206   by (simp add: even_def dvd_eq_mod_eq_0)
   198 
   207 
   199 lemma even_times_anything:
   208 end
   200   "even a \<Longrightarrow> even (a * b)"
   209 
   201   by (simp add: even_def)
   210 lemma even_int_iff:
   202 
   211   "even (int n) \<longleftrightarrow> even n"
   203 lemma anything_times_even:
   212   by (simp add: even_def dvd_int_iff)
   204   "even a \<Longrightarrow> even (b * a)"
   213 
   205   by (simp add: even_def)
   214 declare transfer_morphism_int_nat [transfer add return:
   206 
   215   even_int_iff
   207 lemma odd_times_odd:
   216 ]
   208   "odd a \<Longrightarrow> odd b \<Longrightarrow> odd (a * b)" 
   217 
   209   by (auto simp add: even_iff_mod_2_eq_zero mod_mult_left_eq)
   218 lemma [presburger]:
   210 
   219   "even n \<longleftrightarrow> even (int n)"
   211 lemma even_product:
   220   using even_int_iff [of n] by simp
   212   "even (a * b) \<longleftrightarrow> even a \<or> even b"
       
   213   by (fact even_times_iff)
       
   214 
       
   215 end
       
   216 
       
   217 lemma even_nat_def [presburger]:
       
   218   "even x \<longleftrightarrow> even (int x)"
       
   219   by (auto simp add: even_iff_mod_2_eq_zero int_eq_iff int_mult nat_mult_distrib)
       
   220   
   221   
   221 lemma transfer_int_nat_relations:
       
   222   "even (int x) \<longleftrightarrow> even x"
       
   223   by (simp add: even_nat_def)
       
   224 
       
   225 declare transfer_morphism_int_nat[transfer add return:
       
   226   transfer_int_nat_relations
       
   227 ]
       
   228 
       
   229 declare even_iff_mod_2_eq_zero [of "- numeral v", simp] for v
       
   230 
       
   231 
   222 
   232 subsection {* Behavior under integer arithmetic operations *}
   223 subsection {* Behavior under integer arithmetic operations *}
   233 
   224 
   234 lemma even_plus_even: "even (x::int) ==> even y ==> even (x + y)"
   225 lemma even_plus_even: "even (x::int) ==> even y ==> even (x + y)"
   235 by presburger
   226 by presburger
   244 
   235 
   245 lemma even_sum[simp,presburger]:
   236 lemma even_sum[simp,presburger]:
   246   "even ((x::int) + y) = ((even x & even y) | (odd x & odd y))"
   237   "even ((x::int) + y) = ((even x & even y) | (odd x & odd y))"
   247 by presburger
   238 by presburger
   248 
   239 
   249 lemma even_neg[simp,presburger,algebra]: "even (-(x::int)) = even x"
       
   250 by presburger
       
   251 
       
   252 lemma even_difference[simp]:
   240 lemma even_difference[simp]:
   253     "even ((x::int) - y) = ((even x & even y) | (odd x & odd y))" by presburger
   241     "even ((x::int) - y) = ((even x & even y) | (odd x & odd y))" by presburger
   254 
   242 
   255 lemma even_power[simp,presburger]: "even ((x::int)^n) = (even x & n \<noteq> 0)"
   243 lemma even_power[simp,presburger]: "even ((x::int)^n) = (even x & n \<noteq> 0)"
   256 by (induct n) auto
   244 by (induct n) auto
   272 lemma odd_equiv_def: "odd (x::int) = (EX y. x = 2 * y + 1)" by presburger
   260 lemma odd_equiv_def: "odd (x::int) = (EX y. x = 2 * y + 1)" by presburger
   273 
   261 
   274 subsection {* even and odd for nats *}
   262 subsection {* even and odd for nats *}
   275 
   263 
   276 lemma pos_int_even_equiv_nat_even: "0 \<le> x ==> even x = even (nat x)"
   264 lemma pos_int_even_equiv_nat_even: "0 \<le> x ==> even x = even (nat x)"
   277 by (simp add: even_nat_def)
   265 by (simp add: even_int_iff [symmetric])
   278 
       
   279 lemma even_product_nat:
       
   280   "even((x::nat) * y) = (even x | even y)"
       
   281   by (fact even_times_iff)
       
   282 
   266 
   283 lemma even_sum_nat[simp,presburger,algebra]:
   267 lemma even_sum_nat[simp,presburger,algebra]:
   284   "even ((x::nat) + y) = ((even x & even y) | (odd x & odd y))"
   268   "even ((x::nat) + y) = ((even x & even y) | (odd x & odd y))"
   285 by presburger
   269 by presburger
   286 
   270 
   291 lemma even_Suc[simp,presburger,algebra]: "even (Suc x) = odd x"
   275 lemma even_Suc[simp,presburger,algebra]: "even (Suc x) = odd x"
   292 by presburger
   276 by presburger
   293 
   277 
   294 lemma even_power_nat[simp,presburger,algebra]:
   278 lemma even_power_nat[simp,presburger,algebra]:
   295   "even ((x::nat)^y) = (even x & 0 < y)"
   279   "even ((x::nat)^y) = (even x & 0 < y)"
   296 by (simp add: even_nat_def int_power)
   280 by (simp add: even_int_iff [symmetric] int_power)
   297 
   281 
   298 
   282 
   299 subsection {* Equivalent definitions *}
   283 subsection {* Equivalent definitions *}
   300 
   284 
   301 lemma even_nat_mod_two_eq_zero: "even (x::nat) ==> x mod (Suc (Suc 0)) = 0"
   285 lemma even_nat_mod_two_eq_zero: "even (x::nat) ==> x mod (Suc (Suc 0)) = 0"