Commit 2024-11-04 08:35 88fac4fd
View on Github →chore: refactor roots of unity to avoid PNat (#18516)
This is an attempt to refactor the definition of rootsOfUnity using a Nat instead of a PNat.
- In the definition of
rootsOfUnity, we replace(n : ℕ+)by(n : ℕ). The definition does not requirento be nonzero; it gives thatrootsOfUnity 0 Mis the top subgroup of the unit group ofM. - For results that need a positive
n, we replace(n : ℕ+)with(n : ℕ) [NeZero n]in the parameters. In this way, they transparently apply when aPNatis used fornsincengets coerced toNatand anNeZero (n : ℕ)instance is available. The main benefit is that one no longer needs constructions likerootsOfUnity ⟨n, <proof that n is positive⟩) Rwhennis a natural number; one can simply userootsOfUnity n R. (One may need to turn the positivity proof into anNeZeroinstance, however, if that is not available automatically.) In addition, the code inMathlib.RingTheory.RootsOfUnity.Basiccan be simplified a bit in places, e.g.,x ^ (k : ℕ)can be replaced byx ^ kand∃ (i : ℕ), i < k ∧ P ican be replaced by∃ i < k, P i. One result (eq_pow_of_mem_rootsOfUnity'; it was translating betweenNats andPNats) can be removed altogether. Since I was going through this file anyway, I took the opportunity to replace=>by↦and to do some golfing as well. What this PR does not do is also refactoring cyclotomic extensions to not use (sets of)PNats. This is a more complex matter and requires more thought and discussion.