Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
116 changes: 109 additions & 7 deletions CompPoly/Fields/Mersenne31/Circle.lean
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@ index arithmetic modulo the circle order, and the coset/domain shapes used by
canonical circle domains.

Circle points form an additive commutative group, with binary scalar multiplication.
The STWO generator has order `2^31`, and `CirclePointIndex.toPoint` respects addition.
The STWO generator has order `2^31`, and `CirclePointIndex.toPoint` is injective and
respects addition. Each subgroup step has the requested exact order.

Cosets and domains currently describe indexing shapes, not certified sets of distinct
points. A follow-up must specify validity conditions and prove point distinctness,
disjointness of domain halves, and equality of the declared size with set cardinality.
These properties do not hold for arbitrary values of the current structures.
`Coset.Valid` requires the step order to equal the declared size. Standard constructors
satisfy it; valid cosets enumerate distinct indices and points and have the declared
range cardinality. Circle domains still need a validity condition requiring disjoint
halves before their declared size can be identified with set cardinality.
-/

public section
Expand Down Expand Up @@ -348,6 +349,36 @@ def toPointHom : CirclePointIndex →+ Point where
@[simp]
theorem toPointHom_apply (i : CirclePointIndex) : toPointHom i = toPoint i := by rfl

/-- Different circle indices represent different points. -/
theorem toPoint_injective : Function.Injective toPoint := by
intro i j hij
apply ZMod.val_injective
apply nsmul_injOn_Iio_addOrderOf (x := Circle.generator)
(by simpa only [Set.mem_Iio, addOrderOf_generator] using i.val_lt)
(by simpa only [Set.mem_Iio, addOrderOf_generator] using j.val_lt)
simpa only [toPoint_def] using hij

/-- Equality of interpreted points is exactly equality of their indices. -/
@[simp]
theorem toPoint_inj {i j : CirclePointIndex} : toPoint i = toPoint j ↔ i = j :=
toPoint_injective.eq_iff

/-- Interpreting an index preserves its additive order. -/
theorem addOrderOf_toPoint (i : CirclePointIndex) :
addOrderOf (toPoint i) = addOrderOf i :=
addOrderOf_injective toPointHom toPoint_injective i

/-- The subgroup step has the requested exact order, including log sizes zero and 31. -/
theorem addOrderOf_subgroupGen (n : Nat) (h : n ≤ logOrder) :
addOrderOf (subgroupGen n h) = 2 ^ n := by
rw [subgroupGen_eq, ZMod.addOrderOf_coe _ (by decide : order ≠ 0)]
have hmul : order = 2 ^ n * 2 ^ (logOrder - n) := by
rw [← pow_add, Nat.add_sub_of_le h]
have hdvd : 2 ^ (logOrder - n) ∣ order := by
rw [hmul]
exact dvd_mul_left _ _
rw [Nat.gcd_eq_right hdvd, hmul, Nat.mul_div_cancel _ (pow_pos (by decide) _)]

/-- Negating an index conjugates its circle point. -/
@[simp]
theorem toPoint_neg (i : CirclePointIndex) : toPoint (-i) = -toPoint i :=
Expand All @@ -372,9 +403,9 @@ theorem subgroupGen_logOrder (h : logOrder ≤ logOrder) :

end CirclePointIndex

/-- An indexing shape with a fixed additive step, not a certified coset of distinct points.
/-- An indexing shape with a fixed additive step.
No relation between `stepSize` and `logSize` is required; a zero step is allowed.
Validity conditions and distinctness/cardinality theorems are deferred to a follow-up. -/
`Coset.Valid` supplies the exact-order condition for distinctness and cardinality. -/
structure Coset where
initialIndex : CirclePointIndex
stepSize : CirclePointIndex
Expand Down Expand Up @@ -459,6 +490,62 @@ def pointAt (c : Coset) (i : Nat) : Point :=
theorem pointAt_def (c : Coset) (i : Nat) :
c.pointAt i = CirclePointIndex.toPoint (c.indexAt i) := by rfl

