equal
deleted
inserted
replaced
6 Note: there were previous Isabelle formalizations of unique |
6 Note: there were previous Isabelle formalizations of unique |
7 factorization due to Thomas Marthedal Rasmussen, and, building on |
7 factorization due to Thomas Marthedal Rasmussen, and, building on |
8 that, by Jeremy Avigad and David Gray. |
8 that, by Jeremy Avigad and David Gray. |
9 *) |
9 *) |
10 |
10 |
11 section {* UniqueFactorization *} |
11 section \<open>UniqueFactorization\<close> |
12 |
12 |
13 theory UniqueFactorization |
13 theory UniqueFactorization |
14 imports Cong "~~/src/HOL/Library/Multiset" |
14 imports Cong "~~/src/HOL/Library/Multiset" |
15 begin |
15 begin |
16 |
16 |
32 semirings, using of_nat. Also, is it worth developing bounded quantifiers |
32 semirings, using of_nat. Also, is it worth developing bounded quantifiers |
33 "ALL i :# M. P i"? |
33 "ALL i :# M. P i"? |
34 *) |
34 *) |
35 |
35 |
36 |
36 |
37 subsection {* unique factorization: multiset version *} |
37 subsection \<open>unique factorization: multiset version\<close> |
38 |
38 |
39 lemma multiset_prime_factorization_exists [rule_format]: "n > 0 --> |
39 lemma multiset_prime_factorization_exists [rule_format]: "n > 0 --> |
40 (EX M. (ALL (p::nat) : set_mset M. prime p) & n = (PROD i :# M. i))" |
40 (EX M. (ALL (p::nat) : set_mset M. prime p) & n = (PROD i :# M. i))" |
41 proof (rule nat_less_induct, clarify) |
41 proof (rule nat_less_induct, clarify) |
42 fix n :: nat |
42 fix n :: nat |
152 apply (insert multiset_prime_factorization_unique) |
152 apply (insert multiset_prime_factorization_unique) |
153 apply auto |
153 apply auto |
154 done |
154 done |
155 |
155 |
156 |
156 |
157 subsection {* Prime factors and multiplicity for nats and ints *} |
157 subsection \<open>Prime factors and multiplicity for nats and ints\<close> |
158 |
158 |
159 class unique_factorization = |
159 class unique_factorization = |
160 fixes multiplicity :: "'a \<Rightarrow> 'a \<Rightarrow> nat" |
160 fixes multiplicity :: "'a \<Rightarrow> 'a \<Rightarrow> nat" |
161 and prime_factors :: "'a \<Rightarrow> 'a set" |
161 and prime_factors :: "'a \<Rightarrow> 'a set" |
162 |
162 |
189 instance .. |
189 instance .. |
190 |
190 |
191 end |
191 end |
192 |
192 |
193 |
193 |
194 subsection {* Set up transfer *} |
194 subsection \<open>Set up transfer\<close> |
195 |
195 |
196 lemma transfer_nat_int_prime_factors: "prime_factors (nat n) = nat ` prime_factors n" |
196 lemma transfer_nat_int_prime_factors: "prime_factors (nat n) = nat ` prime_factors n" |
197 unfolding prime_factors_int_def |
197 unfolding prime_factors_int_def |
198 apply auto |
198 apply auto |
199 apply (subst transfer_int_nat_set_return_embed) |
199 apply (subst transfer_int_nat_set_return_embed) |
226 declare transfer_morphism_int_nat[transfer add return: |
226 declare transfer_morphism_int_nat[transfer add return: |
227 transfer_int_nat_prime_factors transfer_int_nat_prime_factors_closure |
227 transfer_int_nat_prime_factors transfer_int_nat_prime_factors_closure |
228 transfer_int_nat_multiplicity] |
228 transfer_int_nat_multiplicity] |
229 |
229 |
230 |
230 |
231 subsection {* Properties of prime factors and multiplicity for nats and ints *} |
231 subsection \<open>Properties of prime factors and multiplicity for nats and ints\<close> |
232 |
232 |
233 lemma prime_factors_ge_0_int [elim]: "p : prime_factors (n::int) \<Longrightarrow> p >= 0" |
233 lemma prime_factors_ge_0_int [elim]: "p : prime_factors (n::int) \<Longrightarrow> p >= 0" |
234 unfolding prime_factors_int_def by auto |
234 unfolding prime_factors_int_def by auto |
235 |
235 |
236 lemma prime_factors_prime_nat [intro]: "p : prime_factors (n::nat) \<Longrightarrow> prime p" |
236 lemma prime_factors_prime_nat [intro]: "p : prime_factors (n::nat) \<Longrightarrow> prime p" |
306 apply force |
306 apply force |
307 apply force |
307 apply force |
308 using assms |
308 using assms |
309 apply (simp add: set_mset_def msetprod_multiplicity) |
309 apply (simp add: set_mset_def msetprod_multiplicity) |
310 done |
310 done |
311 with `f \<in> multiset` have "count (multiset_prime_factorization n) = f" |
311 with \<open>f \<in> multiset\<close> have "count (multiset_prime_factorization n) = f" |
312 by simp |
312 by simp |
313 with S_eq show ?thesis |
313 with S_eq show ?thesis |
314 by (simp add: set_mset_def multiset_def prime_factors_nat_def multiplicity_nat_def) |
314 by (simp add: set_mset_def multiset_def prime_factors_nat_def multiplicity_nat_def) |
315 qed |
315 qed |
316 |
316 |
708 apply (rule dvd_antisym [transferred]) |
708 apply (rule dvd_antisym [transferred]) |
709 apply (auto intro: multiplicity_dvd'_int) |
709 apply (auto intro: multiplicity_dvd'_int) |
710 done |
710 done |
711 |
711 |
712 |
712 |
713 subsection {* An application *} |
713 subsection \<open>An application\<close> |
714 |
714 |
715 lemma gcd_eq_nat: |
715 lemma gcd_eq_nat: |
716 assumes pos [arith]: "x > 0" "y > 0" |
716 assumes pos [arith]: "x > 0" "y > 0" |
717 shows "gcd (x::nat) y = |
717 shows "gcd (x::nat) y = |
718 (PROD p: prime_factors x Un prime_factors y. |
718 (PROD p: prime_factors x Un prime_factors y. |