src/HOL/Library/Pocklington.thy
changeset 30264 2e8a7d86321e
parent 30242 aea5d7fa7ef5
child 30488 5c4c3a9e9102
equal deleted inserted replaced
30263:c88af4619a73 30264:2e8a7d86321e
   552   ultimately show ?thesis by auto
   552   ultimately show ?thesis by auto
   553 qed
   553 qed
   554 
   554 
   555 (* Fermat's Little theorem / Fermat-Euler theorem.                           *)
   555 (* Fermat's Little theorem / Fermat-Euler theorem.                           *)
   556 
   556 
   557 lemma (in comm_monoid_mult) fold_image_related: 
       
   558   assumes Re: "R e e" 
       
   559   and Rop: "\<forall>x1 y1 x2 y2. R x1 x2 \<and> R y1 y2 \<longrightarrow> R (x1 * y1) (x2 * y2)" 
       
   560   and fS: "finite S" and Rfg: "\<forall>x\<in>S. R (h x) (g x)"
       
   561   shows "R (fold_image (op *) h e S) (fold_image (op *) g e S)"
       
   562   using fS by (rule finite_subset_induct) (insert assms, auto)
       
   563 
   557 
   564 lemma nproduct_mod:
   558 lemma nproduct_mod:
   565   assumes fS: "finite S" and n0: "n \<noteq> 0"
   559   assumes fS: "finite S" and n0: "n \<noteq> 0"
   566   shows "[setprod (\<lambda>m. a(m) mod n) S = setprod a S] (mod n)"
   560   shows "[setprod (\<lambda>m. a(m) mod n) S = setprod a S] (mod n)"
   567 proof-
   561 proof-
   582 lemma coprime_nproduct:
   576 lemma coprime_nproduct:
   583   assumes fS: "finite S" and Sn: "\<forall>x\<in>S. coprime n (a x)"
   577   assumes fS: "finite S" and Sn: "\<forall>x\<in>S. coprime n (a x)"
   584   shows "coprime n (setprod a S)"
   578   shows "coprime n (setprod a S)"
   585   using fS unfolding setprod_def by (rule finite_subset_induct)
   579   using fS unfolding setprod_def by (rule finite_subset_induct)
   586     (insert Sn, auto simp add: coprime_mul)
   580     (insert Sn, auto simp add: coprime_mul)
   587 
       
   588 lemma (in comm_monoid_mult) 
       
   589   fold_image_eq_general:
       
   590   assumes fS: "finite S"
       
   591   and h: "\<forall>y\<in>S'. \<exists>!x. x\<in> S \<and> h(x) = y" 
       
   592   and f12:  "\<forall>x\<in>S. h x \<in> S' \<and> f2(h x) = f1 x"
       
   593   shows "fold_image (op *) f1 e S = fold_image (op *) f2 e S'"
       
   594 proof-
       
   595   from h f12 have hS: "h ` S = S'" by auto
       
   596   {fix x y assume H: "x \<in> S" "y \<in> S" "h x = h y"
       
   597     from f12 h H  have "x = y" by auto }
       
   598   hence hinj: "inj_on h S" unfolding inj_on_def Ex1_def by blast
       
   599   from f12 have th: "\<And>x. x \<in> S \<Longrightarrow> (f2 \<circ> h) x = f1 x" by auto 
       
   600   from hS have "fold_image (op *) f2 e S' = fold_image (op *) f2 e (h ` S)" by simp
       
   601   also have "\<dots> = fold_image (op *) (f2 o h) e S" 
       
   602     using fold_image_reindex[OF fS hinj, of f2 e] .
       
   603   also have "\<dots> = fold_image (op *) f1 e S " using th fold_image_cong[OF fS, of "f2 o h" f1 e]
       
   604     by blast
       
   605   finally show ?thesis ..
       
   606 qed
       
   607 
   581 
   608 lemma fermat_little: assumes an: "coprime a n"
   582 lemma fermat_little: assumes an: "coprime a n"
   609   shows "[a ^ (\<phi> n) = 1] (mod n)"
   583   shows "[a ^ (\<phi> n) = 1] (mod n)"
   610 proof-
   584 proof-
   611   {assume "n=0" hence ?thesis by simp}
   585   {assume "n=0" hence ?thesis by simp}
  1285     have "coprime (a ^ ((n - 1) div p) - 1) n" by (simp add: coprime_commute) }
  1259     have "coprime (a ^ ((n - 1) div p) - 1) n" by (simp add: coprime_commute) }
  1286   with pocklington[OF n qrn[symmetric] nq2 an1]
  1260   with pocklington[OF n qrn[symmetric] nq2 an1]
  1287   show ?thesis by blast    
  1261   show ?thesis by blast    
  1288 qed
  1262 qed
  1289 
  1263 
  1290 
       
  1291 end
  1264 end