number_theory.wilson
⟷
Mathlib.NumberTheory.Wilson
The following section lists changes to this file in mathlib3 and mathlib4 that occured after the initial port. Most recent changes are shown first. Hovering over a commit will show all commits associated with the same mathlib3 commit.
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(last sync)
mathlib commit https://github.com/leanprover-community/mathlib/commit/65a1391a0106c9204fe45bc73a039f056558cb83
@@ -97,7 +97,7 @@ theorem prime_of_fac_equiv_neg_one (h : ((n - 1)! : ZMod n) = -1) (h1 : n ≠ 1)
obtain ⟨m, hm1, hm2 : 1 < m, hm3⟩ := exists_dvd_of_not_prime2 h1 h2
have hm : m ∣ (n - 1)! := Nat.dvd_factorial (pos_of_gt hm2) (le_pred_of_lt hm3)
refine' hm2.ne' (nat.dvd_one.mp ((Nat.dvd_add_right hm).mp (hm1.trans _)))
- rw [← ZMod.nat_cast_zmod_eq_zero_iff_dvd, cast_add, cast_one, h, add_left_neg]
+ rw [← ZMod.natCast_zmod_eq_zero_iff_dvd, cast_add, cast_one, h, add_left_neg]
#align nat.prime_of_fac_equiv_neg_one Nat.prime_of_fac_equiv_neg_one
-/
mathlib commit https://github.com/leanprover-community/mathlib/commit/65a1391a0106c9204fe45bc73a039f056558cb83
@@ -63,9 +63,9 @@ theorem wilsons_lemma : ((p - 1)! : ZMod p) = -1 :=
· intro a ha; simp only [cast_id, nat_cast_val]
· intro _ _ _ _ h; rw [Units.ext_iff]; exact val_injective p h
· intro b hb
- rw [mem_Ico, Nat.succ_le_iff, ← succ_sub hp, succ_sub_one, pos_iff_ne_zero] at hb
+ rw [mem_Ico, Nat.succ_le_iff, ← succ_sub hp, succ_sub_one, pos_iff_ne_zero] at hb
refine' ⟨Units.mk0 b _, Finset.mem_univ _, _⟩
- · intro h; apply hb.1; apply_fun val at h
+ · intro h; apply hb.1; apply_fun val at h
simpa only [val_cast_of_lt hb.right, val_zero] using h
· simp only [val_cast_of_lt hb.right, Units.val_mk0]
#align zmod.wilsons_lemma ZMod.wilsons_lemma
@@ -91,7 +91,7 @@ variable {n : ℕ}
theorem prime_of_fac_equiv_neg_one (h : ((n - 1)! : ZMod n) = -1) (h1 : n ≠ 1) : Prime n :=
by
rcases eq_or_ne n 0 with (rfl | h0)
- · norm_num at h
+ · norm_num at h
replace h1 : 1 < n := n.two_le_iff.mpr ⟨h0, h1⟩
by_contra h2
obtain ⟨m, hm1, hm2 : 1 < m, hm3⟩ := exists_dvd_of_not_prime2 h1 h2
mathlib commit https://github.com/leanprover-community/mathlib/commit/65a1391a0106c9204fe45bc73a039f056558cb83
@@ -55,7 +55,7 @@ theorem wilsons_lemma : ((p - 1)! : ZMod p) = -1 :=
symm
refine' prod_bij (fun a _ => (a : ZMod p).val) _ _ _ _
· intro a ha
- rw [mem_Ico, ← Nat.succ_sub hp, Nat.succ_sub_one]
+ rw [mem_Ico, ← Nat.succ_sub hp, Nat.add_one_sub_one]
constructor
· apply Nat.pos_of_ne_zero; rw [← @val_zero p]
intro h; apply Units.ne_zero a (val_injective p h)
mathlib commit https://github.com/leanprover-community/mathlib/commit/ce64cd319bb6b3e82f31c2d38e79080d377be451
@@ -3,7 +3,7 @@ Copyright (c) 2022 John Nicol. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: John Nicol
-/
-import Mathbin.FieldTheory.Finite.Basic
+import FieldTheory.Finite.Basic
#align_import number_theory.wilson from "leanprover-community/mathlib"@"087c325ae0ab42dbdd5dee55bc37d3d5a0bf2197"
mathlib commit https://github.com/leanprover-community/mathlib/commit/8ea5598db6caeddde6cb734aa179cc2408dbd345
@@ -2,14 +2,11 @@
Copyright (c) 2022 John Nicol. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: John Nicol
-
-! This file was ported from Lean 3 source module number_theory.wilson
-! leanprover-community/mathlib commit 087c325ae0ab42dbdd5dee55bc37d3d5a0bf2197
-! Please do not edit these lines, except to modify the commit id
-! if you have ported upstream changes.
-/
import Mathbin.FieldTheory.Finite.Basic
+#align_import number_theory.wilson from "leanprover-community/mathlib"@"087c325ae0ab42dbdd5dee55bc37d3d5a0bf2197"
+
/-!
# Wilson's theorem.
mathlib commit https://github.com/leanprover-community/mathlib/commit/fdc286cc6967a012f41b87f76dcd2797b53152af
@@ -116,5 +116,5 @@ theorem prime_iff_fac_equiv_neg_one (h : n ≠ 1) : Prime n ↔ ((n - 1)! : ZMod
end Nat
-assert_not_exists legendre_sym.quadratic_reciprocity
+assert_not_exists legendreSym.quadratic_reciprocity
mathlib commit https://github.com/leanprover-community/mathlib/commit/9fb8964792b4237dac6200193a0d533f1b3f7423
@@ -41,6 +41,7 @@ namespace ZMod
variable (p : ℕ) [Fact p.Prime]
+#print ZMod.wilsons_lemma /-
/-- **Wilson's Lemma**: the product of `1`, ..., `p-1` is `-1` modulo `p`. -/
@[simp]
theorem wilsons_lemma : ((p - 1)! : ZMod p) = -1 :=
@@ -71,13 +72,16 @@ theorem wilsons_lemma : ((p - 1)! : ZMod p) = -1 :=
simpa only [val_cast_of_lt hb.right, val_zero] using h
· simp only [val_cast_of_lt hb.right, Units.val_mk0]
#align zmod.wilsons_lemma ZMod.wilsons_lemma
+-/
+#print ZMod.prod_Ico_one_prime /-
@[simp]
theorem prod_Ico_one_prime : ∏ x in Ico 1 p, (x : ZMod p) = -1 :=
by
conv in Ico 1 p => rw [← succ_sub_one p, succ_sub (Fact.out p.prime).Pos]
rw [← prod_nat_cast, Finset.prod_Ico_id_eq_factorial, wilsons_lemma]
#align zmod.prod_Ico_one_prime ZMod.prod_Ico_one_prime
+-/
end ZMod
@@ -85,6 +89,7 @@ namespace Nat
variable {n : ℕ}
+#print Nat.prime_of_fac_equiv_neg_one /-
/-- For `n ≠ 1`, `(n-1)!` is congruent to `-1` modulo `n` only if n is prime. -/
theorem prime_of_fac_equiv_neg_one (h : ((n - 1)! : ZMod n) = -1) (h1 : n ≠ 1) : Prime n :=
by
@@ -97,7 +102,9 @@ theorem prime_of_fac_equiv_neg_one (h : ((n - 1)! : ZMod n) = -1) (h1 : n ≠ 1)
refine' hm2.ne' (nat.dvd_one.mp ((Nat.dvd_add_right hm).mp (hm1.trans _)))
rw [← ZMod.nat_cast_zmod_eq_zero_iff_dvd, cast_add, cast_one, h, add_left_neg]
#align nat.prime_of_fac_equiv_neg_one Nat.prime_of_fac_equiv_neg_one
+-/
+#print Nat.prime_iff_fac_equiv_neg_one /-
/-- **Wilson's Theorem**: For `n ≠ 1`, `(n-1)!` is congruent to `-1` modulo `n` iff n is prime. -/
theorem prime_iff_fac_equiv_neg_one (h : n ≠ 1) : Prime n ↔ ((n - 1)! : ZMod n) = -1 :=
by
@@ -105,6 +112,7 @@ theorem prime_iff_fac_equiv_neg_one (h : n ≠ 1) : Prime n ↔ ((n - 1)! : ZMod
haveI := Fact.mk h1
exact ZMod.wilsons_lemma n
#align nat.prime_iff_fac_equiv_neg_one Nat.prime_iff_fac_equiv_neg_one
+-/
end Nat
mathlib commit https://github.com/leanprover-community/mathlib/commit/9fb8964792b4237dac6200193a0d533f1b3f7423
@@ -4,7 +4,7 @@ Released under Apache 2.0 license as described in the file LICENSE.
Authors: John Nicol
! This file was ported from Lean 3 source module number_theory.wilson
-! leanprover-community/mathlib commit c471da714c044131b90c133701e51b877c246677
+! leanprover-community/mathlib commit 087c325ae0ab42dbdd5dee55bc37d3d5a0bf2197
! Please do not edit these lines, except to modify the commit id
! if you have ported upstream changes.
-/
@@ -13,6 +13,9 @@ import Mathbin.FieldTheory.Finite.Basic
/-!
# Wilson's theorem.
+> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
+> Any changes to this file require a corresponding PR to mathlib4.
+
This file contains a proof of Wilson's theorem.
The heavy lifting is mostly done by the previous `wilsons_lemma`,
mathlib commit https://github.com/leanprover-community/mathlib/commit/c471da714c044131b90c133701e51b877c246677
@@ -4,11 +4,11 @@ Released under Apache 2.0 license as described in the file LICENSE.
Authors: John Nicol
! This file was ported from Lean 3 source module number_theory.wilson
-! leanprover-community/mathlib commit e985d48324225202b17a7f9eb50b29ba09b77b44
+! leanprover-community/mathlib commit c471da714c044131b90c133701e51b877c246677
! Please do not edit these lines, except to modify the commit id
! if you have ported upstream changes.
-/
-import Mathbin.NumberTheory.LegendreSymbol.GaussEisensteinLemmas
+import Mathbin.FieldTheory.Finite.Basic
/-!
# Wilson's theorem.
@@ -26,11 +26,57 @@ This could be generalized to similar results about finite abelian groups.
## TODO
-* Move `wilsons_lemma` into this file, and give it a descriptive name.
+* Give `wilsons_lemma` a descriptive name.
-/
-open scoped Nat
+open Finset Nat FiniteField ZMod
+
+open scoped BigOperators Nat
+
+namespace ZMod
+
+variable (p : ℕ) [Fact p.Prime]
+
+/-- **Wilson's Lemma**: the product of `1`, ..., `p-1` is `-1` modulo `p`. -/
+@[simp]
+theorem wilsons_lemma : ((p - 1)! : ZMod p) = -1 :=
+ by
+ refine'
+ calc
+ ((p - 1)! : ZMod p) = ∏ x in Ico 1 (succ (p - 1)), x := by
+ rw [← Finset.prod_Ico_id_eq_factorial, prod_nat_cast]
+ _ = ∏ x : (ZMod p)ˣ, x := _
+ _ = -1 := by
+ simp_rw [← Units.coeHom_apply, ← (Units.coeHom (ZMod p)).map_prod,
+ prod_univ_units_id_eq_neg_one, Units.coeHom_apply, Units.val_neg, Units.val_one]
+ have hp : 0 < p := (Fact.out p.prime).Pos
+ symm
+ refine' prod_bij (fun a _ => (a : ZMod p).val) _ _ _ _
+ · intro a ha
+ rw [mem_Ico, ← Nat.succ_sub hp, Nat.succ_sub_one]
+ constructor
+ · apply Nat.pos_of_ne_zero; rw [← @val_zero p]
+ intro h; apply Units.ne_zero a (val_injective p h)
+ · exact val_lt _
+ · intro a ha; simp only [cast_id, nat_cast_val]
+ · intro _ _ _ _ h; rw [Units.ext_iff]; exact val_injective p h
+ · intro b hb
+ rw [mem_Ico, Nat.succ_le_iff, ← succ_sub hp, succ_sub_one, pos_iff_ne_zero] at hb
+ refine' ⟨Units.mk0 b _, Finset.mem_univ _, _⟩
+ · intro h; apply hb.1; apply_fun val at h
+ simpa only [val_cast_of_lt hb.right, val_zero] using h
+ · simp only [val_cast_of_lt hb.right, Units.val_mk0]
+#align zmod.wilsons_lemma ZMod.wilsons_lemma
+
+@[simp]
+theorem prod_Ico_one_prime : ∏ x in Ico 1 p, (x : ZMod p) = -1 :=
+ by
+ conv in Ico 1 p => rw [← succ_sub_one p, succ_sub (Fact.out p.prime).Pos]
+ rw [← prod_nat_cast, Finset.prod_Ico_id_eq_factorial, wilsons_lemma]
+#align zmod.prod_Ico_one_prime ZMod.prod_Ico_one_prime
+
+end ZMod
namespace Nat
@@ -59,3 +105,5 @@ theorem prime_iff_fac_equiv_neg_one (h : n ≠ 1) : Prime n ↔ ((n - 1)! : ZMod
end Nat
+assert_not_exists legendre_sym.quadratic_reciprocity
+
mathlib commit https://github.com/leanprover-community/mathlib/commit/cca40788df1b8755d5baf17ab2f27dacc2e17acb
@@ -40,7 +40,7 @@ variable {n : ℕ}
theorem prime_of_fac_equiv_neg_one (h : ((n - 1)! : ZMod n) = -1) (h1 : n ≠ 1) : Prime n :=
by
rcases eq_or_ne n 0 with (rfl | h0)
- · norm_num at h
+ · norm_num at h
replace h1 : 1 < n := n.two_le_iff.mpr ⟨h0, h1⟩
by_contra h2
obtain ⟨m, hm1, hm2 : 1 < m, hm3⟩ := exists_dvd_of_not_prime2 h1 h2
mathlib commit https://github.com/leanprover-community/mathlib/commit/917c3c072e487b3cccdbfeff17e75b40e45f66cb
@@ -30,7 +30,7 @@ This could be generalized to similar results about finite abelian groups.
-/
-open Nat
+open scoped Nat
namespace Nat
mathlib commit https://github.com/leanprover-community/mathlib/commit/02ba8949f486ebecf93fe7460f1ed0564b5e442c
@@ -46,7 +46,7 @@ theorem prime_of_fac_equiv_neg_one (h : ((n - 1)! : ZMod n) = -1) (h1 : n ≠ 1)
obtain ⟨m, hm1, hm2 : 1 < m, hm3⟩ := exists_dvd_of_not_prime2 h1 h2
have hm : m ∣ (n - 1)! := Nat.dvd_factorial (pos_of_gt hm2) (le_pred_of_lt hm3)
refine' hm2.ne' (nat.dvd_one.mp ((Nat.dvd_add_right hm).mp (hm1.trans _)))
- rw [← ZMod.nat_coe_zMod_eq_zero_iff_dvd, cast_add, cast_one, h, add_left_neg]
+ rw [← ZMod.nat_cast_zmod_eq_zero_iff_dvd, cast_add, cast_one, h, add_left_neg]
#align nat.prime_of_fac_equiv_neg_one Nat.prime_of_fac_equiv_neg_one
/-- **Wilson's Theorem**: For `n ≠ 1`, `(n-1)!` is congruent to `-1` modulo `n` iff n is prime. -/
mathlib commit https://github.com/leanprover-community/mathlib/commit/bd9851ca476957ea4549eb19b40e7b5ade9428cc
nat_cast
/int_cast
/rat_cast
to natCast
/intCast
/ratCast
(#11486)
Now that I am defining NNRat.cast
, I want a definitive answer to this naming issue. Plenty of lemmas in mathlib already use natCast
/intCast
/ratCast
over nat_cast
/int_cast
/rat_cast
, and this matches with the general expectation that underscore-separated name parts correspond to a single declaration.
@@ -66,7 +66,7 @@ theorem wilsons_lemma : ((p - 1)! : ZMod p) = -1 := by
· intro h; apply hb.1; apply_fun val at h
simpa only [val_cast_of_lt hb.right, val_zero] using h
· simp only [val_cast_of_lt hb.right, Units.val_mk0]
- · rintro a -; simp only [cast_id, nat_cast_val]
+ · rintro a -; simp only [cast_id, natCast_val]
#align zmod.wilsons_lemma ZMod.wilsons_lemma
@[simp]
@@ -94,7 +94,7 @@ theorem prime_of_fac_equiv_neg_one (h : ((n - 1)! : ZMod n) = -1) (h1 : n ≠ 1)
obtain ⟨m, hm1, hm2 : 1 < m, hm3⟩ := exists_dvd_of_not_prime2 h1 h2
have hm : m ∣ (n - 1)! := Nat.dvd_factorial (pos_of_gt hm2) (le_pred_of_lt hm3)
refine' hm2.ne' (Nat.dvd_one.mp ((Nat.dvd_add_right hm).mp (hm1.trans _)))
- rw [← ZMod.nat_cast_zmod_eq_zero_iff_dvd, cast_add, cast_one, h, add_left_neg]
+ rw [← ZMod.natCast_zmod_eq_zero_iff_dvd, cast_add, cast_one, h, add_left_neg]
#align nat.prime_of_fac_equiv_neg_one Nat.prime_of_fac_equiv_neg_one
/-- **Wilson's Theorem**: For `n ≠ 1`, `(n-1)!` is congruent to `-1` modulo `n` iff n is prime. -/
Lemmas around this were a mess, throth in terms of names, statement and location. This PR standardises everything to be in Algebra.BigOperators.Basic
and changes the lemmas to take in InjOn
and SurjOn
assumptions where possible (and where impossible make sure the hypotheses are taken in the correct order) and moves the equality of functions hypothesis last.
Also add a few lemmas that help fix downstream uses by golfing.
From LeanAPAP and LeanCamCombi
@@ -59,7 +59,6 @@ theorem wilsons_lemma : ((p - 1)! : ZMod p) = -1 := by
· apply Nat.pos_of_ne_zero; rw [← @val_zero p]
intro h; apply Units.ne_zero a (val_injective p h)
· exact val_lt _
- · rintro a -; simp only [cast_id, nat_cast_val]
· intro _ _ _ _ h; rw [Units.ext_iff]; exact val_injective p h
· intro b hb
rw [mem_Ico, Nat.succ_le_iff, ← succ_sub hp, Nat.add_one_sub_one, pos_iff_ne_zero] at hb
@@ -67,6 +66,7 @@ theorem wilsons_lemma : ((p - 1)! : ZMod p) = -1 := by
· intro h; apply hb.1; apply_fun val at h
simpa only [val_cast_of_lt hb.right, val_zero] using h
· simp only [val_cast_of_lt hb.right, Units.val_mk0]
+ · rintro a -; simp only [cast_id, nat_cast_val]
#align zmod.wilsons_lemma ZMod.wilsons_lemma
@[simp]
@@ -48,7 +48,7 @@ theorem wilsons_lemma : ((p - 1)! : ZMod p) = -1 := by
-- simp_rw [← Units.coeHom_apply, ← (Units.coeHom (ZMod p)).map_prod,
-- prod_univ_units_id_eq_neg_one, Units.coeHom_apply, Units.val_neg, Units.val_one]
simp_rw [← Units.coeHom_apply]
- rw [← (Units.coeHom (ZMod p)).map_prod]
+ rw [← map_prod (Units.coeHom (ZMod p))]
simp_rw [prod_univ_units_id_eq_neg_one, Units.coeHom_apply, Units.val_neg, Units.val_one]
have hp : 0 < p := (Fact.out (p := p.Prime)).pos
symm
@@ -54,7 +54,7 @@ theorem wilsons_lemma : ((p - 1)! : ZMod p) = -1 := by
symm
refine' prod_bij (fun a _ => (a : ZMod p).val) _ _ _ _
· intro a ha
- rw [mem_Ico, ← Nat.succ_sub hp, Nat.succ_sub_one]
+ rw [mem_Ico, ← Nat.succ_sub hp, Nat.add_one_sub_one]
constructor
· apply Nat.pos_of_ne_zero; rw [← @val_zero p]
intro h; apply Units.ne_zero a (val_injective p h)
@@ -62,7 +62,7 @@ theorem wilsons_lemma : ((p - 1)! : ZMod p) = -1 := by
· rintro a -; simp only [cast_id, nat_cast_val]
· intro _ _ _ _ h; rw [Units.ext_iff]; exact val_injective p h
· intro b hb
- rw [mem_Ico, Nat.succ_le_iff, ← succ_sub hp, succ_sub_one, pos_iff_ne_zero] at hb
+ rw [mem_Ico, Nat.succ_le_iff, ← succ_sub hp, Nat.add_one_sub_one, pos_iff_ne_zero] at hb
refine' ⟨Units.mk0 b _, Finset.mem_univ _, _⟩
· intro h; apply hb.1; apply_fun val at h
simpa only [val_cast_of_lt hb.right, val_zero] using h
@@ -75,7 +75,7 @@ theorem prod_Ico_one_prime : ∏ x in Ico 1 p, (x : ZMod p) = -1 := by
conv =>
congr
congr
- rw [← succ_sub_one p, succ_sub (Fact.out (p := p.Prime)).pos]
+ rw [← Nat.add_one_sub_one p, succ_sub (Fact.out (p := p.Prime)).pos]
rw [← prod_natCast, Finset.prod_Ico_id_eq_factorial, wilsons_lemma]
#align zmod.prod_Ico_one_prime ZMod.prod_Ico_one_prime
@@ -2,14 +2,11 @@
Copyright (c) 2022 John Nicol. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: John Nicol
-
-! This file was ported from Lean 3 source module number_theory.wilson
-! leanprover-community/mathlib commit c471da714c044131b90c133701e51b877c246677
-! Please do not edit these lines, except to modify the commit id
-! if you have ported upstream changes.
-/
import Mathlib.FieldTheory.Finite.Basic
+#align_import number_theory.wilson from "leanprover-community/mathlib"@"c471da714c044131b90c133701e51b877c246677"
+
/-!
# Wilson's theorem.
The unported dependencies are