/-- The step has exactly as many distinct multiples as the declared coset size. -/
def Valid (c : Coset) : Prop := addOrderOf c.stepSize = c.size

/-- Validity is an exact-order condition on the step, independent of the initial index. -/
theorem valid_iff (c : Coset) : c.Valid ↔ addOrderOf c.stepSize = c.size := by rfl

/-- The standard constructor uses a step of the requested order. -/
theorem new_valid (i : CirclePointIndex) (n : Nat) (h : n ≤ logOrder) :
(new i n h).Valid := by
rw [valid_iff, new_stepSize, size_eq, new_logSize]
exact CirclePointIndex.addOrderOf_subgroupGen n h

/-- The subgroup constructor has a step of the declared order. -/
theorem subgroup_valid (n : Nat) (h : n ≤ logOrder) : (subgroup n h).Valid := by
rw [subgroup_eq]
exact new_valid _ _ _

/-- The odds constructor has a step of the declared order. -/
theorem odds_valid (n : Nat) (h : n + 1 ≤ logOrder) : (odds n h).Valid := by
rw [odds_eq]
exact new_valid _ _ _

/-- The half-odds constructor has a step of the declared order. -/
theorem halfOdds_valid (n : Nat) (h : n + 2 ≤ logOrder) : (halfOdds n h).Valid := by
rw [halfOdds_eq]
exact new_valid _ _ _

/-- Valid cosets enumerate distinct indices within their declared size. -/
theorem indexAt_injective (c : Coset) (hc : c.Valid) :
Function.Injective (fun i : Fin c.size => c.indexAt i.val) := by
intro i j hij
apply Fin.ext
have horder := (valid_iff c).mp hc
apply nsmul_injOn_Iio_addOrderOf (x := c.stepSize)
(by simpa only [Set.mem_Iio, horder] using i.isLt)
(by simpa only [Set.mem_Iio, horder] using j.isLt)
simpa only [indexAt_eq, add_right_inj, nsmul_eq_mul, mul_comm] using hij

/-- Valid cosets enumerate distinct circle points within their declared size. -/
theorem pointAt_injective (c : Coset) (hc : c.Valid) :
Function.Injective (fun i : Fin c.size => c.pointAt i.val) := by
intro i j hij
apply c.indexAt_injective hc
apply CirclePointIndex.toPoint_injective
simpa only [pointAt_def] using hij

/-- The bounded index range of a valid coset has its declared cardinality. -/
theorem card_range_indexAt (c : Coset) (hc : c.Valid) :
Nat.card (Set.range (fun i : Fin c.size => c.indexAt i.val)) = c.size := by
simpa only [Nat.card_fin] using Nat.card_range_of_injective (c.indexAt_injective hc)

/-- The bounded point range of a valid coset has its declared cardinality. -/
theorem card_range_pointAt (c : Coset) (hc : c.Valid) :
Nat.card (Set.range (fun i : Fin c.size => c.pointAt i.val)) = c.size := by
simpa only [Nat.card_fin] using Nat.card_range_of_injective (c.pointAt_injective hc)

/-- The conjugate coset `-initial - <step>`. -/
def conjugate (c : Coset) : Coset where
initialIndex := -c.initialIndex
Expand Down Expand Up @@ -490,6 +577,11 @@ theorem conjugate_initialIndex (c : Coset) :
@[simp]
theorem conjugate_stepSize (c : Coset) : c.conjugate.stepSize = -c.stepSize := by rfl

/-- Conjugation preserves the exact-order condition. -/
@[simp]
theorem conjugate_valid_iff (c : Coset) : c.conjugate.Valid ↔ c.Valid := by
simp only [valid_iff, conjugate_stepSize, addOrderOf_neg, size_eq, conjugate_logSize]

