src/HOL/Algebra/Multiplicative_Group.thy
changeset 67051 e7e54a0b9197
parent 66500 ba94aeb02fbc
child 67226 ec32cdaab97b
equal deleted inserted replaced
67050:1e29e2666a15 67051:e7e54a0b9197
   137  shows "n > 0 \<and> n \<le> p"
   137  shows "n > 0 \<and> n \<le> p"
   138  using assms by (simp add: dvd_pos_nat dvd_imp_le)
   138  using assms by (simp add: dvd_pos_nat dvd_imp_le)
   139 
   139 
   140 (* Deviates from the definition given in the library in number theory *)
   140 (* Deviates from the definition given in the library in number theory *)
   141 definition phi' :: "nat => nat"
   141 definition phi' :: "nat => nat"
   142   where "phi' m = card {x. 1 \<le> x \<and> x \<le> m \<and> gcd x m = 1}"
   142   where "phi' m = card {x. 1 \<le> x \<and> x \<le> m \<and> coprime x m}"
   143 
   143 
   144 notation (latex output)
   144 notation (latex output)
   145   phi' ("\<phi> _")
   145   phi' ("\<phi> _")
   146 
   146 
   147 lemma phi'_nonzero :
   147 lemma phi'_nonzero :
   148   assumes "m > 0"
   148   assumes "m > 0"
   149   shows "phi' m > 0"
   149   shows "phi' m > 0"
   150 proof -
   150 proof -
   151   have "1 \<in> {x. 1 \<le> x \<and> x \<le> m \<and> gcd x m = 1}" using assms by simp
   151   have "1 \<in> {x. 1 \<le> x \<and> x \<le> m \<and> coprime x m}" using assms by simp
   152   hence "card {x. 1 \<le> x \<and> x \<le> m \<and> gcd x m = 1} > 0" by (auto simp: card_gt_0_iff)
   152   hence "card {x. 1 \<le> x \<and> x \<le> m \<and> coprime x m} > 0" by (auto simp: card_gt_0_iff)
   153   thus ?thesis unfolding phi'_def by simp
   153   thus ?thesis unfolding phi'_def by simp
   154 qed
   154 qed
   155 
   155 
   156 lemma dvd_div_eq_1:
   156 lemma dvd_div_eq_1:
   157   fixes a b c :: nat
   157   fixes a b c :: nat
   230         have le_n:"a * n div d \<le> n" using div_mult_mono a by simp
   230         have le_n:"a * n div d \<le> n" using div_mult_mono a by simp
   231         have "gcd (a * n div d) n = n div d * gcd a d"
   231         have "gcd (a * n div d) n = n div d * gcd a d"
   232           by (simp add: gcd_mult_distrib_nat q ac_simps)
   232           by (simp add: gcd_mult_distrib_nat q ac_simps)
   233         hence "n div gcd (a * n div d) n = d*n div (d*(n div d))" using a by simp
   233         hence "n div gcd (a * n div d) n = d*n div (d*(n div d))" using a by simp
   234         hence "a * n div d \<in> ?F"
   234         hence "a * n div d \<in> ?F"
   235           using ge_1 le_n by (fastforce simp add: `d dvd n` dvd_mult_div_cancel)
   235           using ge_1 le_n by (fastforce simp add: `d dvd n`)
   236       } thus "(\<lambda>a. a*n div d) ` ?RF \<subseteq> ?F" by blast
   236       } thus "(\<lambda>a. a*n div d) ` ?RF \<subseteq> ?F" by blast
   237       { fix m l assume A: "m \<in> ?F" "l \<in> ?F" "m div gcd m n = l div gcd l n"
   237       { fix m l assume A: "m \<in> ?F" "l \<in> ?F" "m div gcd m n = l div gcd l n"
   238         hence "gcd m n = gcd l n" using dvd_div_eq_2[OF assms] by fastforce
   238         hence "gcd m n = gcd l n" using dvd_div_eq_2[OF assms] by fastforce
   239         hence "m = l" using dvd_div_eq_1[of "gcd m n" m l] A(3) by fastforce
   239         hence "m = l" using dvd_div_eq_1[of "gcd m n" m l] A(3) by fastforce
   240       } thus "inj_on (\<lambda>a. a div gcd a n) ?F" unfolding inj_on_def by blast
   240       } thus "inj_on (\<lambda>a. a div gcd a n) ?F" unfolding inj_on_def by blast
   254   proof
   254   proof
   255     show "?L \<supseteq> ?R"
   255     show "?L \<supseteq> ?R"
   256     proof
   256     proof
   257       fix m assume m: "m \<in> ?R"
   257       fix m assume m: "m \<in> ?R"
   258       thus "m \<in> ?L" using dvd_triv_right[of "n div gcd m n" "gcd m n"]
   258       thus "m \<in> ?L" using dvd_triv_right[of "n div gcd m n" "gcd m n"]
   259         by (simp add: dvd_mult_div_cancel)
   259         by simp
   260     qed
   260     qed
   261   qed fastforce
   261   qed fastforce
   262   finally show ?thesis by force
   262   finally show ?thesis by force
   263 qed
   263 qed
   264 
   264 
   327   using assms ord_ge_1 pow_ord_eq_1 by auto
   327   using assms ord_ge_1 pow_ord_eq_1 by auto
   328 
   328 
   329 lemma ord_min:
   329 lemma ord_min:
   330   assumes  "finite (carrier G)" "1 \<le> d" "a \<in> carrier G" "a (^) d = \<one>" shows "ord a \<le> d"
   330   assumes  "finite (carrier G)" "1 \<le> d" "a \<in> carrier G" "a (^) d = \<one>" shows "ord a \<le> d"
   331 proof -
   331 proof -
   332   def Ord \<equiv> "{d \<in> {1..order G}. a (^) d = \<one>}"
   332   define Ord where "Ord = {d \<in> {1..order G}. a (^) d = \<one>}"
   333   have fin: "finite Ord" by (auto simp: Ord_def)
   333   have fin: "finite Ord" by (auto simp: Ord_def)
   334   have in_ord: "ord a \<in> Ord"
   334   have in_ord: "ord a \<in> Ord"
   335     using assms pow_ord_eq_1 ord_ge_1 ord_le_group_order by (auto simp: Ord_def)
   335     using assms pow_ord_eq_1 ord_ge_1 ord_le_group_order by (auto simp: Ord_def)
   336   then have "Ord \<noteq> {}" by auto
   336   then have "Ord \<noteq> {}" by auto
   337 
   337 
   409   shows "{a(^)x | x. x \<in> (UNIV :: nat set)} = {a(^)x | x. x \<in> {0 .. ord a - 1}}" (is "?L = ?R")
   409   shows "{a(^)x | x. x \<in> (UNIV :: nat set)} = {a(^)x | x. x \<in> {0 .. ord a - 1}}" (is "?L = ?R")
   410 proof
   410 proof
   411   show "?R \<subseteq> ?L" by blast
   411   show "?R \<subseteq> ?L" by blast
   412   { fix y assume "y \<in> ?L"
   412   { fix y assume "y \<in> ?L"
   413     then obtain x::nat where x:"y = a(^)x" by auto
   413     then obtain x::nat where x:"y = a(^)x" by auto
   414     def r \<equiv> "x mod ord a"
   414     define r where "r = x mod ord a"
   415     then obtain q where q:"x = q * ord a + r" using mod_eqD by atomize_elim presburger
   415     then obtain q where q:"x = q * ord a + r" using mod_eqD by atomize_elim presburger
   416     hence "y = (a(^)ord a)(^)q \<otimes> a(^)r"
   416     hence "y = (a(^)ord a)(^)q \<otimes> a(^)r"
   417       using x assms by (simp add: mult.commute nat_pow_mult nat_pow_pow)
   417       using x assms by (simp add: mult.commute nat_pow_mult nat_pow_pow)
   418     hence "y = a(^)r" using assms by (simp add: pow_ord_eq_1)
   418     hence "y = a(^)r" using assms by (simp add: pow_ord_eq_1)
   419     have "r < ord a" using ord_ge_1[OF assms] by (simp add: r_def)
   419     have "r < ord a" using ord_ge_1[OF assms] by (simp add: r_def)
   425 
   425 
   426 lemma ord_dvd_pow_eq_1 :
   426 lemma ord_dvd_pow_eq_1 :
   427   assumes "finite (carrier G)" "a \<in> carrier G" "a (^) k = \<one>"
   427   assumes "finite (carrier G)" "a \<in> carrier G" "a (^) k = \<one>"
   428   shows "ord a dvd k"
   428   shows "ord a dvd k"
   429 proof -
   429 proof -
   430   def r \<equiv> "k mod ord a"
   430   define r where "r = k mod ord a"
   431   then obtain q where q:"k = q*ord a + r" using mod_eqD by atomize_elim presburger
   431   then obtain q where q:"k = q*ord a + r" using mod_eqD by atomize_elim presburger
   432   hence "a(^)k = (a(^)ord a)(^)q \<otimes> a(^)r"
   432   hence "a(^)k = (a(^)ord a)(^)q \<otimes> a(^)r"
   433       using assms by (simp add: mult.commute nat_pow_mult nat_pow_pow)
   433       using assms by (simp add: mult.commute nat_pow_mult nat_pow_pow)
   434   hence "a(^)k = a(^)r" using assms by (simp add: pow_ord_eq_1)
   434   hence "a(^)k = a(^)r" using assms by (simp add: pow_ord_eq_1)
   435   hence "a(^)r = \<one>" using assms(3) by simp
   435   hence "a(^)r = \<one>" using assms(3) by simp
   484       by (simp add: dvd_div_mult)
   484       by (simp add: dvd_div_mult)
   485     have cp:"coprime (ord a div gcd n (ord a)) (n div gcd n (ord a))"
   485     have cp:"coprime (ord a div gcd n (ord a)) (n div gcd n (ord a))"
   486     proof -
   486     proof -
   487       have "coprime (n div gcd n (ord a)) (ord a div gcd n (ord a))"
   487       have "coprime (n div gcd n (ord a)) (ord a div gcd n (ord a))"
   488         using div_gcd_coprime[of n "ord a"] ge_1 by fastforce
   488         using div_gcd_coprime[of n "ord a"] ge_1 by fastforce
   489       thus ?thesis by (simp add: gcd.commute)
   489       thus ?thesis by (simp add: ac_simps)
   490     qed
   490     qed
   491     have dvd_d:"(ord a div gcd n (ord a)) dvd d"
   491     have dvd_d:"(ord a div gcd n (ord a)) dvd d"
   492     proof -
   492     proof -
   493       have "ord a div gcd n (ord a) dvd (n div gcd n (ord a)) * d" using prod_eq
   493       have "ord a div gcd n (ord a) dvd (n div gcd n (ord a)) * d" using prod_eq
   494         by (metis dvd_triv_right mult.commute)
   494         by (metis dvd_triv_right mult.commute)
   495       hence "ord a div gcd n (ord a) dvd d * (n div gcd n (ord a))"
   495       hence "ord a div gcd n (ord a) dvd d * (n div gcd n (ord a))"
   496         by (simp add:  mult.commute)
   496         by (simp add: mult.commute)
   497       thus ?thesis using coprime_dvd_mult[OF cp, of d] by fastforce
   497       then show ?thesis
       
   498         using cp by (simp add: coprime_dvd_mult_left_iff)
   498     qed
   499     qed
   499     have "d > 0" using d_elem by simp
   500     have "d > 0" using d_elem by simp
   500     hence "ord a div gcd n (ord a) \<le> d" using dvd_d by (simp add : Nat.dvd_imp_le)
   501     hence "ord a div gcd n (ord a) \<le> d" using dvd_d by (simp add : Nat.dvd_imp_le)
   501     hence False using d_lt by simp
   502     hence False using d_lt by simp
   502   } hence ord_gcd_min: "\<And> d . d \<in> {d \<in> {1..order G}. (a(^)n) (^) d = \<one>}
   503   } hence ord_gcd_min: "\<And> d . d \<in> {d \<in> {1..order G}. (a(^)n) (^) d = \<one>}
   742   assumes finite': "finite (carrier G)"
   743   assumes finite': "finite (carrier G)"
   743   assumes "a \<in> carrier G"
   744   assumes "a \<in> carrier G"
   744   shows pow_ord_eq_ord_iff: "group.ord G (a (^) k) = ord a \<longleftrightarrow> coprime k (ord a)" (is "?L \<longleftrightarrow> ?R")
   745   shows pow_ord_eq_ord_iff: "group.ord G (a (^) k) = ord a \<longleftrightarrow> coprime k (ord a)" (is "?L \<longleftrightarrow> ?R")
   745 proof
   746 proof
   746   assume A: ?L then show ?R
   747   assume A: ?L then show ?R
   747     using assms ord_ge_1[OF assms] by (auto simp: nat_div_eq ord_pow_dvd_ord_elem)
   748     using assms ord_ge_1 [OF assms]
       
   749     by (auto simp: nat_div_eq ord_pow_dvd_ord_elem coprime_iff_gcd_eq_1)
   748 next
   750 next
   749   assume ?R then show ?L
   751   assume ?R then show ?L
   750     using ord_pow_dvd_ord_elem[OF assms, of k] by auto
   752     using ord_pow_dvd_ord_elem[OF assms, of k] by auto
   751 qed
   753 qed
   752 
   754