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 requiren
to be nonzero; it gives thatrootsOfUnity 0 M
is 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 aPNat
is used forn
sincen
gets coerced toNat
and anNeZero (n : ℕ)
instance is available. The main benefit is that one no longer needs constructions likerootsOfUnity ⟨n, <proof that n is positive⟩) R
whenn
is a natural number; one can simply userootsOfUnity n R
. (One may need to turn the positivity proof into anNeZero
instance, however, if that is not available automatically.) In addition, the code inMathlib.RingTheory.RootsOfUnity.Basic
can be simplified a bit in places, e.g.,x ^ (k : ℕ)
can be replaced byx ^ k
and∃ (i : ℕ), i < k ∧ P i
can be replaced by∃ i < k, P i
. One result (eq_pow_of_mem_rootsOfUnity'
; it was translating betweenNat
s andPNat
s) 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)PNat
s. This is a more complex matter and requires more thought and discussion.