Skip to content

feat(FieldTheory/SplittingField/Construction): don't expose SplittingField and fix diamonds - #46811

Open
JovanGerb wants to merge 1 commit into
leanprover-community:masterfrom
JovanGerb:Jovan-SplittingField-private-2
Open

JovanGerb wants to merge 1 commit into
leanprover-community:masterfrom
JovanGerb:Jovan-SplittingField-private-2

Conversation

@JovanGerb

Copy link
Copy Markdown
Contributor

This PR makes Polynomial.SplittingField unexposed, so that later modules cannot unfold it. This requires carefully constructing the instances on it such that there are no instance diamonds. The test file that we have for this shows that after this PR there are no such instance diamonds anymore. In particular, there were still diamonds around the NatCast and IntCast instances that this PR fixes.

I previously attempted this change at #37854 but that failed. Since then, I have added the NSMul and ZSMul type classes, and inferInstanceAs has improved, making this new PR possible.

There is still a slight limitation in inferInstanceAs that the expression passed to it needs to be public, so this PR leaves SplittingFieldAux as public.

#37474 was another attempt at the same refactor.

A similar refactor could probably be done for AlgebraicClosure.


This PR was made with help from @roy7 and their AIs.


@github-actions github-actions Bot added the tech debt Fixes cross-cutting technical debt, see the "technical debt counters" stream on zulip label Dec 1, 2026
@github-actions

github-actions Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

PR summary 831580749d

Import changes for modified files

No significant changes to the import graph

Import changes for all files
Files Import difference

Declarations diff (regex)

+ coe
+ coeHom
+ instance (f : K[X]) : IsSplittingField K (SplittingField f) f
+ instance (p : ℕ) [CharP K p] : CharP (SplittingField f) p
+ instance (p : ℕ) [ExpChar K p] : ExpChar (SplittingField f) p
+ instance : CommRing (SplittingField f)
+ instance : Field (SplittingField f)
+ instance : GroupWithZero (SplittingField f)
+ instance : IntCast (SplittingField f)
+ instance : Inv (SplittingField f)
+ instance : NatCast (SplittingField f)
+ instance [CharZero K] : CharZero (SplittingField f)
+ instance {R : Type*} [CommSemiring R] [Algebra R K] :
- instCharP
- instCharZero
- instExpChar
- instField
- instGroupWithZero
- instance : CommRing (SplittingField f) := inferInstanceAs <| CommRing (_ ⧸ _)
- instance _root_.Polynomial.IsSplittingField.splittingField (f : K[X]) :

You can run this locally as follows
## from your `mathlib4` directory:
git clone https://github.com/leanprover-community/mathlib-ci.git ../mathlib-ci

## summary with just the declaration names:
../mathlib-ci/scripts/pr_summary/declarations_diff.sh <optional_commit>

## more verbose report:
../mathlib-ci/scripts/pr_summary/declarations_diff.sh long <optional_commit>

The doc-module for scripts/pr_summary/declarations_diff.sh in the mathlib-ci repository contains some details about this script.

Declarations diff (Lean)

✅ Lean-aware diff — post-build, computed from the Lean environment (commit 8315807).

  • +6 new declarations
  • −26 removed declarations
-Polynomial.IsSplittingField.splittingField
-Polynomial.SplittingField.algEquivSplittingFieldAux
+Polynomial.SplittingField.coe
+Polynomial.SplittingField.coeHom
+Polynomial.SplittingField.instIntCast
+Polynomial.SplittingField.instInv
+Polynomial.SplittingField.instIsSplittingField
+Polynomial.SplittingField.instNatCast
-Polynomial.SplittingFieldAux.adjoin_rootSet
-Polynomial.SplittingFieldAux.algebra
-Polynomial.SplittingFieldAux.algebra'
-Polynomial.SplittingFieldAux.algebra''
-Polynomial.SplittingFieldAux.algebra'''
-Polynomial.SplittingFieldAux.algebraMap_succ
-Polynomial.SplittingFieldAux.field
-Polynomial.SplittingFieldAux.instIsSplittingFieldNatDegree
-Polynomial.SplittingFieldAux.scalar_tower'
-Polynomial.SplittingFieldAux.splits
-Polynomial.SplittingFieldAux.succ
-Polynomial.SplittingFieldAuxAux
-Polynomial.X_sub_C_mul_removeFactor
-Polynomial.fact_irreducible_factor
-Polynomial.factor
-Polynomial.factor_dvd_of_degree_ne_zero
-Polynomial.factor_dvd_of_natDegree_ne_zero
-Polynomial.factor_dvd_of_not_isUnit
-Polynomial.instInhabitedSplittingFieldAux
-Polynomial.irreducible_factor
-Polynomial.isCoprime_iff_aeval_ne_zero
-Polynomial.natDegree_removeFactor
-Polynomial.natDegree_removeFactor'
-Polynomial.removeFactor

No changes to strong technical debt.

Decrease in weak tech debt: (relative, absolute) = (1.00, 0.00)
Current number Change Type (weak)
5160 -1 exposed public sections

Current commit 831580749d
Reference commit 55f142d243

This script lives in the mathlib-ci repository. To run it locally, from your mathlib4 directory:

git clone https://github.com/leanprover-community/mathlib-ci.git ../mathlib-ci
../mathlib-ci/scripts/reporting/technical-debt-metrics.py pr_summary
  • The relative value is the weighted sum of the differences with weight given by the inverse of the current value of the statistic.
  • The absolute value is the relative value divided by the total sum of the inverses of the current values (i.e. the weighted average of the differences).

@github-actions github-actions Bot added the t-algebra Algebra (groups, rings, fields, etc) label Dec 1, 2026
@roy7

roy7 commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

@plp127 I saw you ask about two prior similar PRs. If you need this functionality, please try this PR out?

@JovanGerb

Copy link
Copy Markdown
Contributor Author

!radar

@leanprover-radar

leanprover-radar commented Dec 2, 2026 •

Copy link
Copy Markdown

Benchmark results for 8315807 against 55f142d are in. No significant results found. @JovanGerb

  • ✅ build//instructions: -889.2M (-0.00%)

Small changes (13✅, 4🟥)

  • 17 hidden

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

t-algebra Algebra (groups, rings, fields, etc) tech debt Fixes cross-cutting technical debt, see the "technical debt counters" stream on zulip

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants