Skip to content

Commit 2511ced

Browse files
refactor(multivariate): place renameEquiv and finSuccEquiv under CMvPolynomial namespace (#206)
* fix: dot notation in defs and duplicate defs removed * fix: added a comma
1 parent b29e6c3 commit 2511ced

3 files changed

Lines changed: 55 additions & 79 deletions

File tree

Lines changed: 42 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,58 @@
11
/-
22
Copyright (c) 2025 CompPoly. All rights reserved.
33
Released under Apache 2.0 license as described in the file LICENSE.
4-
Authors: Elias Judin, Aristotle (Harmonic)
4+
Authors: Elias Judin, Aristotle (Harmonic), Dimitris Mitsios
55
-/
66
import CompPoly.Multivariate.MvPolyEquiv
77
import Mathlib.Algebra.MvPolynomial.Equiv
88
import Mathlib.RingTheory.Polynomial.Basic
99

1010
/-!
11-
# `finSuccEquiv` and `optionEquivLeft` for `CMvPolynomial`
11+
# `finSuccEquiv` for `CMvPolynomial`
1212
13-
This file defines computable multivariate polynomial equivalences for splitting off one variable,
14-
mirroring `MvPolynomial.finSuccEquiv` and `MvPolynomial.optionEquivLeft` from Mathlib.
13+
This file defines the computable multivariate polynomial equivalence for
14+
splitting off one variable, mirroring `MvPolynomial.finSuccEquiv` from Mathlib.
15+
16+
In Mathlib, `MvPolynomial` accepts a general type `σ` for the index set of the
17+
variables. Then, `optionEquivLeft` provides the algebra isomorphism
18+
`MvPolynomial (Option σ) R ≃ₐ[R] Polynomial (MvPolynomial σ R)`. Finally,
19+
`finSuccEquiv` is defined as the composition of the rename step
20+
(`Fin (n+1) ≃ Option (Fin n)`) with `optionEquivLeft`. There is no such
21+
distinction in `CMvPolynomial` because the variables are of type `Fin n` by
22+
definition. Therefore, only `CMvPolynomial.finSuccEquiv` applies.
1523
1624
## Main definitions
1725
1826
* `CMvPolynomial.finSuccEquiv` — ring equivalence
1927
`CMvPolynomial (n+1) R ≃+* Polynomial (CMvPolynomial n R)`,
2028
viewing a polynomial in `n+1` variables as a univariate polynomial over `n` variables.
21-
* `CMvPolynomial.optionEquivLeft` — ring equivalence
22-
`CMvPolynomial (n+1) R ≃+* Polynomial (CMvPolynomial n R)`,
23-
defined as the composition of the variable renaming `Fin (n+1) ≃ Option (Fin n)` with
24-
the Mathlib `MvPolynomial.optionEquivLeft` equivalence. This mirrors the way
25-
`MvPolynomial.finSuccEquiv` is built from `MvPolynomial.optionEquivLeft`.
2629
2730
## Implementation notes
2831
29-
Both equivalences are `noncomputable` because they go through the `polyRingEquiv`
32+
The equivalence is `noncomputable` because it goes through the `polyRingEquiv`
3033
bridge between `CMvPolynomial` and `MvPolynomial`.
3134
3235
The forward/inverse correctness is obtained structurally from the underlying
3336
Mathlib `AlgEquiv` via `RingEquiv.trans`.
3437
-/
3538

36-
namespace CPoly
37-
38-
open Std CMvPolynomial
39+
open Std CPoly CMvPolynomial
3940

4041
variable {n : ℕ} {R : Type*} [CommSemiring R] [BEq R] [LawfulBEq R]
4142

43+
namespace CPoly
44+
4245
/-! ### Polynomial-level ring equivalence -/
4346

4447
/-- `Polynomial.mapEquiv` through the CMvPolynomial ↔ MvPolynomial bridge. -/
4548
noncomputable def polynomialCMvPolyEquiv :
4649
Polynomial (CMvPolynomial n R) ≃+* Polynomial (MvPolynomial (Fin n) R) :=
4750
Polynomial.mapEquiv polyRingEquiv
4851

52+
end CPoly
53+
54+
namespace CMvPolynomial
55+
4956
/-! ### `finSuccEquiv` -/
5057

5158
/-- Ring equivalence splitting off the first variable:
@@ -54,85 +61,46 @@ noncomputable def polynomialCMvPolyEquiv :
5461
This mirrors `MvPolynomial.finSuccEquiv R n`. The 0-th variable becomes
5562
the univariate indeterminate `Polynomial.X`, and variables `1, …, n` become
5663
the multivariate variables of the coefficient ring `CMvPolynomial n R`. -/
57-
noncomputable def CMvPolynomial.finSuccEquiv :
64+
noncomputable def finSuccEquiv :
5865
CMvPolynomial (n + 1) R ≃+* Polynomial (CMvPolynomial n R) :=
5966
(polyRingEquiv (n := n + 1)).trans <|
6067
(MvPolynomial.finSuccEquiv R n).toRingEquiv.trans polynomialCMvPolyEquiv.symm
6168

6269
/-- The equivalence is a left inverse: applying the inverse then forward is the identity. -/
6370
@[simp]
64-
theorem CMvPolynomial.finSuccEquiv_symm_apply_apply (p : CMvPolynomial (n + 1) R) :
65-
CMvPolynomial.finSuccEquiv.symm (CMvPolynomial.finSuccEquiv p) = p :=
66-
CMvPolynomial.finSuccEquiv.symm_apply_apply p
71+
theorem finSuccEquiv_symm_apply_apply (p : CMvPolynomial (n + 1) R) :
72+
finSuccEquiv.symm (finSuccEquiv p) = p :=
73+
finSuccEquiv.symm_apply_apply p
6774

6875
/-- The equivalence is a right inverse: applying forward then the inverse is the identity. -/
6976
@[simp]
70-
theorem CMvPolynomial.finSuccEquiv_apply_symm_apply
77+
theorem finSuccEquiv_apply_symm_apply
7178
(q : Polynomial (CMvPolynomial n R)) :
72-
CMvPolynomial.finSuccEquiv (CMvPolynomial.finSuccEquiv.symm q) = q :=
73-
CMvPolynomial.finSuccEquiv.apply_symm_apply q
79+
finSuccEquiv (finSuccEquiv.symm q) = q :=
80+
finSuccEquiv.apply_symm_apply q
7481

7582
/-- `finSuccEquiv` preserves addition. -/
76-
theorem CMvPolynomial.finSuccEquiv_add (p q : CMvPolynomial (n + 1) R) :
77-
CMvPolynomial.finSuccEquiv (p + q) =
78-
CMvPolynomial.finSuccEquiv p + CMvPolynomial.finSuccEquiv q :=
79-
CMvPolynomial.finSuccEquiv.map_add p q
83+
theorem finSuccEquiv_add (p q : CMvPolynomial (n + 1) R) :
84+
finSuccEquiv (p + q) =
85+
finSuccEquiv p + finSuccEquiv q :=
86+
finSuccEquiv.map_add p q
8087

8188
/-- `finSuccEquiv` preserves multiplication. -/
82-
theorem CMvPolynomial.finSuccEquiv_mul (p q : CMvPolynomial (n + 1) R) :
83-
CMvPolynomial.finSuccEquiv (p * q) =
84-
CMvPolynomial.finSuccEquiv p * CMvPolynomial.finSuccEquiv q :=
85-
CMvPolynomial.finSuccEquiv.map_mul p q
89+
theorem finSuccEquiv_mul (p q : CMvPolynomial (n + 1) R) :
90+
finSuccEquiv (p * q) =
91+
finSuccEquiv p * finSuccEquiv q :=
92+
finSuccEquiv.map_mul p q
8693

8794
/-- `finSuccEquiv` maps zero to zero. -/
8895
@[simp]
89-
theorem CMvPolynomial.finSuccEquiv_zero :
90-
CMvPolynomial.finSuccEquiv (0 : CMvPolynomial (n + 1) R) = 0 :=
91-
RingEquiv.map_zero (CMvPolynomial.finSuccEquiv (n := n) (R := R))
96+
theorem finSuccEquiv_zero :
97+
finSuccEquiv (0 : CMvPolynomial (n + 1) R) = 0 :=
98+
RingEquiv.map_zero (finSuccEquiv (n := n) (R := R))
9299

93100
/-- `finSuccEquiv` maps one to one. -/
94101
@[simp]
95-
theorem CMvPolynomial.finSuccEquiv_one :
96-
CMvPolynomial.finSuccEquiv (1 : CMvPolynomial (n + 1) R) = 1 :=
97-
RingEquiv.map_one (CMvPolynomial.finSuccEquiv (n := n) (R := R))
98-
99-
/-! ### `optionEquivLeft` -/
100-
101-
/-- Ring equivalence mirroring `MvPolynomial.optionEquivLeft` for `CMvPolynomial`.
102-
103-
Since `CMvPolynomial` is indexed by `Fin n`, the `Option`-indexed analogue
104-
of `MvPolynomial.optionEquivLeft R (Fin n)` is an equivalence
105-
`CMvPolynomial (n+1) R ≃+* Polynomial (CMvPolynomial n R)`.
106-
We define it by composing the `polyRingEquiv` bridge with the Mathlib
107-
`MvPolynomial.optionEquivLeft` (after renaming `Fin (n+1) ≃ Option (Fin n)`
108-
via `finSuccEquiv'`), matching how `MvPolynomial.finSuccEquiv` is built. -/
109-
noncomputable def CMvPolynomial.optionEquivLeft :
110-
CMvPolynomial (n + 1) R ≃+* Polynomial (CMvPolynomial n R) :=
111-
CMvPolynomial.finSuccEquiv
112-
113-
/-- `optionEquivLeft` is a left inverse. -/
114-
@[simp]
115-
theorem CMvPolynomial.optionEquivLeft_symm_apply_apply (p : CMvPolynomial (n + 1) R) :
116-
CMvPolynomial.optionEquivLeft.symm (CMvPolynomial.optionEquivLeft p) = p :=
117-
CMvPolynomial.optionEquivLeft.symm_apply_apply p
102+
theorem finSuccEquiv_one :
103+
finSuccEquiv (1 : CMvPolynomial (n + 1) R) = 1 :=
104+
RingEquiv.map_one (finSuccEquiv (n := n) (R := R))
118105

119-
/-- `optionEquivLeft` is a right inverse. -/
120-
@[simp]
121-
theorem CMvPolynomial.optionEquivLeft_apply_symm_apply
122-
(q : Polynomial (CMvPolynomial n R)) :
123-
CMvPolynomial.optionEquivLeft (CMvPolynomial.optionEquivLeft.symm q) = q :=
124-
CMvPolynomial.optionEquivLeft.apply_symm_apply q
125-
126-
/-- `optionEquivLeft` preserves addition. -/
127-
theorem CMvPolynomial.optionEquivLeft_add (p q : CMvPolynomial (n + 1) R) :
128-
CMvPolynomial.optionEquivLeft (p + q) =
129-
CMvPolynomial.optionEquivLeft p + CMvPolynomial.optionEquivLeft q :=
130-
CMvPolynomial.optionEquivLeft.map_add p q
131-
132-
/-- `optionEquivLeft` preserves multiplication. -/
133-
theorem CMvPolynomial.optionEquivLeft_mul (p q : CMvPolynomial (n + 1) R) :
134-
CMvPolynomial.optionEquivLeft (p * q) =
135-
CMvPolynomial.optionEquivLeft p * CMvPolynomial.optionEquivLeft q :=
136-
CMvPolynomial.optionEquivLeft.map_mul p q
137-
138-
end CPoly
106+
end CMvPolynomial

CompPoly/Multivariate/Rename.lean

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,9 +287,17 @@ lemma rename_rename {k : ℕ} (f : Fin n → Fin m)
287287
fromCMvPolynomial_rename]
288288
exact MvPolynomial.rename_rename f g (fromCMvPolynomial p)
289289

