theoremkernel_square_residues (S : Finsetℤ) (root : ℤ→ℕ)
(m : ℕ) (h u : ℤ) (hred : h.natAbs.Coprime m) (hS : S.Nonempty)
(hroot : ∀ x ∈S, u * (root x : ℤ) ^ 2 = (m : ℤ) * x - h) :
∃a : (ZMod m)ˣ, ∀ x ∈S,
(root x).Coprime m ∧ (root x : ZMod m) ^ 2 = (a : ZMod m) :=by
proof · 13
lines
obtain ⟨x0, hx0⟩ := hS
have ht0 := kernel_root_coprime m (root x0) h x0 u hred (hroot x0 hx0)
let a := (ZMod.unitOfCoprime (root x0) ht0) ^ 2
refine ⟨a, fun x hx => ⟨kernel_root_coprime m (root x) h x u hred (hroot x hx), ?_⟩⟩
have hu := intCast_isUnit_of_natAbs_coprime m u
(kernel_coefficient_coprime m h x0 u (root x0) hred (hroot x0 hx0))
have h1 := congrArg (funz : ℤ=> (z : ZMod m)) (hroot x hx)
have h0 := congrArg (funz : ℤ=> (z : ZMod m)) (hroot x0 hx0)
simp only [Int.cast_mul, Int.cast_pow, Int.cast_natCast, Int.cast_sub,
ZMod.natCast_self, zero_mul, zero_sub] at h1 h0
haveheq : (root x : ZMod m) ^ 2 = (root x0 : ZMod m) ^ 2:=
hu.mul_left_cancel (h1.trans h0.symm)
simpa [a] using heq