Skip to content

stdlib: commutative algebra; mixins for domains and fields - #1244

Merged
strub merged 1 commit into
mainfrom
feat/comm-algebra
Nov 24, 2026
Merged

strub merged 1 commit into
mainfrom
feat/comm-algebra

Conversation

@strub

@strub strub commented Nov 24, 2026

Copy link
Copy Markdown
Member

New theory CommAlgebra, over an integral domain:

  • Base is the ideal-theoretic core, with no axiom beyond the ring
    structure: divisibility, the Chinese remainder theorem stated with
    Bezout witnesses (comax x y, defined as
    exists u v, u * x + v * y = oner), and the congruence modulo an
    element (eqm m x y, an abbreviation for m %| (x - y)). An
    instance can enter at this level by giving the Bezout witnesses
    directly, without any division theory.
  • Euclidean includes Base and adds a weight function with its
    axioms, gcds, Bezout, coprimality, factorization and the coprime
    form of the CRT.

Ring gains mixins, which take their parent ComRing as a parameter
instead of copying it, so that a ring has a single ring object:

  • IDomainMixin carries mulf_eq0 and the domain lemmas;
  • FieldMixin has a single axiom, that the units are the nonzero
    elements; mulf_eq0 is derived, and its Dom is an IDomainMixin
    over the same parent;
  • IDomainBundle and FieldBundle package the carrier, the ring and
    the mixin, so that a consumer takes a single theory parameter.

Ideal and CommAlgebra take a ComRing and an IDomainMixin.

Poly takes its coefficients as a ComRing plus an IDomainMixin.
Its units are now realized instead of being left unproved and
cleared, and its domain level IDPoly is a mixin over the one
PolyComRing. Poly also gains:

  • evaluation lemmas (pevalC, pevalD, pevalM, peval_sum,
    peval_prod, ...); peval now sums over 0 <= i < deg p;
  • products of monic linear factors (mprod), with their roots and
    degree;
  • PolyField, polynomials over a field, with Lagrange interpolation
    in PolyField.Lagrange.

ZModP gets its field structure from the mixin ZModpFieldMx and the
bundle ZModpFieldBd, over the one ring ZModpRing, instead of a
second clone of Ring.Field. ZModpField remains as a packed alias,
so qualified names such as ZModpField.mulrC still resolve:

theory ZModpField = ZModpRing + ZModpFieldMx.

This breaks the developments that clone ZModpField: an alias cannot
be cloned. They clone the bundle instead, and its ring lemmas are
under R:

clone GP.ZModE.ZModpFieldBd as ZPF.
... ZPF.R.mulrC ...

The examples and DHIES are updated accordingly.

Base automatically changed from feat/theory-alias-packed to main November 24, 2026 16:55
@strub
strub force-pushed the feat/comm-algebra branch from b63770c to 5d9d4c8 Compare November 24, 2026 17:00
New theory CommAlgebra, over an integral domain:

- `Base` is the ideal-theoretic core, with no axiom beyond the ring
  structure: divisibility, the Chinese remainder theorem stated with
  Bezout witnesses (`comax x y`, defined as
  `exists u v, u * x + v * y = oner`), and the congruence modulo an
  element (`eqm m x y`, an abbreviation for `m %| (x - y)`). An
  instance can enter at this level by giving the Bezout witnesses
  directly, without any division theory.
- `Euclidean` includes `Base` and adds a weight function with its
  axioms, gcds, Bezout, coprimality, factorization and the coprime
  form of the CRT.

Ring gains mixins, which take their parent `ComRing` as a parameter
instead of copying it, so that a ring has a single ring object:

- `IDomainMixin` carries `mulf_eq0` and the domain lemmas;
- `FieldMixin` has a single axiom, that the units are the nonzero
  elements; `mulf_eq0` is derived, and its `Dom` is an `IDomainMixin`
  over the same parent;
- `IDomainBundle` and `FieldBundle` package the carrier, the ring and
  the mixin, so that a consumer takes a single theory parameter.

Ideal and CommAlgebra take a `ComRing` and an `IDomainMixin`.

Poly takes its coefficients as a `ComRing` plus an `IDomainMixin`.
Its units are now realized instead of being left unproved and
cleared, and its domain level `IDPoly` is a mixin over the one
`PolyComRing`. Poly also gains:

- evaluation lemmas (`pevalC`, `pevalD`, `pevalM`, `peval_sum`,
  `peval_prod`, ...); `peval` now sums over `0 <= i < deg p`;
- products of monic linear factors (`mprod`), with their roots and
  degree;
- `PolyField`, polynomials over a field, with Lagrange interpolation
  in `PolyField.Lagrange`.

ZModP gets its field structure from the mixin `ZModpFieldMx` and the
bundle `ZModpFieldBd`, over the one ring `ZModpRing`, instead of a
second clone of `Ring.Field`. `ZModpField` remains as a packed alias,
so qualified names such as `ZModpField.mulrC` still resolve:

    theory ZModpField = ZModpRing + ZModpFieldMx.

This breaks the developments that clone `ZModpField`: an alias cannot
be cloned. They clone the bundle instead, and its ring lemmas are
under `R`:

    clone GP.ZModE.ZModpFieldBd as ZPF.
    ... ZPF.R.mulrC ...

The examples and DHIES are updated accordingly.
@strub
strub force-pushed the feat/comm-algebra branch from 5d9d4c8 to f0fbef8 Compare November 24, 2026 18:57
@strub strub self-assigned this Nov 24, 2026
@strub strub added the yolo-pr Don't bother reviewing, I will merge label Nov 24, 2026
@strub
strub merged commit c421928 into main Nov 24, 2026
20 checks passed
@strub
strub deleted the feat/comm-algebra branch November 24, 2026 20:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

yolo-pr Don't bother reviewing, I will merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant