mathlib4 review helperopen PRs by @wwylele on leanprover-community/mathlib4

← queue

#46993 feat(Algebra/MvPolynomial): degree of Polynomial.toMvPolynomial

t-algebra CI success

+45 −0 · 2 files · 3 commits · head f7b1152 · updated today · Files changed on GitHub

PR description

AI usage: I used Claude Code to generate about 50% of the proof

Conversation on GitHub 2
wwylele · comment · 2026-12-05

LLM-generated

github-actions[bot] · comment · 2026-12-05
PR summary f7b1152ae6
Import changes for modified files

No significant changes to the import graph

<details><summary>Import changes for all files</summary>

|Files|Import difference| |-|-|

</details>


<details><summary>

Declarations diff (regex)

</summary>

+ Polynomial.degreeOf_toMvPolynomial + Polynomial.degreeOf_toMvPolynomial_of_ne + Polynomial.degrees_toMvPolynomial + Polynomial.toMvPolynomial_eq_rename_optionEquivLeft_symm + Polynomial.totalDegree_toMvPolynomial + degree_mapEquiv + natDegree_mapEquiv <details> <summary>You can run this locally as follows</summary>

## 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>

</details>

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

</details>

Declarations diff (Lean)

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

  • +7 new declarations
  • −0 removed declarations
+Polynomial.degreeOf_toMvPolynomial
+Polynomial.degreeOf_toMvPolynomial_of_ne
+Polynomial.degree_mapEquiv
+Polynomial.degrees_toMvPolynomial
+Polynomial.natDegree_mapEquiv
+Polynomial.toMvPolynomial_eq_rename_optionEquivLeft_symm
+Polynomial.totalDegree_toMvPolynomial

No changes to strong technical debt. No changes to weak technical debt.

Current commit f7b1152ae6 Reference commit c2eaf80729

This script lives in the undefined 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).

Mathlib/Algebra/MvPolynomial/Equiv.lean +38 −0

lemma Polynomial.toMvPolynomial_inj {i : σ} {p q : R[X]} :
859 toMvPolynomial (R := R) i p = toMvPolynomial i q ↔ p = q :=
860 ⟨fun h ↦ Polynomial.toMvPolynomial_injective i h, fun h ↦ by rw [h]⟩
lemma Polynomial.toMvPolynomial_eq_rename_optionEquivLeft_symm newL862–868
862lemma Polynomial.toMvPolynomial_eq_rename_optionEquivLeft_symm (p : R[X]) (i : σ) :
863 p.toMvPolynomial i = ((MvPolynomial.optionEquivLeft R Empty).symm
864 (p.mapEquiv (MvPolynomial.isEmptyAlgEquiv R Empty).symm)).rename fun _ ↦ i := by
865 induction p using Polynomial.induction_on' with
866 | add p q hp hq => simp_all
867 | monomial n a =>
868 simp [MvPolynomial.optionEquivLeft_symm_apply, ← C_mul_X_pow_eq_monomial, toMvPolynomial]
lemma Polynomial.degreeOf_toMvPolynomial newL870–875
870@[simp]
871lemma Polynomial.degreeOf_toMvPolynomial (p : R[X]) (i : σ) :
872 (p.toMvPolynomial i).degreeOf i = p.natDegree := by
873 rw [toMvPolynomial_eq_rename_optionEquivLeft_symm,
874 MvPolynomial.degreeOf_rename_of_injective (Function.injective_of_subsingleton fun _ ↦ i) none,
875 ← MvPolynomial.natDegree_optionEquivLeft, AlgEquiv.apply_symm_apply, natDegree_mapEquiv]
lemma Polynomial.degreeOf_toMvPolynomial_of_ne newL877–883
877@[simp]
878lemma Polynomial.degreeOf_toMvPolynomial_of_ne (p : R[X]) {i j : σ} (h : i ≠ j) :
879 (p.toMvPolynomial i).degreeOf j = 0 := by
880 classical
881 rw [toMvPolynomial_eq_rename_optionEquivLeft_symm, MvPolynomial.degreeOf_def,
882 MvPolynomial.degrees_rename_of_injective (Function.injective_of_subsingleton _)]
883 simp [Multiset.mem_replicate, h.symm]
lemma Polynomial.degrees_toMvPolynomial newL885–891
885@[simp]
886lemma Polynomial.degrees_toMvPolynomial (p : R[X]) (i : σ) :
887 (p.toMvPolynomial i).degrees = .replicate p.natDegree i := by
888 classical
889 ext j
890 rw [← MvPolynomial.degreeOf_def, Multiset.count_replicate]
891 split_ifs with h <;> simp [h]
lemma Polynomial.totalDegree_toMvPolynomial newL893–898
893@[simp]
894lemma Polynomial.totalDegree_toMvPolynomial (p : R[X]) (i : σ) :
895 (p.toMvPolynomial i).totalDegree = p.natDegree := by
896 apply le_antisymm
897 · simpa using (p.toMvPolynomial i).totalDegree_le_degrees_card
898 · simpa using (p.toMvPolynomial i).degreeOf_le_totalDegree i
900@[simp]
901lemma MvPolynomial.eval_comp_toMvPolynomial (f : σ → R) (i : σ) :
902 (eval f).comp (toMvPolynomial (R := R) i) = Polynomial.evalRingHom (f i) := by

Mathlib/Algebra/Polynomial/Eval/Degree.lean +7 −0

lemma degree_map_le : degree (p.map f) ≤ degree p := by
148 rw [degree_lt_iff_coeff_zero] at hm
149 simp [hm m le_rfl]
lemma degree_mapEquiv newL151–153
151lemma degree_mapEquiv (e : R ≃+* S) (p : R[X]) : (p.mapEquiv e).degree = p.degree := by
152 apply le_antisymm degree_map_le
153 simpa [Polynomial.map_map] using degree_map_le (f := e.symm.toRingHom) (p := p.mapEquiv e)
155lemma natDegree_map_le : natDegree (p.map f) ≤ natDegree p := natDegree_le_natDegree degree_map_le
lemma natDegree_mapEquiv newL157–158
157lemma natDegree_mapEquiv (e : R ≃+* S) (p : R[X]) : (p.mapEquiv e).natDegree = p.natDegree :=
158 natDegree_eq_natDegree <| degree_mapEquiv e p
160lemma degree_map_lt (hp : f p.leadingCoeff = 0) (hp₀ : p ≠ 0) : (p.map f).degree < p.degree := by
161 refine degree_map_le.lt_of_ne fun hpq ↦ hp₀ ?_
162 rw [leadingCoeff, ← coeff_map, ← natDegree_eq_natDegree hpq, ← leadingCoeff, leadingCoeff_eq_zero]
0/7 declarations checked

Your review, as Markdown

Paste it as a comment or a review on the PR. Line links to the head commit unfold into code snippets on GitHub.