src/HOL/Library/Primes.thy
changeset 16663 13e9c402308b
parent 15628 9f912f8fd2df
child 16762 aafd23b47a5d
equal deleted inserted replaced
16662:0836569a8ffc 16663:13e9c402308b
    27     (\<forall>d. d dvd m \<and> d dvd n --> d dvd p)"
    27     (\<forall>d. d dvd m \<and> d dvd n --> d dvd p)"
    28 
    28 
    29   coprime :: "nat => nat => bool"
    29   coprime :: "nat => nat => bool"
    30   "coprime m n == gcd (m, n) = 1"
    30   "coprime m n == gcd (m, n) = 1"
    31 
    31 
    32   prime :: "nat set"
    32   prime :: "nat \<Rightarrow> bool"
    33   "prime == {p. 1 < p \<and> (\<forall>m. m dvd p --> m = 1 \<or> m = p)}"
    33   "prime p == 1 < p \<and> (\<forall>m. m dvd p --> m = 1 \<or> m = p)"
    34 
    34 
    35 
    35 
    36 lemma gcd_induct:
    36 lemma gcd_induct:
    37   "(!!m. P m 0) ==>
    37   "(!!m. P m 0) ==>
    38     (!!m n. 0 < n ==> P n (m mod n) ==> P m n)
    38     (!!m n. 0 < n ==> P n (m mod n) ==> P m n)
   170 
   170 
   171 lemma relprime_dvd_mult_iff: "gcd (k, n) = 1 ==> (k dvd m * n) = (k dvd m)"
   171 lemma relprime_dvd_mult_iff: "gcd (k, n) = 1 ==> (k dvd m * n) = (k dvd m)"
   172   apply (blast intro: relprime_dvd_mult dvd_trans)
   172   apply (blast intro: relprime_dvd_mult dvd_trans)
   173   done
   173   done
   174 
   174 
   175 lemma prime_imp_relprime: "p \<in> prime ==> \<not> p dvd n ==> gcd (p, n) = 1"
   175 lemma prime_imp_relprime: "prime p ==> \<not> p dvd n ==> gcd (p, n) = 1"
   176   apply (auto simp add: prime_def)
   176   apply (auto simp add: prime_def)
   177   apply (drule_tac x = "gcd (p, n)" in spec)
   177   apply (drule_tac x = "gcd (p, n)" in spec)
   178   apply auto
   178   apply auto
   179   apply (insert gcd_dvd2 [of p n])
   179   apply (insert gcd_dvd2 [of p n])
   180   apply simp
   180   apply simp
   181   done
   181   done
   182 
   182 
   183 lemma two_is_prime: "2 \<in> prime"
   183 lemma two_is_prime: "prime 2"
   184   apply (auto simp add: prime_def)
   184   apply (auto simp add: prime_def)
   185   apply (case_tac m)
   185   apply (case_tac m)
   186    apply (auto dest!: dvd_imp_le)
   186    apply (auto dest!: dvd_imp_le)
   187   done
   187   done
   188 
   188 
   190   This theorem leads immediately to a proof of the uniqueness of
   190   This theorem leads immediately to a proof of the uniqueness of
   191   factorization.  If @{term p} divides a product of primes then it is
   191   factorization.  If @{term p} divides a product of primes then it is
   192   one of those primes.
   192   one of those primes.
   193 *}
   193 *}
   194 
   194 
   195 lemma prime_dvd_mult: "p \<in> prime ==> p dvd m * n ==> p dvd m \<or> p dvd n"
   195 lemma prime_dvd_mult: "prime p ==> p dvd m * n ==> p dvd m \<or> p dvd n"
   196   by (blast intro: relprime_dvd_mult prime_imp_relprime)
   196   by (blast intro: relprime_dvd_mult prime_imp_relprime)
   197 
   197 
   198 lemma prime_dvd_square: "p \<in> prime ==> p dvd m^Suc (Suc 0) ==> p dvd m"
   198 lemma prime_dvd_square: "prime p ==> p dvd m^Suc (Suc 0) ==> p dvd m"
   199   by (auto dest: prime_dvd_mult)
   199   by (auto dest: prime_dvd_mult)
   200 
   200 
   201 lemma prime_dvd_power_two: "p \<in> prime ==> p dvd m\<twosuperior> ==> p dvd m"
   201 lemma prime_dvd_power_two: "prime p ==> p dvd m\<twosuperior> ==> p dvd m"
   202   by (rule prime_dvd_square) (simp_all add: power2_eq_square)
   202   by (rule prime_dvd_square) (simp_all add: power2_eq_square)
   203 
   203 
   204 
   204 
   205 text {* \medskip Addition laws *}
   205 text {* \medskip Addition laws *}
   206 
   206