/-- Each conjugate-coset index is the negation of the corresponding original index. -/
@[simp]
theorem conjugate_indexAt (c : Coset) (i : Nat) :
Expand Down Expand Up @@ -608,6 +700,16 @@ theorem halfCoset_eq (c : CanonicCoset) :
have hBound := c.logSize_succ_le_logOrder
omega) := by rfl

/-- The full canonical coset has a step of the declared order. -/
theorem coset_valid (c : CanonicCoset) : c.coset.Valid := by
rw [coset_eq]
exact Coset.odds_valid _ _

/-- The canonical half coset has a step of the declared order. -/
theorem halfCoset_valid (c : CanonicCoset) : c.halfCoset.Valid := by
rw [halfCoset_eq]
exact Coset.halfOdds_valid _ _

/-- The canonical circle domain with the same log size. -/
def circleDomain (c : CanonicCoset) : CircleDomain :=
CircleDomain.new c.halfCoset
Expand Down
19 changes: 14 additions & 5 deletions docs/wiki/field-extensions.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,20 @@ use `by decide`. `CirclePointIndex.subgroupGen logSize h` requires a proof
`h : logSize ≤ logOrder`; out-of-range sizes are rejected instead of silently
truncating the exponent. Coset constructors pass their existing bounds to it.

`Coset` and `CircleDomain` still describe indexing shapes: arbitrary steps are allowed,
points may repeat, and a half coset may overlap its conjugate. Their `size` counts index
positions, not necessarily distinct points. The follow-up must specify validity conditions
and prove coset point distinctness, disjointness of domain halves, and the corresponding
cardinality theorems. These claims cannot be made for all current structure values.
`CirclePointIndex.toPoint_injective` proves that different indices represent different
points. `addOrderOf_toPoint` transfers exact orders to points, and
`addOrderOf_subgroupGen` proves the requested order `2^logSize`, including log sizes 0 and 31.

`Coset.Valid` requires the step's additive order to equal the declared size. The standard
constructors satisfy it, as do `CanonicCoset.coset` and `CanonicCoset.halfCoset`.
Conjugation preserves validity. For valid cosets, `indexAt_injective` and
`pointAt_injective` prove distinctness over `Fin c.size`; `card_range_indexAt` and
`card_range_pointAt` identify the bounded ranges' cardinalities with `c.size`.
Arbitrary structure values need not satisfy this condition.

`CircleDomain` still describes an indexing shape: even a valid half coset may overlap
its conjugate. Domain validity, disjointness of the halves, and domain cardinality
remain follow-up work. Coset validity alone does not establish these claims.

## Irreducibility: Rabin, Collapsed

Expand Down
84 changes: 84 additions & 0 deletions tests/CompPolyTests/Fields/Mersenne31/Circle.lean
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,90 @@ example : CirclePointIndex.toPoint CirclePointIndex.generator = generator := by

example : addOrderOf generator = 2 ^ 31 := addOrderOf_generator

example : Function.Injective CirclePointIndex.toPoint := CirclePointIndex.toPoint_injective

example (i j : CirclePointIndex) :
CirclePointIndex.toPoint i = CirclePointIndex.toPoint j ↔ i = j := by
simp only [CirclePointIndex.toPoint_inj]

example (i : CirclePointIndex) : CirclePointIndex.toPoint i = 0 ↔ i = 0 := by
rw [← CirclePointIndex.toPoint_zero, CirclePointIndex.toPoint_inj]

example (i : CirclePointIndex) :
addOrderOf (CirclePointIndex.toPoint i) = addOrderOf i :=
CirclePointIndex.addOrderOf_toPoint i

example (n : Nat) (h : n ≤ logOrder) :
addOrderOf (CirclePointIndex.toPoint (CirclePointIndex.subgroupGen n h)) = 2 ^ n := by
rw [CirclePointIndex.addOrderOf_toPoint, CirclePointIndex.addOrderOf_subgroupGen]

