# HG changeset patch # User paulson # Date 1391368525 0 # Node ID 413ec965f95dd95aec954589afcfddd426f8de93 # Parent ef601c60ccbea92851750b3c7a3283aa17b98d65 Number_Theory: prime is no longer overloaded, but only for nat. Automatic coercion to int enabled. diff -r ef601c60ccbe -r 413ec965f95d src/HOL/Algebra/Divisibility.thy --- a/src/HOL/Algebra/Divisibility.thy Sat Feb 01 22:02:20 2014 +0100 +++ b/src/HOL/Algebra/Divisibility.thy Sun Feb 02 19:15:25 2014 +0000 @@ -2831,9 +2831,7 @@ proof - interpret weak_lower_semilattice "division_rel G" by simp show ?thesis - apply (simp add: somegcd_meet[OF carr]) - apply (rule meet_closed[simplified], fact+) - done + by (metis carr(1) carr(2) gcd_closed) qed lemma (in gcd_condition_monoid) gcd_divides_l: @@ -2842,9 +2840,7 @@ proof - interpret weak_lower_semilattice "division_rel G" by simp show ?thesis - apply (simp add: somegcd_meet[OF carr]) - apply (rule meet_left[simplified], fact+) - done + by (metis carr(1) carr(2) gcd_isgcd isgcd_def) qed lemma (in gcd_condition_monoid) gcd_divides_r: @@ -2853,9 +2849,7 @@ proof - interpret weak_lower_semilattice "division_rel G" by simp show ?thesis - apply (simp add: somegcd_meet[OF carr]) - apply (rule meet_right[simplified], fact+) - done + by (metis carr gcd_isgcd isgcd_def) qed lemma (in gcd_condition_monoid) gcd_divides: @@ -2865,9 +2859,7 @@ proof - interpret weak_lower_semilattice "division_rel G" by simp show ?thesis - apply (simp add: somegcd_meet L) - apply (rule meet_le[simplified], fact+) - done + by (metis gcd_isgcd isgcd_def assms) qed lemma (in gcd_condition_monoid) gcd_cong_l: @@ -3409,13 +3401,7 @@ from aa2carr carr aa1fs aa2fs have "wfactors G (as'!i # drop (Suc i) as') (as'!i \ aa_2)" - apply (intro wfactors_mult_single) - apply (rule wfactorsE[OF afs'], fast intro: nth_mem[OF len]) - apply (fast intro: nth_mem[OF len]) - apply fast - apply fast - apply assumption - done + by (metis irrasi wfactors_mult_single) with len carr aa1carr aa2carr aa1fs have v2: "wfactors G (take i as' @ as'!i # drop (Suc i) as') (aa_1 \ (as'!i \ aa_2))" apply (intro wfactors_mult) @@ -3429,23 +3415,15 @@ with carr have eer: "essentially_equal G (take i as' @ as'!i # drop (Suc i) as') as'" by simp - with v2 afs' carr aa1carr aa2carr nth_mem[OF len] have "aa_1 \ (as'!i \ aa_2) \ a" - apply (intro ee_wfactorsD[of "take i as' @ as'!i # drop (Suc i) as'" "as'"]) - apply fast+ - apply (simp, fast) - done + by (metis as' ee_wfactorsD m_closed) then have t1: "as'!i \ (aa_1 \ aa_2) \ a" - apply (simp add: m_assoc[symmetric]) - apply (simp add: m_comm) - done + by (metis aa1carr aa2carr asicarr m_lcomm) from carr asiah have "ah \ (aa_1 \ aa_2) \ as'!i \ (aa_1 \ aa_2)" - apply (intro mult_cong_l) - apply (fast intro: associated_sym, simp+) - done + by (metis associated_sym m_closed mult_cong_l) also note t1 finally have "ah \ (aa_1 \ aa_2) \ a" by simp @@ -3530,7 +3508,6 @@ where ascarr[simp]: "set as \ carrier G" and afs: "wfactors G as a" by (auto simp del: carr) - have "ALL as'. set as' \ carrier G \ wfactors G as' a \ length as = length as'" by (metis afs ascarr assms ee_length wfactors_unique) thus "EX c. ALL as'. set as' \ carrier G \ wfactors G as' a \ c = length as'" .. @@ -3549,8 +3526,7 @@ apply (simp add: factorcount_def) apply (rule theI2) apply (rule alen) - apply (elim allE[of _ "as"], rule allE[OF alen, of "as"], simp add: ascarr afs) - apply (elim allE[of _ "as"], rule allE[OF alen, of "as"], simp add: ascarr afs) + apply (metis afs alen ascarr)+ done from ascarr afs have "ac = length as" by (iprover intro: alen[rule_format]) diff -r ef601c60ccbe -r 413ec965f95d src/HOL/Algebra/IntRing.thy --- a/src/HOL/Algebra/IntRing.thy Sat Feb 01 22:02:20 2014 +0100 +++ b/src/HOL/Algebra/IntRing.thy Sun Feb 02 19:15:25 2014 +0000 @@ -239,14 +239,10 @@ lemma multiples_principalideal: "principalideal {x * a | x. True } \" -apply (subst int_Idl[symmetric], rule principalidealI) - apply (rule int.genideal_ideal, simp) -apply fast -done - +by (metis UNIV_I int.cgenideal_eq_genideal int.cgenideal_is_principalideal int_Idl) lemma prime_primeideal: - assumes prime: "prime (nat p)" + assumes prime: "prime p" shows "primeideal (Idl\<^bsub>\\<^esub> {p}) \" apply (rule primeidealI) apply (rule int.genideal_ideal, simp) @@ -257,48 +253,18 @@ apply (elim exE) proof - fix a b x - have ppos: "0 <= p" - by (metis prime linear nat_0_iff zero_not_prime_nat) - have unnat: "!!x. nat p dvd nat (abs x) ==> p dvd x" - proof - - fix x - assume "nat p dvd nat (abs x)" - hence "int (nat p) dvd x" by (simp add: int_dvd_iff[symmetric]) - thus "p dvd x" by (simp add: ppos) - qed - assume "a * b = x * p" + assume "a * b = x * int p" hence "p dvd a * b" by simp - hence "nat p dvd nat (abs (a * b))" using ppos by (simp add: nat_dvd_iff) - hence "nat p dvd (nat (abs a) * nat (abs b))" by (simp add: nat_abs_mult_distrib) - hence "nat p dvd nat (abs a) | nat p dvd nat (abs b)" - by (metis prime prime_dvd_mult_eq_nat) - hence "p dvd a | p dvd b" by (fast intro: unnat) - thus "(EX x. a = x * p) | (EX x. b = x * p)" - proof - assume "p dvd a" - hence "EX x. a = p * x" by (simp add: dvd_def) - then obtain x - where "a = p * x" by fast - hence "a = x * p" by simp - hence "EX x. a = x * p" by simp - thus "(EX x. a = x * p) | (EX x. b = x * p)" .. - next - assume "p dvd b" - hence "EX x. b = p * x" by (simp add: dvd_def) - then obtain x - where "b = p * x" by fast - hence "b = x * p" by simp - hence "EX x. b = x * p" by simp - thus "(EX x. a = x * p) | (EX x. b = x * p)" .. - qed + hence "p dvd a | p dvd b" + by (metis prime prime_dvd_mult_eq_int) + thus "(\x. a = x * int p) \ (\x. b = x * int p)" + by (metis dvd_def mult_commute) next - assume "UNIV = {uu. EX x. uu = x * p}" - then obtain x where "1 = x * p" by best - then have "p * x = 1" by (metis mult_commute) - hence "\p * x\ = 1" by simp - hence "\p\ = 1" by (rule abs_zmult_eq_1) - then show "False" - by (metis prime abs_of_pos one_not_prime_int prime_gt_0_int prime_int_def) + assume "UNIV = {uu. EX x. uu = x * int p}" + then obtain x where "1 = x * int p" by best + hence "\int p * x\ = 1" by (simp add: mult_commute) + then show False + by (metis abs_of_nat int_1 of_nat_eq_iff abs_zmult_eq_1 one_not_prime_nat prime) qed @@ -454,7 +420,7 @@ done lemma ZFact_prime_is_domain: - assumes pprime: "prime (nat p)" + assumes pprime: "prime p" shows "domain (ZFact p)" apply (unfold ZFact_def) apply (rule primeideal.quotient_is_domain) diff -r ef601c60ccbe -r 413ec965f95d src/HOL/Number_Theory/Cong.thy --- a/src/HOL/Number_Theory/Cong.thy Sat Feb 01 22:02:20 2014 +0100 +++ b/src/HOL/Number_Theory/Cong.thy Sun Feb 02 19:15:25 2014 +0000 @@ -261,7 +261,8 @@ by (simp add: cong_altdef_int) lemma cong_square_int: - "\ prime (p::int); 0 < a; [a * a = 1] (mod p) \ + fixes a::int + shows "\ prime p; 0 < a; [a * a = 1] (mod p) \ \ [a = 1] (mod p) \ [a = - 1] (mod p)" apply (simp only: cong_altdef_int) apply (subst prime_dvd_mult_eq_int [symmetric], assumption) diff -r ef601c60ccbe -r 413ec965f95d src/HOL/Number_Theory/Primes.thy --- a/src/HOL/Number_Theory/Primes.thy Sat Feb 01 22:02:20 2014 +0100 +++ b/src/HOL/Number_Theory/Primes.thy Sun Feb 02 19:15:25 2014 +0000 @@ -32,129 +32,76 @@ begin declare One_nat_def [simp] - -class prime = one + - fixes prime :: "'a \ bool" - -instantiation nat :: prime -begin - -definition prime_nat :: "nat \ bool" - where "prime_nat p = (1 < p \ (\m. m dvd p --> m = 1 \ m = p))" - -instance .. - -end - -instantiation int :: prime -begin - -definition prime_int :: "int \ bool" - where "prime_int p = prime (nat p)" +declare [[coercion int]] +declare [[coercion_enabled]] -instance .. - -end - - -subsection {* Set up Transfer *} +definition prime :: "nat \ bool" + where "prime p = (1 < p \ (\m. m dvd p --> m = 1 \ m = p))" -lemma transfer_nat_int_prime: - "(x::int) >= 0 \ prime (nat x) = prime x" - unfolding gcd_int_def lcm_int_def prime_int_def by auto - -declare transfer_morphism_nat_int[transfer add return: - transfer_nat_int_prime] - -lemma transfer_int_nat_prime: "prime (int x) = prime x" - unfolding gcd_int_def lcm_int_def prime_int_def by auto - -declare transfer_morphism_int_nat[transfer add return: - transfer_int_nat_prime] +lemmas prime_nat_def = prime_def subsection {* Primes *} -lemma prime_odd_nat: "prime (p::nat) \ p > 2 \ odd p" +lemma prime_odd_nat: "prime p \ p > 2 \ odd p" apply (auto simp add: prime_nat_def even_def dvd_eq_mod_eq_0) apply (metis dvd_eq_mod_eq_0 even_Suc even_def mod_by_1 nat_dvd_not_less not_mod_2_eq_0_eq_1 zero_less_numeral) done -lemma prime_odd_int: "prime (p::int) \ p > 2 \ odd p" - unfolding prime_int_def - apply (frule prime_odd_nat) - apply (auto simp add: even_nat_def) - done - (* FIXME Is there a better way to handle these, rather than making them elim rules? *) -lemma prime_ge_0_nat [elim]: "prime (p::nat) \ p >= 0" - unfolding prime_nat_def by auto - -lemma prime_gt_0_nat [elim]: "prime (p::nat) \ p > 0" - unfolding prime_nat_def by auto - -lemma prime_ge_1_nat [elim]: "prime (p::nat) \ p >= 1" +lemma prime_gt_0_nat [elim]: "prime p \ p > 0" unfolding prime_nat_def by auto -lemma prime_gt_1_nat [elim]: "prime (p::nat) \ p > 1" +lemma prime_ge_1_nat [elim]: "prime p \ p >= 1" unfolding prime_nat_def by auto -lemma prime_ge_Suc_0_nat [elim]: "prime (p::nat) \ p >= Suc 0" - unfolding prime_nat_def by auto - -lemma prime_gt_Suc_0_nat [elim]: "prime (p::nat) \ p > Suc 0" - unfolding prime_nat_def by auto - -lemma prime_ge_2_nat [elim]: "prime (p::nat) \ p >= 2" +lemma prime_gt_1_nat [elim]: "prime p \ p > 1" unfolding prime_nat_def by auto -lemma prime_ge_0_int [elim]: "prime (p::int) \ p >= 0" - unfolding prime_int_def prime_nat_def by auto - -lemma prime_gt_0_int [elim]: "prime (p::int) \ p > 0" - unfolding prime_int_def prime_nat_def by auto - -lemma prime_ge_1_int [elim]: "prime (p::int) \ p >= 1" - unfolding prime_int_def prime_nat_def by auto - -lemma prime_gt_1_int [elim]: "prime (p::int) \ p > 1" - unfolding prime_int_def prime_nat_def by auto +lemma prime_ge_Suc_0_nat [elim]: "prime p \ p >= Suc 0" + unfolding prime_nat_def by auto -lemma prime_ge_2_int [elim]: "prime (p::int) \ p >= 2" - unfolding prime_int_def prime_nat_def by auto - +lemma prime_gt_Suc_0_nat [elim]: "prime p \ p > Suc 0" + unfolding prime_nat_def by auto -lemma prime_int_altdef: "prime (p::int) = (1 < p \ (\m \ 0. m dvd p \ - m = 1 \ m = p))" - using prime_nat_def [transferred] - apply (cases "p >= 0") - apply blast - apply (auto simp add: prime_ge_0_int) - done +lemma prime_ge_2_nat [elim]: "prime p \ p >= 2" + unfolding prime_nat_def by auto -lemma prime_imp_coprime_nat: "prime (p::nat) \ \ p dvd n \ coprime p n" +lemma prime_imp_coprime_nat: "prime p \ \ p dvd n \ coprime p n" apply (unfold prime_nat_def) apply (metis gcd_dvd1_nat gcd_dvd2_nat) done -lemma prime_imp_coprime_int: "prime (p::int) \ \ p dvd n \ coprime p n" +lemma prime_int_altdef: + "prime p = (1 < p \ (\m::int. m \ 0 \ m dvd p \ + m = 1 \ m = p))" + apply (simp add: prime_def) + apply (auto simp add: ) + apply (metis One_nat_def int_1 nat_0_le nat_dvd_iff) + apply (metis zdvd_int One_nat_def le0 of_nat_0 of_nat_1 of_nat_eq_iff of_nat_le_iff) + done + +lemma prime_imp_coprime_int: + fixes n::int shows "prime p \ \ p dvd n \ coprime p n" apply (unfold prime_int_altdef) apply (metis gcd_dvd1_int gcd_dvd2_int gcd_ge_0_int) done -lemma prime_dvd_mult_nat: "prime (p::nat) \ p dvd m * n \ p dvd m \ p dvd n" +lemma prime_dvd_mult_nat: "prime p \ p dvd m * n \ p dvd m \ p dvd n" by (blast intro: coprime_dvd_mult_nat prime_imp_coprime_nat) -lemma prime_dvd_mult_int: "prime (p::int) \ p dvd m * n \ p dvd m \ p dvd n" +lemma prime_dvd_mult_int: + fixes n::int shows "prime p \ p dvd m * n \ p dvd m \ p dvd n" by (blast intro: coprime_dvd_mult_int prime_imp_coprime_int) -lemma prime_dvd_mult_eq_nat [simp]: "prime (p::nat) \ +lemma prime_dvd_mult_eq_nat [simp]: "prime p \ p dvd m * n = (p dvd m \ p dvd n)" by (rule iffI, rule prime_dvd_mult_nat, auto) -lemma prime_dvd_mult_eq_int [simp]: "prime (p::int) \ - p dvd m * n = (p dvd m \ p dvd n)" +lemma prime_dvd_mult_eq_int [simp]: + fixes n::int + shows "prime p \ p dvd m * n = (p dvd m \ p dvd n)" by (rule iffI, rule prime_dvd_mult_int, auto) lemma not_prime_eq_prod_nat: "(n::nat) > 1 \ ~ prime n \ @@ -163,25 +110,20 @@ by (metis mult_commute linorder_neq_iff linorder_not_le mult_1 n_less_n_mult_m one_le_mult_iff less_imp_le_nat) -lemma not_prime_eq_prod_int: "(n::int) > 1 \ ~ prime n \ - EX m k. n = m * k & 1 < m & m < n & 1 < k & k < n" - unfolding prime_int_altdef dvd_def - apply auto - by (metis div_mult_self1_is_id div_mult_self2_is_id - int_div_less_self int_one_le_iff_zero_less zero_less_mult_pos less_le) - -lemma prime_dvd_power_nat: "prime (p::nat) \ p dvd x^n \ p dvd x" +lemma prime_dvd_power_nat: "prime p \ p dvd x^n \ p dvd x" by (induct n) auto -lemma prime_dvd_power_int: "prime (p::int) \ p dvd x^n \ p dvd x" - by (induct n) (auto simp: prime_ge_0_int) +lemma prime_dvd_power_int: + fixes x::int shows "prime p \ p dvd x^n \ p dvd x" + by (induct n) auto -lemma prime_dvd_power_nat_iff: "prime (p::nat) \ n > 0 \ +lemma prime_dvd_power_nat_iff: "prime p \ n > 0 \ p dvd x^n \ p dvd x" by (cases n) (auto elim: prime_dvd_power_nat) -lemma prime_dvd_power_int_iff: "prime (p::int) \ n > 0 \ - p dvd x^n \ p dvd x" +lemma prime_dvd_power_int_iff: + fixes x::int + shows "prime p \ n > 0 \ p dvd x^n \ p dvd x" by (cases n) (auto elim: prime_dvd_power_int) @@ -190,80 +132,47 @@ lemma zero_not_prime_nat [simp]: "~prime (0::nat)" by (simp add: prime_nat_def) -lemma zero_not_prime_int [simp]: "~prime (0::int)" - by (simp add: prime_int_def) - lemma one_not_prime_nat [simp]: "~prime (1::nat)" by (simp add: prime_nat_def) lemma Suc_0_not_prime_nat [simp]: "~prime (Suc 0)" by (simp add: prime_nat_def) -lemma one_not_prime_int [simp]: "~prime (1::int)" - by (simp add: prime_int_def) - lemma prime_nat_code [code]: - "prime (p::nat) \ p > 1 \ (\n \ {1<.. p > 1 \ (\n \ {1<.. p > 1 \ (\n \ set [2.. n dvd p)" + "prime p \ p > 1 \ (\n \ set [2.. n dvd p)" by (auto simp add: prime_nat_code) lemmas prime_nat_simp_numeral [simp] = prime_nat_simp [of "numeral m"] for m -lemma prime_int_code [code]: - "prime (p::int) \ p > 1 \ (\n \ {1<.. p > 1 \ (\n \ set [2..p - 1]. ~ n dvd p)" - by (auto simp add: prime_int_code) - -lemmas prime_int_simp_numeral [simp] = prime_int_simp [of "numeral m"] for m - lemma two_is_prime_nat [simp]: "prime (2::nat)" by simp -lemma two_is_prime_int [simp]: "prime (2::int)" - by simp - text{* A bit of regression testing: *} lemma "prime(97::nat)" by simp -lemma "prime(97::int)" by simp lemma "prime(997::nat)" by eval -lemma "prime(997::int)" by eval -lemma prime_imp_power_coprime_nat: "prime (p::nat) \ ~ p dvd a \ coprime a (p^m)" +lemma prime_imp_power_coprime_nat: "prime p \ ~ p dvd a \ coprime a (p^m)" by (metis coprime_exp_nat gcd_nat.commute prime_imp_coprime_nat) -lemma prime_imp_power_coprime_int: "prime (p::int) \ ~ p dvd a \ coprime a (p^m)" +lemma prime_imp_power_coprime_int: + fixes a::int shows "prime p \ ~ p dvd a \ coprime a (p^m)" by (metis coprime_exp_int gcd_int.commute prime_imp_coprime_int) -lemma primes_coprime_nat: "prime (p::nat) \ prime q \ p \ q \ coprime p q" +lemma primes_coprime_nat: "prime p \ prime q \ p \ q \ coprime p q" by (metis gcd_nat.absorb1 gcd_nat.absorb2 prime_imp_coprime_nat) -lemma primes_coprime_int: "prime (p::int) \ prime q \ p \ q \ coprime p q" - by (metis leD linear prime_gt_0_int prime_imp_coprime_int prime_int_altdef) - lemma primes_imp_powers_coprime_nat: - "prime (p::nat) \ prime q \ p ~= q \ coprime (p^m) (q^n)" + "prime p \ prime q \ p ~= q \ coprime (p^m) (q^n)" by (rule coprime_exp2_nat, rule primes_coprime_nat) -lemma primes_imp_powers_coprime_int: - "prime (p::int) \ prime q \ p ~= q \ coprime (p^m) (q^n)" - by (rule coprime_exp2_int, rule primes_coprime_int) - lemma prime_factor_nat: "n \ (1::nat) \ \ p. prime p \ p dvd n" apply (induct n rule: nat_less_induct) apply (case_tac "n = 0") @@ -276,7 +185,7 @@ text {* One property of coprimality is easier to prove via prime factors. *} lemma prime_divprod_pow_nat: - assumes p: "prime (p::nat)" and ab: "coprime a b" and pab: "p^n dvd a * b" + assumes p: "prime p" and ab: "coprime a b" and pab: "p^n dvd a * b" shows "p^n dvd a \ p^n dvd b" proof- { assume "n = 0 \ a = 1 \ b = 1" with pab have ?thesis @@ -316,7 +225,7 @@ subsection {* Infinitely many primes *} -lemma next_prime_bound: "\(p::nat). prime p \ n < p \ p <= fact n + 1" +lemma next_prime_bound: "\p. prime p \ n < p \ p <= fact n + 1" proof- have f1: "fact n + 1 \ 1" using fact_ge_one_nat [of n] by arith from prime_factor_nat [OF f1] diff -r ef601c60ccbe -r 413ec965f95d src/HOL/Number_Theory/Residues.thy --- a/src/HOL/Number_Theory/Residues.thy Sat Feb 01 22:02:20 2014 +0100 +++ b/src/HOL/Number_Theory/Residues.thy Sun Feb 02 19:15:25 2014 +0000 @@ -14,7 +14,6 @@ MiscAlgebra begin - (* A locale for residue rings @@ -235,13 +234,14 @@ (* prime residues *) locale residues_prime = - fixes p :: int and R (structure) + fixes p and R (structure) assumes p_prime [intro]: "prime p" defines "R == residue_ring p" sublocale residues_prime < residues p apply (unfold R_def residues_def) using p_prime apply auto + apply (metis (full_types) int_1 of_nat_less_iff prime_gt_1_nat) done context residues_prime @@ -357,26 +357,26 @@ done lemma fermat_theorem: + fixes a::int assumes "prime p" and "~ (p dvd a)" - shows "[a^(nat p - 1) = 1] (mod p)" + shows "[a^(p - 1) = 1] (mod p)" proof - from assms have "[a^phi p = 1] (mod p)" apply (intro euler_theorem) - (* auto should get this next part. matching across - substitutions is needed. *) - apply (frule prime_gt_1_int, arith) - apply (subst gcd_commute_int, erule prime_imp_coprime_int, assumption) + apply (metis of_nat_0_le_iff) + apply (metis gcd_int.commute prime_imp_coprime_int) done also have "phi p = nat p - 1" by (rule phi_prime, rule assms) - finally show ?thesis . + finally show ?thesis + by (metis nat_int) qed lemma fermat_theorem_nat: assumes "prime p" and "~ (p dvd a)" shows "[a^(p - 1) = 1] (mod p)" using fermat_theorem [of p a] assms -by (metis int_1 nat_int of_nat_power prime_int_def transfer_int_nat_cong zdvd_int) +by (metis int_1 of_nat_power transfer_int_nat_cong zdvd_int) subsection {* Wilson's theorem *} @@ -445,18 +445,20 @@ apply auto done also have "\ = fact (p - 1) mod p" - apply (subst fact_altdef_int) - apply (insert assms, force) - apply (subst res_prime_units_eq, rule refl) + apply (subst fact_altdef_nat) + apply (insert assms) + apply (subst res_prime_units_eq) + apply (simp add: int_setprod zmod_int setprod_int_eq) done finally have "fact (p - 1) mod p = \ \". - then show ?thesis by (simp add: res_to_cong_simps) + then show ?thesis + by (metis Divides.transfer_int_nat_functions(2) cong_int_def res_neg_eq res_one_eq) qed -lemma wilson_theorem: "prime (p::int) \ [fact (p - 1) = - 1] (mod p)" - apply (frule prime_gt_1_int) +lemma wilson_theorem: "prime p \ [fact (p - 1) = - 1] (mod p)" + apply (frule prime_gt_1_nat) apply (case_tac "p = 2") - apply (subst fact_altdef_int, simp) + apply (subst fact_altdef_nat, simp) apply (subst cong_int_def) apply simp apply (rule residues_prime.wilson_theorem1) diff -r ef601c60ccbe -r 413ec965f95d src/HOL/Number_Theory/UniqueFactorization.thy --- a/src/HOL/Number_Theory/UniqueFactorization.thy Sat Feb 01 22:02:20 2014 +0100 +++ b/src/HOL/Number_Theory/UniqueFactorization.thy Sun Feb 02 19:15:25 2014 +0000 @@ -242,7 +242,7 @@ lemma prime_factors_prime_int [intro]: assumes "n >= 0" and "p : prime_factors (n::int)" shows "prime p" - apply (rule prime_factors_prime_nat [transferred, of n p]) + apply (rule prime_factors_prime_nat [transferred, of n p, simplified]) using assms apply auto done @@ -252,8 +252,7 @@ done lemma prime_factors_gt_0_int [elim]: "x >= 0 \ p : prime_factors x \ - p > (0::int)" - apply (frule (1) prime_factors_prime_int) + int p > (0::int)" apply auto done @@ -307,7 +306,7 @@ apply force apply force using assms - apply (simp add: Abs_multiset_inverse set_of_def msetprod_multiplicity) + apply (simp add: set_of_def msetprod_multiplicity) done with `f \ multiset` have "count (multiset_prime_factorization n) = f" by (simp add: Abs_multiset_inverse) @@ -354,14 +353,15 @@ done lemma prime_factors_characterization_int: "S = {p. 0 < f (p::int)} \ - finite S \ (ALL p:S. prime p) \ n = (PROD p:S. p ^ f p) \ + finite S \ (ALL p:S. prime (nat p)) \ n = (PROD p:S. p ^ f p) \ prime_factors n = S" apply simp apply (subgoal_tac "{p. 0 < f p} = {p. 0 <= p & 0 < f p}") apply (simp only:) apply (subst primes_characterization'_int) apply auto - apply (auto simp add: prime_ge_0_int) + apply (metis nat_int) + apply (metis le_cases nat_le_0 zero_not_prime_nat) done lemma multiplicity_characterization_nat: "S = {p. 0 < f (p::nat)} \ @@ -390,14 +390,15 @@ done lemma multiplicity_characterization_int: "S = {p. 0 < f (p::int)} \ - finite S \ (ALL p:S. prime p) \ n = (PROD p:S. p ^ f p) \ + finite S \ (ALL p:S. prime (nat p)) \ n = (PROD p:S. p ^ f p) \ p >= 0 \ multiplicity p n = f p" apply simp apply (subgoal_tac "{p. 0 < f p} = {p. 0 <= p & 0 < f p}") apply (simp only:) apply (subst multiplicity_characterization'_int) apply auto - apply (auto simp add: prime_ge_0_int) + apply (metis nat_int) + apply (metis le_cases nat_le_0 zero_not_prime_nat) done lemma multiplicity_zero_nat [simp]: "multiplicity (p::nat) 0 = 0" @@ -415,25 +416,20 @@ lemma multiplicity_one_int [simp]: "multiplicity p (1::int) = 0" by (metis multiplicity_int_def multiplicity_one_nat' transfer_nat_int_numerals(2)) -lemma multiplicity_prime_nat [simp]: "prime (p::nat) \ multiplicity p p = 1" +lemma multiplicity_prime_nat [simp]: "prime p \ multiplicity p p = 1" apply (subst multiplicity_characterization_nat [where f = "(%q. if q = p then 1 else 0)"]) apply auto by (metis (full_types) less_not_refl) -lemma multiplicity_prime_int [simp]: "prime (p::int) \ multiplicity p p = 1" - unfolding prime_int_def multiplicity_int_def by auto - -lemma multiplicity_prime_power_nat [simp]: "prime (p::nat) \ multiplicity p (p^n) = n" +lemma multiplicity_prime_power_nat [simp]: "prime p \ multiplicity p (p^n) = n" apply (cases "n = 0") apply auto apply (subst multiplicity_characterization_nat [where f = "(%q. if q = p then n else 0)"]) apply auto by (metis (full_types) less_not_refl) -lemma multiplicity_prime_power_int [simp]: "prime (p::int) \ multiplicity p (p^n) = n" - apply (frule prime_ge_0_int) - apply (auto simp add: prime_int_def multiplicity_int_def nat_power_eq) - done +lemma multiplicity_prime_power_int [simp]: "prime p \ multiplicity p ( (int p)^n) = n" + by (metis multiplicity_prime_power_nat of_nat_power transfer_int_nat_multiplicity) lemma multiplicity_nonprime_nat [simp]: "~ prime (p::nat) \ multiplicity p n = 0" apply (cases "n = 0") @@ -442,9 +438,6 @@ apply (auto simp add: set_of_def multiplicity_nat_def) done -lemma multiplicity_nonprime_int [simp]: "~ prime (p::int) \ multiplicity p n = 0" - unfolding multiplicity_int_def prime_int_def by auto - lemma multiplicity_not_factor_nat [simp]: "p ~: prime_factors (n::nat) \ multiplicity p n = 0" apply (subst (asm) prime_factors_altdef_nat) @@ -584,18 +577,17 @@ (* Here the issue with transfer is the implicit quantifier over S *) lemma multiplicity_prod_prime_powers_int: - "(p::int) >= 0 \ finite S \ (ALL p : S. prime p) \ + "(p::int) >= 0 \ finite S \ (ALL p:S. prime (nat p)) \ multiplicity p (PROD p : S. p ^ f p) = (if p : S then f p else 0)" apply (subgoal_tac "int ` nat ` S = S") apply (frule multiplicity_prod_prime_powers_nat [where f = "%x. f(int x)" and S = "nat ` S", transferred]) apply auto - apply (metis prime_int_def) - apply (metis prime_ge_0_int) - apply (metis nat_set_def prime_ge_0_int transfer_nat_int_set_return_embed) + apply (metis linear nat_0_iff zero_not_prime_nat) + apply (metis (full_types) image_iff int_nat_eq less_le less_linear nat_0_iff zero_not_prime_nat) done -lemma multiplicity_distinct_prime_power_nat: "prime (p::nat) \ prime q \ +lemma multiplicity_distinct_prime_power_nat: "prime p \ prime q \ p ~= q \ multiplicity p (q^n) = 0" apply (subgoal_tac "q^n = setprod (%x. x^n) {q}") apply (erule ssubst) @@ -603,14 +595,10 @@ apply auto done -lemma multiplicity_distinct_prime_power_int: "prime (p::int) \ prime q \ - p ~= q \ multiplicity p (q^n) = 0" - apply (frule prime_ge_0_int [of q]) - apply (frule multiplicity_distinct_prime_power_nat [transferred leaving: n]) - prefer 4 - apply assumption - apply auto - done +lemma multiplicity_distinct_prime_power_int: "prime p \ prime q \ + p ~= q \ multiplicity p (int q ^ n) = 0" + by (metis multiplicity_distinct_prime_power_nat of_nat_power transfer_int_nat_multiplicity) + lemma dvd_multiplicity_nat: "(0::nat) < y \ x dvd y \ multiplicity p x <= multiplicity p y" @@ -670,11 +658,12 @@ by (metis gcd_lcm_complete_lattice_nat.top_greatest le_refl multiplicity_dvd_nat multiplicity_nonprime_nat neq0_conv) -lemma multiplicity_dvd'_int: "(0::int) < x \ 0 <= y \ +lemma multiplicity_dvd'_int: + fixes x::int and y::int + shows "0 < x \ 0 <= y \ \p. prime p \ multiplicity p x \ multiplicity p y \ x dvd y" - by (metis eq_imp_le gcd_lcm_complete_lattice_nat.top_greatest int_eq_0_conv - multiplicity_dvd_int multiplicity_nonprime_int nat_int transfer_nat_int_relations(4) - less_le) +by (metis GCD.dvd_int_iff abs_int_eq multiplicity_dvd'_nat multiplicity_int_def nat_int + zero_le_imp_eq_int zero_less_imp_eq_int) lemma dvd_multiplicity_eq_nat: "0 < (x::nat) \ 0 < y \ (x dvd y) = (ALL p. multiplicity p x <= multiplicity p y)" @@ -700,11 +689,7 @@ lemma prime_factors_altdef2_int: assumes "(n::int) > 0" shows "(p : prime_factors n) = (prime p & p dvd n)" - apply (cases "p >= 0") - apply (rule prime_factors_altdef2_nat [transferred]) - using assms apply auto - apply (auto simp add: prime_ge_0_int prime_factors_ge_0_int) - done +using assms by (simp add: prime_factors_altdef2_nat [transferred]) lemma multiplicity_eq_nat: fixes x and y::nat diff -r ef601c60ccbe -r 413ec965f95d src/HOL/Set_Interval.thy --- a/src/HOL/Set_Interval.thy Sat Feb 01 22:02:20 2014 +0100 +++ b/src/HOL/Set_Interval.thy Sun Feb 02 19:15:25 2014 +0000 @@ -1635,4 +1635,18 @@ transfer_int_nat_set_function_closures ] +lemma setprod_int_plus_eq: "setprod int {i..i+j} = \{int i..int (i+j)}" + by (induct j) (auto simp add: atLeastAtMostSuc_conv atLeastAtMostPlus1_int_conv) + +lemma setprod_int_eq: "setprod int {i..j} = \{int i..int j}" +proof (cases "i \ j") + case True + then show ?thesis + by (metis Nat.le_iff_add setprod_int_plus_eq) +next + case False + then show ?thesis + by auto +qed + end