src/HOL/Old_Number_Theory/EvenOdd.thy
changeset 61382 efac889fccbc
parent 58889 5b7a9633cfa8
child 61649 268d88ec9087
equal deleted inserted replaced
61381:ddca85598c65 61382:efac889fccbc
     1 (*  Title:      HOL/Old_Number_Theory/EvenOdd.thy
     1 (*  Title:      HOL/Old_Number_Theory/EvenOdd.thy
     2     Authors:    Jeremy Avigad, David Gray, and Adam Kramer
     2     Authors:    Jeremy Avigad, David Gray, and Adam Kramer
     3 *)
     3 *)
     4 
     4 
     5 section {*Parity: Even and Odd Integers*}
     5 section \<open>Parity: Even and Odd Integers\<close>
     6 
     6 
     7 theory EvenOdd
     7 theory EvenOdd
     8 imports Int2
     8 imports Int2
     9 begin
     9 begin
    10 
    10 
    12   where "zOdd = {x. \<exists>k. x = 2 * k + 1}"
    12   where "zOdd = {x. \<exists>k. x = 2 * k + 1}"
    13 
    13 
    14 definition zEven :: "int set"
    14 definition zEven :: "int set"
    15   where "zEven = {x. \<exists>k. x = 2 * k}"
    15   where "zEven = {x. \<exists>k. x = 2 * k}"
    16 
    16 
    17 subsection {* Some useful properties about even and odd *}
    17 subsection \<open>Some useful properties about even and odd\<close>
    18 
    18 
    19 lemma zOddI [intro?]: "x = 2 * k + 1 \<Longrightarrow> x \<in> zOdd"
    19 lemma zOddI [intro?]: "x = 2 * k + 1 \<Longrightarrow> x \<in> zOdd"
    20   and zOddE [elim?]: "x \<in> zOdd \<Longrightarrow> (!!k. x = 2 * k + 1 \<Longrightarrow> C) \<Longrightarrow> C"
    20   and zOddE [elim?]: "x \<in> zOdd \<Longrightarrow> (!!k. x = 2 * k + 1 \<Longrightarrow> C) \<Longrightarrow> C"
    21   by (auto simp add: zOdd_def)
    21   by (auto simp add: zOdd_def)
    22 
    22 
   165 qed
   165 qed
   166 
   166 
   167 lemma neg_one_even_power: "[| x \<in> zEven; 0 \<le> x |] ==> (-1::int)^(nat x) = 1"
   167 lemma neg_one_even_power: "[| x \<in> zEven; 0 \<le> x |] ==> (-1::int)^(nat x) = 1"
   168 proof -
   168 proof -
   169   assume "x \<in> zEven" and "0 \<le> x"
   169   assume "x \<in> zEven" and "0 \<le> x"
   170   from `x \<in> zEven` obtain a where "x = 2 * a" ..
   170   from \<open>x \<in> zEven\<close> obtain a where "x = 2 * a" ..
   171   with `0 \<le> x` have "0 \<le> a" by simp
   171   with \<open>0 \<le> x\<close> have "0 \<le> a" by simp
   172   from `0 \<le> x` and `x = 2 * a` have "nat x = nat (2 * a)"
   172   from \<open>0 \<le> x\<close> and \<open>x = 2 * a\<close> have "nat x = nat (2 * a)"
   173     by simp
   173     by simp
   174   also from `x = 2 * a` have "nat (2 * a) = 2 * nat a"
   174   also from \<open>x = 2 * a\<close> have "nat (2 * a) = 2 * nat a"
   175     by (simp add: nat_mult_distrib)
   175     by (simp add: nat_mult_distrib)
   176   finally have "(-1::int)^nat x = (-1)^(2 * nat a)"
   176   finally have "(-1::int)^nat x = (-1)^(2 * nat a)"
   177     by simp
   177     by simp
   178   also have "... = (-1::int)\<^sup>2 ^ nat a"
   178   also have "... = (-1::int)\<^sup>2 ^ nat a"
   179     by (simp add: zpower_zpower [symmetric])
   179     by (simp add: zpower_zpower [symmetric])
   184 qed
   184 qed
   185 
   185 
   186 lemma neg_one_odd_power: "[| x \<in> zOdd; 0 \<le> x |] ==> (-1::int)^(nat x) = -1"
   186 lemma neg_one_odd_power: "[| x \<in> zOdd; 0 \<le> x |] ==> (-1::int)^(nat x) = -1"
   187 proof -
   187 proof -
   188   assume "x \<in> zOdd" and "0 \<le> x"
   188   assume "x \<in> zOdd" and "0 \<le> x"
   189   from `x \<in> zOdd` obtain a where "x = 2 * a + 1" ..
   189   from \<open>x \<in> zOdd\<close> obtain a where "x = 2 * a + 1" ..
   190   with `0 \<le> x` have a: "0 \<le> a" by simp
   190   with \<open>0 \<le> x\<close> have a: "0 \<le> a" by simp
   191   with `0 \<le> x` and `x = 2 * a + 1` have "nat x = nat (2 * a + 1)"
   191   with \<open>0 \<le> x\<close> and \<open>x = 2 * a + 1\<close> have "nat x = nat (2 * a + 1)"
   192     by simp
   192     by simp
   193   also from a have "nat (2 * a + 1) = 2 * nat a + 1"
   193   also from a have "nat (2 * a + 1) = 2 * nat a + 1"
   194     by (auto simp add: nat_mult_distrib nat_add_distrib)
   194     by (auto simp add: nat_mult_distrib nat_add_distrib)
   195   finally have "(-1::int) ^ nat x = (-1)^(2 * nat a + 1)"
   195   finally have "(-1::int) ^ nat x = (-1)^(2 * nat a + 1)"
   196     by simp
   196     by simp
   212   by (auto simp add: zcong_def zdvd_not_zless)
   212   by (auto simp add: zcong_def zdvd_not_zless)
   213 
   213 
   214 lemma even_div_2_l: "[| y \<in> zEven; x < y |] ==> x div 2 < y div 2"
   214 lemma even_div_2_l: "[| y \<in> zEven; x < y |] ==> x div 2 < y div 2"
   215 proof -
   215 proof -
   216   assume "y \<in> zEven" and "x < y"
   216   assume "y \<in> zEven" and "x < y"
   217   from `y \<in> zEven` obtain k where k: "y = 2 * k" ..
   217   from \<open>y \<in> zEven\<close> obtain k where k: "y = 2 * k" ..
   218   with `x < y` have "x < 2 * k" by simp
   218   with \<open>x < y\<close> have "x < 2 * k" by simp
   219   then have "x div 2 < k" by (auto simp add: div_prop1)
   219   then have "x div 2 < k" by (auto simp add: div_prop1)
   220   also have "k = (2 * k) div 2" by simp
   220   also have "k = (2 * k) div 2" by simp
   221   finally have "x div 2 < 2 * k div 2" by simp
   221   finally have "x div 2 < 2 * k div 2" by simp
   222   with k show ?thesis by simp
   222   with k show ?thesis by simp
   223 qed
   223 qed