example : addOrderOf (CirclePointIndex.subgroupGen 0 (by decide)) = 1 :=
CirclePointIndex.addOrderOf_subgroupGen 0 (by decide)

example : addOrderOf (CirclePointIndex.subgroupGen 1 (by decide)) = 2 :=
CirclePointIndex.addOrderOf_subgroupGen 1 (by decide)

example : addOrderOf (CirclePointIndex.subgroupGen 30 (by decide)) = 2 ^ 30 :=
CirclePointIndex.addOrderOf_subgroupGen 30 (by decide)

example : addOrderOf (CirclePointIndex.subgroupGen 31 (by decide)) = 2 ^ 31 :=
CirclePointIndex.addOrderOf_subgroupGen 31 (by decide)

example (i : CirclePointIndex) (n : Nat) (h : n ≤ logOrder) :
(Coset.new i n h).Valid := Coset.new_valid i n h

example : (Coset.subgroup 0 (by decide)).Valid := Coset.subgroup_valid _ _

example : (Coset.subgroup 31 (by decide)).Valid := Coset.subgroup_valid _ _

example : (Coset.odds 30 (by decide)).Valid := Coset.odds_valid _ _

example : (Coset.halfOdds 29 (by decide)).Valid := Coset.halfOdds_valid _ _

example (c : Coset) : c.Valid ↔ addOrderOf c.stepSize = c.size := by
fail_if_success rfl
exact c.valid_iff

example (c : Coset) (hc : c.Valid) : c.conjugate.Valid := by
simpa only [Coset.conjugate_valid_iff] using hc

example (c : Coset) (hc : c.Valid) (i j : Fin c.size)
(h : c.indexAt i.val = c.indexAt j.val) : i = j := c.indexAt_injective hc h

example (c : Coset) (hc : c.Valid) (i j : Fin c.size)
(h : c.pointAt i.val = c.pointAt j.val) : i = j := c.pointAt_injective hc h

example (c : Coset) (hc : c.Valid) :
Nat.card (Set.range (fun i : Fin c.size => c.indexAt i.val)) = c.size :=
c.card_range_indexAt hc

example (c : Coset) (hc : c.Valid) :
Nat.card (Set.range (fun i : Fin c.size => c.pointAt i.val)) = c.size :=
c.card_range_pointAt hc

example (c : CanonicCoset) :
Function.Injective (fun i : Fin c.coset.size => c.coset.pointAt i.val) :=
c.coset.pointAt_injective c.coset_valid

example (c : CanonicCoset) :
Nat.card (Set.range (fun i : Fin c.halfCoset.size => c.halfCoset.pointAt i.val)) =
c.halfCoset.size := c.halfCoset.card_range_pointAt c.halfCoset_valid

-- A size-two indexing shape with a zero step does not satisfy the exact-order condition.
example : ¬ (Coset.mk 0 0 1 (by decide)).Valid := by
rw [Coset.valid_iff, Coset.size_eq]
simp only [addOrderOf_zero, pow_one]
decide

-- A valid singleton half coset can still overlap its conjugate.
example : (CircleDomain.new (Coset.subgroup 0 (by decide))).indexAt 0 =
(CircleDomain.new (Coset.subgroup 0 (by decide))).indexAt 1 := by
rw [CircleDomain.indexAt_def, CircleDomain.indexAt_def]
simp only [CircleDomain.new_halfCoset, Coset.size_eq, Coset.subgroup_eq,
Coset.new_logSize, pow_zero, Nat.zero_lt_one, ↓reduceIte, lt_self_iff_false,
Nat.sub_self, Coset.indexAt_zero, Coset.new_initialIndex, Coset.conjugate_initialIndex,
neg_zero]

example : order • generator = 0 := order_nsmul_generator

example : (2 ^ 30 : Nat) • generator = Point.antipode 0 := generator_half_order
Expand Down
Loading