src/HOL/Library/Pocklington.thy
changeset 29667 53103fc8ffa3
parent 28854 c2b8be5ddc4a
child 30042 31039ee583fa
child 30240 5b25fee0362c
equal deleted inserted replaced
29549:7187373c6cb1 29667:53103fc8ffa3
   252   using nat_mod_lemma[of x y n]
   252   using nat_mod_lemma[of x y n]
   253   apply auto
   253   apply auto
   254   apply (simp add: nat_mod)
   254   apply (simp add: nat_mod)
   255   apply (rule_tac x="q" in exI)
   255   apply (rule_tac x="q" in exI)
   256   apply (rule_tac x="q + q" in exI)
   256   apply (rule_tac x="q + q" in exI)
   257   by (auto simp: ring_simps)
   257   by (auto simp: algebra_simps)
   258 
   258 
   259 lemma cong_to_1: "[a = 1] (mod n) \<longleftrightarrow> a = 0 \<and> n = 1 \<or> (\<exists>m. a = 1 + m * n)"
   259 lemma cong_to_1: "[a = 1] (mod n) \<longleftrightarrow> a = 0 \<and> n = 1 \<or> (\<exists>m. a = 1 + m * n)"
   260 proof-
   260 proof-
   261   {assume "n = 0 \<or> n = 1\<or> a = 0 \<or> a = 1" hence ?thesis 
   261   {assume "n = 0 \<or> n = 1\<or> a = 0 \<or> a = 1" hence ?thesis 
   262       apply (cases "n=0", simp_all add: cong_commute)
   262       apply (cases "n=0", simp_all add: cong_commute)
   778       note mdeq = mod_div_equality[of "(n - 1)" m]
   778       note mdeq = mod_div_equality[of "(n - 1)" m]
   779       from coprime_exp[OF an(1)[unfolded coprime_commute[of a n]], 
   779       from coprime_exp[OF an(1)[unfolded coprime_commute[of a n]], 
   780 	of "(n - 1) div m * m"]
   780 	of "(n - 1) div m * m"]
   781       have yn: "coprime ?y n" by (simp add: coprime_commute) 
   781       have yn: "coprime ?y n" by (simp add: coprime_commute) 
   782       have "?y mod n = (a^m)^((n - 1) div m) mod n" 
   782       have "?y mod n = (a^m)^((n - 1) div m) mod n" 
   783 	by (simp add: ring_simps power_mult)
   783 	by (simp add: algebra_simps power_mult)
   784       also have "\<dots> = (a^m mod n)^((n - 1) div m) mod n" 
   784       also have "\<dots> = (a^m mod n)^((n - 1) div m) mod n" 
   785 	using power_mod[of "a^m" n "(n - 1) div m"] by simp
   785 	using power_mod[of "a^m" n "(n - 1) div m"] by simp
   786       also have "\<dots> = 1" using m(3)[unfolded modeq_def onen] onen 
   786       also have "\<dots> = 1" using m(3)[unfolded modeq_def onen] onen 
   787 	by (simp add: power_Suc0)
   787 	by (simp add: power_Suc0)
   788       finally have th3: "?y mod n = 1"  . 
   788       finally have th3: "?y mod n = 1"  . 
  1237   shows "prime n"
  1237   shows "prime n"
  1238 proof-
  1238 proof-
  1239   from bqn psp qrn
  1239   from bqn psp qrn
  1240   have bqn: "a ^ (n - 1) mod n = 1"
  1240   have bqn: "a ^ (n - 1) mod n = 1"
  1241     and psp: "list_all (\<lambda>p. prime p \<and> coprime (a^(r *(q div p)) mod n - 1) n) ps"  unfolding arnb[symmetric] power_mod 
  1241     and psp: "list_all (\<lambda>p. prime p \<and> coprime (a^(r *(q div p)) mod n - 1) n) ps"  unfolding arnb[symmetric] power_mod 
  1242     by (simp_all add: power_mult[symmetric] ring_simps)
  1242     by (simp_all add: power_mult[symmetric] algebra_simps)
  1243   from n  have n0: "n > 0" by arith
  1243   from n  have n0: "n > 0" by arith
  1244   from mod_div_equality[of "a^(n - 1)" n]
  1244   from mod_div_equality[of "a^(n - 1)" n]
  1245     mod_less_divisor[OF n0, of "a^(n - 1)"]
  1245     mod_less_divisor[OF n0, of "a^(n - 1)"]
  1246   have an1: "[a ^ (n - 1) = 1] (mod n)" 
  1246   have an1: "[a ^ (n - 1) = 1] (mod n)" 
  1247     unfolding nat_mod bqn
  1247     unfolding nat_mod bqn
  1248     apply -
  1248     apply -
  1249     apply (rule exI[where x="0"])
  1249     apply (rule exI[where x="0"])
  1250     apply (rule exI[where x="a^(n - 1) div n"])
  1250     apply (rule exI[where x="a^(n - 1) div n"])
  1251     by (simp add: ring_simps)
  1251     by (simp add: algebra_simps)
  1252   {fix p assume p: "prime p" "p dvd q"
  1252   {fix p assume p: "prime p" "p dvd q"
  1253     from psp psq have pfpsq: "primefact ps q"
  1253     from psp psq have pfpsq: "primefact ps q"
  1254       by (auto simp add: primefact_variant list_all_iff)
  1254       by (auto simp add: primefact_variant list_all_iff)
  1255     from psp primefact_contains[OF pfpsq p] 
  1255     from psp primefact_contains[OF pfpsq p] 
  1256     have p': "coprime (a ^ (r * (q div p)) mod n - 1) n"
  1256     have p': "coprime (a ^ (r * (q div p)) mod n - 1) n"