src/HOL/Algebra/Divisibility.thy
changeset 35847 19f1f7066917
parent 35416 d8d7d1b785af
child 35848 5443079512ea
equal deleted inserted replaced
35846:2ae4b7585501 35847:19f1f7066917
   158 
   158 
   159 subsection {* Divisibility and Association *}
   159 subsection {* Divisibility and Association *}
   160 
   160 
   161 subsubsection {* Function definitions *}
   161 subsubsection {* Function definitions *}
   162 
   162 
   163 constdefs (structure G)
   163 definition
   164   factor :: "[_, 'a, 'a] \<Rightarrow> bool" (infix "divides\<index>" 65)
   164   factor :: "[_, 'a, 'a] \<Rightarrow> bool" (infix "divides\<index>" 65)
   165   "a divides b == \<exists>c\<in>carrier G. b = a \<otimes> c"
   165   where "a divides\<^bsub>G\<^esub> b == \<exists>c\<in>carrier G. b = a \<otimes>\<^bsub>G\<^esub> c"
   166 
   166 
   167 constdefs (structure G)
   167 definition
   168   associated :: "[_, 'a, 'a] => bool" (infix "\<sim>\<index>" 55)
   168   associated :: "[_, 'a, 'a] => bool" (infix "\<sim>\<index>" 55)
   169   "a \<sim> b == a divides b \<and> b divides a"
   169   where "a \<sim>\<^bsub>G\<^esub> b == a divides\<^bsub>G\<^esub> b \<and> b divides\<^bsub>G\<^esub> a"
   170 
   170 
   171 abbreviation
   171 abbreviation
   172   "division_rel G == \<lparr>carrier = carrier G, eq = op \<sim>\<^bsub>G\<^esub>, le = op divides\<^bsub>G\<^esub>\<rparr>"
   172   "division_rel G == \<lparr>carrier = carrier G, eq = op \<sim>\<^bsub>G\<^esub>, le = op divides\<^bsub>G\<^esub>\<rparr>"
   173 
   173 
   174 constdefs (structure G)
   174 definition
   175   properfactor :: "[_, 'a, 'a] \<Rightarrow> bool"
   175   properfactor :: "[_, 'a, 'a] \<Rightarrow> bool"
   176   "properfactor G a b == a divides b \<and> \<not>(b divides a)"
   176   where "properfactor G a b == a divides\<^bsub>G\<^esub> b \<and> \<not>(b divides\<^bsub>G\<^esub> a)"
   177 
   177 
   178 constdefs (structure G)
   178 definition
   179   irreducible :: "[_, 'a] \<Rightarrow> bool"
   179   irreducible :: "[_, 'a] \<Rightarrow> bool"
   180   "irreducible G a == a \<notin> Units G \<and> (\<forall>b\<in>carrier G. properfactor G b a \<longrightarrow> b \<in> Units G)"
   180   where "irreducible G a == a \<notin> Units G \<and> (\<forall>b\<in>carrier G. properfactor G b a \<longrightarrow> b \<in> Units G)"
   181 
   181 
   182 constdefs (structure G)
   182 definition
   183   prime :: "[_, 'a] \<Rightarrow> bool"
   183   prime :: "[_, 'a] \<Rightarrow> bool" where
   184   "prime G p == p \<notin> Units G \<and> 
   184   "prime G p ==
   185                 (\<forall>a\<in>carrier G. \<forall>b\<in>carrier G. p divides (a \<otimes> b) \<longrightarrow> p divides a \<or> p divides b)"
   185     p \<notin> Units G \<and> 
   186 
   186     (\<forall>a\<in>carrier G. \<forall>b\<in>carrier G. p divides\<^bsub>G\<^esub> (a \<otimes>\<^bsub>G\<^esub> b) \<longrightarrow> p divides\<^bsub>G\<^esub> a \<or> p divides\<^bsub>G\<^esub> b)"
   187 
   187 
   188 
   188 
   189 subsubsection {* Divisibility *}
   189 subsubsection {* Divisibility *}
   190 
   190 
   191 lemma dividesI:
   191 lemma dividesI:
  1039 
  1039 
  1040 subsection {* Factorization and Factorial Monoids *}
  1040 subsection {* Factorization and Factorial Monoids *}
  1041 
  1041 
  1042 subsubsection {* Function definitions *}
  1042 subsubsection {* Function definitions *}
  1043 
  1043 
  1044 constdefs (structure G)
  1044 definition
  1045   factors :: "[_, 'a list, 'a] \<Rightarrow> bool"
  1045   factors :: "[_, 'a list, 'a] \<Rightarrow> bool"
  1046   "factors G fs a == (\<forall>x \<in> (set fs). irreducible G x) \<and> foldr (op \<otimes>) fs \<one> = a"
  1046   where "factors G fs a == (\<forall>x \<in> (set fs). irreducible G x) \<and> foldr (op \<otimes>\<^bsub>G\<^esub>) fs \<one>\<^bsub>G\<^esub> = a"
  1047 
  1047 
       
  1048 definition
  1048   wfactors ::"[_, 'a list, 'a] \<Rightarrow> bool"
  1049   wfactors ::"[_, 'a list, 'a] \<Rightarrow> bool"
  1049   "wfactors G fs a == (\<forall>x \<in> (set fs). irreducible G x) \<and> foldr (op \<otimes>) fs \<one> \<sim> a"
  1050   where "wfactors G fs a == (\<forall>x \<in> (set fs). irreducible G x) \<and> foldr (op \<otimes>\<^bsub>G\<^esub>) fs \<one>\<^bsub>G\<^esub> \<sim>\<^bsub>G\<^esub> a"
  1050 
  1051 
  1051 abbreviation
  1052 abbreviation
  1052   list_assoc :: "('a,_) monoid_scheme \<Rightarrow> 'a list \<Rightarrow> 'a list \<Rightarrow> bool" (infix "[\<sim>]\<index>" 44) where
  1053   list_assoc :: "('a,_) monoid_scheme \<Rightarrow> 'a list \<Rightarrow> 'a list \<Rightarrow> bool" (infix "[\<sim>]\<index>" 44)
  1053   "list_assoc G == list_all2 (op \<sim>\<^bsub>G\<^esub>)"
  1054   where "list_assoc G == list_all2 (op \<sim>\<^bsub>G\<^esub>)"
  1054 
  1055 
  1055 constdefs (structure G)
  1056 definition
  1056   essentially_equal :: "[_, 'a list, 'a list] \<Rightarrow> bool"
  1057   essentially_equal :: "[_, 'a list, 'a list] \<Rightarrow> bool"
  1057   "essentially_equal G fs1 fs2 == (\<exists>fs1'. fs1 <~~> fs1' \<and> fs1' [\<sim>] fs2)"
  1058   where "essentially_equal G fs1 fs2 == (\<exists>fs1'. fs1 <~~> fs1' \<and> fs1' [\<sim>]\<^bsub>G\<^esub> fs2)"
  1058 
  1059 
  1059 
  1060 
  1060 locale factorial_monoid = comm_monoid_cancel +
  1061 locale factorial_monoid = comm_monoid_cancel +
  1061   assumes factors_exist: 
  1062   assumes factors_exist: 
  1062           "\<lbrakk>a \<in> carrier G; a \<notin> Units G\<rbrakk> \<Longrightarrow> \<exists>fs. set fs \<subseteq> carrier G \<and> factors G fs a"
  1063           "\<lbrakk>a \<in> carrier G; a \<notin> Units G\<rbrakk> \<Longrightarrow> \<exists>fs. set fs \<subseteq> carrier G \<and> factors G fs a"
  1899 (* FIXME: use class_of x instead of closure_of {x} *)
  1900 (* FIXME: use class_of x instead of closure_of {x} *)
  1900 
  1901 
  1901 abbreviation
  1902 abbreviation
  1902   "assocs G x == eq_closure_of (division_rel G) {x}"
  1903   "assocs G x == eq_closure_of (division_rel G) {x}"
  1903 
  1904 
  1904 constdefs (structure G)
  1905 definition
  1905   "fmset G as \<equiv> multiset_of (map (\<lambda>a. assocs G a) as)"
  1906   "fmset G as \<equiv> multiset_of (map (\<lambda>a. assocs G a) as)"
  1906 
  1907 
  1907 
  1908 
  1908 text {* Helper lemmas *}
  1909 text {* Helper lemmas *}
  1909 
  1910 
  2613 
  2614 
  2614 subsection {* Greatest Common Divisors and Lowest Common Multiples *}
  2615 subsection {* Greatest Common Divisors and Lowest Common Multiples *}
  2615 
  2616 
  2616 subsubsection {* Definitions *}
  2617 subsubsection {* Definitions *}
  2617 
  2618 
  2618 constdefs (structure G)
  2619 definition
  2619   isgcd :: "[('a,_) monoid_scheme, 'a, 'a, 'a] \<Rightarrow> bool"  ("(_ gcdof\<index> _ _)" [81,81,81] 80)
  2620   isgcd :: "[('a,_) monoid_scheme, 'a, 'a, 'a] \<Rightarrow> bool"  ("(_ gcdof\<index> _ _)" [81,81,81] 80)
  2620   "x gcdof a b \<equiv> x divides a \<and> x divides b \<and> 
  2621   where "x gcdof\<^bsub>G\<^esub> a b \<equiv> x divides\<^bsub>G\<^esub> a \<and> x divides\<^bsub>G\<^esub> b \<and> 
  2621                  (\<forall>y\<in>carrier G. (y divides a \<and> y divides b \<longrightarrow> y divides x))"
  2622     (\<forall>y\<in>carrier G. (y divides\<^bsub>G\<^esub> a \<and> y divides\<^bsub>G\<^esub> b \<longrightarrow> y divides\<^bsub>G\<^esub> x))"
  2622 
  2623 
       
  2624 definition
  2623   islcm :: "[_, 'a, 'a, 'a] \<Rightarrow> bool"  ("(_ lcmof\<index> _ _)" [81,81,81] 80)
  2625   islcm :: "[_, 'a, 'a, 'a] \<Rightarrow> bool"  ("(_ lcmof\<index> _ _)" [81,81,81] 80)
  2624   "x lcmof a b \<equiv> a divides x \<and> b divides x \<and> 
  2626   where "x lcmof\<^bsub>G\<^esub> a b \<equiv> a divides\<^bsub>G\<^esub> x \<and> b divides\<^bsub>G\<^esub> x \<and> 
  2625                  (\<forall>y\<in>carrier G. (a divides y \<and> b divides y \<longrightarrow> x divides y))"
  2627     (\<forall>y\<in>carrier G. (a divides\<^bsub>G\<^esub> y \<and> b divides\<^bsub>G\<^esub> y \<longrightarrow> x divides\<^bsub>G\<^esub> y))"
  2626 
  2628 
  2627 constdefs (structure G)
  2629 definition
  2628   somegcd :: "('a,_) monoid_scheme \<Rightarrow> 'a \<Rightarrow> 'a \<Rightarrow> 'a"
  2630   somegcd :: "('a,_) monoid_scheme \<Rightarrow> 'a \<Rightarrow> 'a \<Rightarrow> 'a"
  2629   "somegcd G a b == SOME x. x \<in> carrier G \<and> x gcdof a b"
  2631   where "somegcd G a b == SOME x. x \<in> carrier G \<and> x gcdof\<^bsub>G\<^esub> a b"
  2630 
  2632 
       
  2633 definition
  2631   somelcm :: "('a,_) monoid_scheme \<Rightarrow> 'a \<Rightarrow> 'a \<Rightarrow> 'a"
  2634   somelcm :: "('a,_) monoid_scheme \<Rightarrow> 'a \<Rightarrow> 'a \<Rightarrow> 'a"
  2632   "somelcm G a b == SOME x. x \<in> carrier G \<and> x lcmof a b"
  2635   where "somelcm G a b == SOME x. x \<in> carrier G \<and> x lcmof\<^bsub>G\<^esub> a b"
  2633 
  2636 
  2634 constdefs (structure G)
  2637 definition
  2635   "SomeGcd G A == inf (division_rel G) A"
  2638   "SomeGcd G A == inf (division_rel G) A"
  2636 
  2639 
  2637 
  2640 
  2638 locale gcd_condition_monoid = comm_monoid_cancel +
  2641 locale gcd_condition_monoid = comm_monoid_cancel +
  2639   assumes gcdof_exists:
  2642   assumes gcdof_exists: