src/HOL/Algebra/Divisibility.thy
changeset 35848 5443079512ea
parent 35847 19f1f7066917
child 35849 b5522b51cb1e
equal deleted inserted replaced
35847:19f1f7066917 35848:5443079512ea
   160 
   160 
   161 subsubsection {* Function definitions *}
   161 subsubsection {* Function definitions *}
   162 
   162 
   163 definition
   163 definition
   164   factor :: "[_, 'a, 'a] \<Rightarrow> bool" (infix "divides\<index>" 65)
   164   factor :: "[_, 'a, 'a] \<Rightarrow> bool" (infix "divides\<index>" 65)
   165   where "a divides\<^bsub>G\<^esub> b == \<exists>c\<in>carrier G. b = a \<otimes>\<^bsub>G\<^esub> c"
   165   where "a divides\<^bsub>G\<^esub> b \<longleftrightarrow> (\<exists>c\<in>carrier G. b = a \<otimes>\<^bsub>G\<^esub> c)"
   166 
   166 
   167 definition
   167 definition
   168   associated :: "[_, 'a, 'a] => bool" (infix "\<sim>\<index>" 55)
   168   associated :: "[_, 'a, 'a] => bool" (infix "\<sim>\<index>" 55)
   169   where "a \<sim>\<^bsub>G\<^esub> b == a divides\<^bsub>G\<^esub> b \<and> b divides\<^bsub>G\<^esub> a"
   169   where "a \<sim>\<^bsub>G\<^esub> b \<longleftrightarrow> 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 definition
   174 definition
   175   properfactor :: "[_, 'a, 'a] \<Rightarrow> bool"
   175   properfactor :: "[_, 'a, 'a] \<Rightarrow> bool"
   176   where "properfactor G a b == a divides\<^bsub>G\<^esub> b \<and> \<not>(b divides\<^bsub>G\<^esub> a)"
   176   where "properfactor G a b \<longleftrightarrow> a divides\<^bsub>G\<^esub> b \<and> \<not>(b divides\<^bsub>G\<^esub> a)"
   177 
   177 
   178 definition
   178 definition
   179   irreducible :: "[_, 'a] \<Rightarrow> bool"
   179   irreducible :: "[_, 'a] \<Rightarrow> bool"
   180   where "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 \<longleftrightarrow> a \<notin> Units G \<and> (\<forall>b\<in>carrier G. properfactor G b a \<longrightarrow> b \<in> Units G)"
   181 
   181 
   182 definition
   182 definition
   183   prime :: "[_, 'a] \<Rightarrow> bool" where
   183   prime :: "[_, 'a] \<Rightarrow> bool" where
   184   "prime G p ==
   184   "prime G p \<longleftrightarrow>
   185     p \<notin> Units G \<and> 
   185     p \<notin> Units G \<and> 
   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)"
   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 *}
  1041 
  1041 
  1042 subsubsection {* Function definitions *}
  1042 subsubsection {* Function definitions *}
  1043 
  1043 
  1044 definition
  1044 definition
  1045   factors :: "[_, 'a list, 'a] \<Rightarrow> bool"
  1045   factors :: "[_, 'a list, 'a] \<Rightarrow> bool"
  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"
  1046   where "factors G fs a \<longleftrightarrow> (\<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 definition
  1049   wfactors ::"[_, 'a list, 'a] \<Rightarrow> bool"
  1049   wfactors ::"[_, 'a list, 'a] \<Rightarrow> bool"
  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   where "wfactors G fs a \<longleftrightarrow> (\<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"
  1051 
  1051 
  1052 abbreviation
  1052 abbreviation
  1053   list_assoc :: "('a,_) monoid_scheme \<Rightarrow> 'a list \<Rightarrow> 'a list \<Rightarrow> bool" (infix "[\<sim>]\<index>" 44)
  1053   list_assoc :: "('a,_) monoid_scheme \<Rightarrow> 'a list \<Rightarrow> 'a list \<Rightarrow> bool" (infix "[\<sim>]\<index>" 44)
  1054   where "list_assoc G == list_all2 (op \<sim>\<^bsub>G\<^esub>)"
  1054   where "list_assoc G == list_all2 (op \<sim>\<^bsub>G\<^esub>)"
  1055 
  1055 
  1056 definition
  1056 definition
  1057   essentially_equal :: "[_, 'a list, 'a list] \<Rightarrow> bool"
  1057   essentially_equal :: "[_, 'a list, 'a list] \<Rightarrow> bool"
  1058   where "essentially_equal G fs1 fs2 == (\<exists>fs1'. fs1 <~~> fs1' \<and> fs1' [\<sim>]\<^bsub>G\<^esub> fs2)"
  1058   where "essentially_equal G fs1 fs2 \<longleftrightarrow> (\<exists>fs1'. fs1 <~~> fs1' \<and> fs1' [\<sim>]\<^bsub>G\<^esub> fs2)"
  1059 
  1059 
  1060 
  1060 
  1061 locale factorial_monoid = comm_monoid_cancel +
  1061 locale factorial_monoid = comm_monoid_cancel +
  1062   assumes factors_exist: 
  1062   assumes factors_exist: 
  1063           "\<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"
  1901 
  1901 
  1902 abbreviation
  1902 abbreviation
  1903   "assocs G x == eq_closure_of (division_rel G) {x}"
  1903   "assocs G x == eq_closure_of (division_rel G) {x}"
  1904 
  1904 
  1905 definition
  1905 definition
  1906   "fmset G as \<equiv> multiset_of (map (\<lambda>a. assocs G a) as)"
  1906   "fmset G as = multiset_of (map (\<lambda>a. assocs G a) as)"
  1907 
  1907 
  1908 
  1908 
  1909 text {* Helper lemmas *}
  1909 text {* Helper lemmas *}
  1910 
  1910 
  1911 lemma (in monoid) assocs_repr_independence:
  1911 lemma (in monoid) assocs_repr_independence:
  2616 
  2616 
  2617 subsubsection {* Definitions *}
  2617 subsubsection {* Definitions *}
  2618 
  2618 
  2619 definition
  2619 definition
  2620   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)
  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   where "x gcdof\<^bsub>G\<^esub> a b \<longleftrightarrow> x divides\<^bsub>G\<^esub> a \<and> x divides\<^bsub>G\<^esub> b \<and>
  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     (\<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))"
  2623 
  2623 
  2624 definition
  2624 definition
  2625   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)
  2626   where "x lcmof\<^bsub>G\<^esub> a b \<equiv> a divides\<^bsub>G\<^esub> x \<and> b divides\<^bsub>G\<^esub> x \<and> 
  2626   where "x lcmof\<^bsub>G\<^esub> a b \<longleftrightarrow> a divides\<^bsub>G\<^esub> x \<and> b divides\<^bsub>G\<^esub> x \<and>
  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))"
  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))"
  2628 
  2628 
  2629 definition
  2629 definition
  2630   somegcd :: "('a,_) monoid_scheme \<Rightarrow> 'a \<Rightarrow> 'a \<Rightarrow> 'a"
  2630   somegcd :: "('a,_) monoid_scheme \<Rightarrow> 'a \<Rightarrow> 'a \<Rightarrow> 'a"
  2631   where "somegcd G a b == SOME x. x \<in> carrier G \<and> x gcdof\<^bsub>G\<^esub> a b"
  2631   where "somegcd G a b = (SOME x. x \<in> carrier G \<and> x gcdof\<^bsub>G\<^esub> a b)"
  2632 
  2632 
  2633 definition
  2633 definition
  2634   somelcm :: "('a,_) monoid_scheme \<Rightarrow> 'a \<Rightarrow> 'a \<Rightarrow> 'a"
  2634   somelcm :: "('a,_) monoid_scheme \<Rightarrow> 'a \<Rightarrow> 'a \<Rightarrow> 'a"
  2635   where "somelcm G a b == SOME x. x \<in> carrier G \<and> x lcmof\<^bsub>G\<^esub> a b"
  2635   where "somelcm G a b = (SOME x. x \<in> carrier G \<and> x lcmof\<^bsub>G\<^esub> a b)"
  2636 
  2636 
  2637 definition
  2637 definition
  2638   "SomeGcd G A == inf (division_rel G) A"
  2638   "SomeGcd G A = inf (division_rel G) A"
  2639 
  2639 
  2640 
  2640 
  2641 locale gcd_condition_monoid = comm_monoid_cancel +
  2641 locale gcd_condition_monoid = comm_monoid_cancel +
  2642   assumes gcdof_exists:
  2642   assumes gcdof_exists:
  2643           "\<lbrakk>a \<in> carrier G; b \<in> carrier G\<rbrakk> \<Longrightarrow> \<exists>c. c \<in> carrier G \<and> c gcdof a b"
  2643           "\<lbrakk>a \<in> carrier G; b \<in> carrier G\<rbrakk> \<Longrightarrow> \<exists>c. c \<in> carrier G \<and> c gcdof a b"
  3631 
  3631 
  3632 subsubsection {* Application to factorial monoids *}
  3632 subsubsection {* Application to factorial monoids *}
  3633 
  3633 
  3634 text {* Number of factors for wellfoundedness *}
  3634 text {* Number of factors for wellfoundedness *}
  3635 
  3635 
  3636 definition factorcount :: "_ \<Rightarrow> 'a \<Rightarrow> nat" where
  3636 definition
  3637   "factorcount G a == THE c. (ALL as. set as \<subseteq> carrier G \<and> 
  3637   factorcount :: "_ \<Rightarrow> 'a \<Rightarrow> nat" where
  3638                                       wfactors G as a \<longrightarrow> c = length as)"
  3638   "factorcount G a =
       
  3639     (THE c. (ALL as. set as \<subseteq> carrier G \<and> wfactors G as a \<longrightarrow> c = length as))"
  3639 
  3640 
  3640 lemma (in monoid) ee_length:
  3641 lemma (in monoid) ee_length:
  3641   assumes ee: "essentially_equal G as bs"
  3642   assumes ee: "essentially_equal G as bs"
  3642   shows "length as = length bs"
  3643   shows "length as = length bs"
  3643 apply (rule essentially_equalE[OF ee])
  3644 apply (rule essentially_equalE[OF ee])