290+
end CPoly
291+
292+
namespace CMvPolynomial
293+
294+
open CPoly
295+
296+
variable {n m : ℕ} {R : Type*} [CommSemiring R] [BEq R] [LawfulBEq R]
297+
290298
/-- Ring equivalence for variable renaming when the function is
291299
a bijection. -/
292-
noncomputable def CMvPolynomial.renameEquiv
300+
noncomputable def renameEquiv
293301
(f : Fin n ≃ Fin m) :
294302
CMvPolynomial n R ≃+* CMvPolynomial m R where
295303
toFun := CMvPolynomial.rename f
@@ -301,4 +309,4 @@ noncomputable def CMvPolynomial.renameEquiv
301309
map_add' p q := rename_add f p q
302310
map_mul' p q := rename_mul f p q
303311

304-
end CPoly
312+
end CMvPolynomial

ROADMAP.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ CompPoly aims to be the premier formally verified library for computable polynom
4242
-`aeval`, `bind₁`: Algebra evaluation and substitution
4343
-`algebra`, `module`: Algebra and module structures
4444
-`degrees`; ✅ `eval₂Hom`: Degree utilities and evaluation homomorphisms
45-
-`finSuccEquiv`, `optionEquivLeft`: Variable manipulation equivalences (for `CMvPolynomial`)
45+
-`finSuccEquiv`: Variable manipulation equivalences (for `CMvPolynomial`)
4646
-`isEmptyRingEquiv` for `CMvPolynomial 0 R`
4747
-`smulZeroClass`: Scalar multiplication with zero behavior
4848
-`sumToIter`: Iteration utility with reconstruction/API lemmas
@@ -69,7 +69,7 @@ CompPoly aims to be the premier formally verified library for computable polynom
6969
- Implement FFT/NTT-based multiplication (O(n log n) vs current O(n²))
7070
- Focus on NTT for finite field arithmetic
7171
- Maintain correctness proofs alongside optimizations
72-
72+
7373
**Note**: [erdkocak](https://github.com/erdkocak) and [doran2728](https://github.com/doran2728) have communicated they will be working on this.
7474

7575
3. **Exponentiation optimization**
@@ -105,7 +105,7 @@ CompPoly aims to be the premier formally verified library for computable polynom
105105

106106
**Goal**: Turn CompPoly into an integration-ready, downstream-friendly library by adding interoperability layers, serialization, proof automation, and extraction compatibility.
107107

108-
#### Priorities
108+
#### Priorities
109109

110110
1. **Lowering / interop with LLZK / PrimeIR polynomial dialects**
111111
- Explore representing CompPoly structures in the MLIR pipeline

0 commit comments

Comments
 (0)