Skip to content

Commit 876249b

Browse files
committed
feat: Chinese Remainder Theorem for ZMod n (#29761)
Define `ZMod.equivPi`, the Chinese Remainder Theorem for `ZMod n`, decomposing it as a product of `ZMod` over its prime power factors. Co-authored-by: bwangpj <70694994+bwangpj@users.noreply.github.com>
1 parent 8c6c626 commit 876249b

2 files changed

Lines changed: 22 additions & 0 deletions

File tree

Mathlib/Data/Nat/Factorization/Basic.lean

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,20 @@ theorem prod_pow_prime_padicValNat (n : Nat) (hn : n ≠ 0) (m : Nat) (pr : n <
442442
· intro p hp
443443
simp [factorization_def n (prime_of_mem_primeFactors hp)]
444444

445+
lemma prod_pow_primeFactors_factorization (hn : n ≠ 0) :
446+
n = ∏ (p : n.primeFactors), (p : ℕ) ^ (n.factorization p) := by
447+
nth_rw 1 [← factorization_prod_pow_eq_self hn]
448+
rw [prod_factorization_eq_prod_primeFactors _]
449+
exact prod_subtype n.primeFactors (fun _ ↦ Iff.rfl) fun a ↦ a ^ n.factorization a
450+
451+
lemma pairwise_coprime_pow_primeFactors_factorization :
452+
Pairwise (Function.onFun Nat.Coprime fun (p : n.primeFactors) ↦ p ^ n.factorization p) := by
453+
intro p1 p2 hp
454+
refine Nat.Coprime.pow (n.factorization p1) (n.factorization p2) ?_
455+
refine (Nat.coprime_primes ?_ ?_).mpr <| Subtype.coe_ne_coe.mpr hp
456+
· exact Nat.prime_of_mem_primeFactors p1.2
457+
· exact Nat.prime_of_mem_primeFactors p2.2
458+
445459
/-! ### Lemmas about factorizations of particular functions -/
446460

447461
/-- Exactly `n / p` naturals in `[1, n]` are multiples of `p`.

Mathlib/Data/ZMod/QuotientRing.lean

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Authors: Anne Baanen
66
import Mathlib.RingTheory.Ideal.Quotient.Operations
77
import Mathlib.RingTheory.Int.Basic
88
import Mathlib.RingTheory.ZMod
9+
import Mathlib.Data.Nat.Factorization.Basic
910

1011
/-!
1112
# `ZMod n` and quotient groups / rings
@@ -76,4 +77,11 @@ def ZMod.prodEquivPi {ι : Type*} [Fintype ι] (a : ι → ℕ)
7677
quotientInfRingEquivPiQuotient _ this |>.trans <|
7778
RingEquiv.piCongrRight fun i ↦ Int.quotientSpanNatEquivZMod (a i)
7879

80+
/-- The **Chinese remainder theorem**, version for `ZMod n`. -/
81+
def ZMod.equivPi (hn : n ≠ 0) :
82+
ZMod n ≃+* Π (p : n.primeFactors), ZMod (p ^ (n.factorization p)) :=
83+
(ringEquivCongr <| Nat.prod_pow_primeFactors_factorization hn).trans
84+
<| prodEquivPi (fun (p : n.primeFactors) ↦ (p : ℕ) ^ (n.factorization p))
85+
n.pairwise_coprime_pow_primeFactors_factorization
86+
7987
end ChineseRemainder

0 commit comments

Comments
 (0)