Skip to content

[Merged by Bors] - chore: use congr() much more widely - #43408

Closed
YaelDillies wants to merge 4 commits into
leanprover-community:masterfrom
YaelDillies:no_congr_arg
Closed

YaelDillies wants to merge 4 commits into
leanprover-community:masterfrom
YaelDillies:no_congr_arg

Conversation

@YaelDillies

@YaelDillies YaelDillies commented Sep 3, 2026 •

Copy link
Copy Markdown
Contributor

Replace most uses of congr_fun, congr_arg, DFunLike.congr_fun, DFunLike.congr_arg, etc... by uses of the congr() elaborator. Some uses were silly and have been replaced by the congr or congr! tactic?

Generated by Claude Opus, painstakingly reviewed and improved line-by-line by myself.

Assisted-by: Claude Opus 5


I know this is a churny PR, but my point is that a new notation (like congr()) will never be used (by humans and LLMs alike) if we don't make such big changes adopting it widely.

Open in Gitpod

@github-actions

github-actions Bot commented Sep 3, 2026 •

Copy link
Copy Markdown

PR summary 318ce8e1c8

Import changes for modified files

No significant changes to the import graph

Import changes for all files
Files Import difference

Declarations diff (regex)

+-+- pow_apply

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 318ce8e).

  • +0 new declarations
  • −0 removed declarations

No declaration differences.


Decrease in strong tech debt: (relative, absolute) = (2.00, 0.00)
Current number Change Type (strong)
418 -2 porting notes
No changes to weak technical debt.

Current commit 318ce8e1c8
Reference commit 159df8fb17

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 tech debt Fixes cross-cutting technical debt, see the "technical debt counters" stream on zulip label Sep 3, 2026
@riccardobrasca

Copy link
Copy Markdown
Member

!radar

@leanprover-radar

leanprover-radar commented Sep 3, 2026 •

Copy link
Copy Markdown

Benchmark results for 03e7e55 against cd67817 are in. There are significant results. @riccardobrasca

  • ✅ build//instructions: -2.2G (-0.00%)

Large changes (2🟥)

  • 🟥 build/module/Mathlib.RingTheory.MvPowerSeries.Expand//instructions: +6.6G (+41.43%)
  • 🟥 build/module/Mathlib.RingTheory.PowerSeries.Expand//instructions: +6.4G (+75.10%)

Medium changes (5✅, 3🟥)

  • 🟥 build/module/Mathlib.AlgebraicGeometry.Modules.Sheaf//instructions: +22.4G (+8.80%)
  • ✅ build/module/Mathlib.AlgebraicGeometry.Sites.Representability//instructions: -2.2G (-11.81%)
  • ✅ build/module/Mathlib.AlgebraicTopology.SimplicialSet.StdSimplexOne//instructions: -3.6G (-36.91%)
  • ✅ build/module/Mathlib.CategoryTheory.Sites.DenseSubsite.Basic//instructions: -3.0G (-8.04%)
  • 🟥 build/module/Mathlib.CategoryTheory.Sites.Descent.DescentDataAsCoalgebra//instructions: +5.4G (+7.46%)
  • 🟥 build/module/Mathlib.Data.List.PeriodicityLemma//instructions: +2.4G (+13.03%)
  • ✅ build/module/Mathlib.LinearAlgebra.QuadraticForm.TensorProduct.Isometries//instructions: -4.7G (-8.66%)
  • ✅ build/module/Mathlib.LinearAlgebra.TensorProduct.Graded.External//instructions: -3.9G (-7.05%)

Small changes (8✅, 8🟥)

  • 🟥 build/module/Mathlib.Algebra.Category.Grp.EpiMono//instructions: +833.8M (+4.10%)
  • ✅ build/module/Mathlib.Algebra.MvPolynomial.Equiv//instructions: -501.6M (-1.04%)
  • ✅ build/module/Mathlib.Algebra.Order.Group.PiLex//instructions: -66.8M (-1.75%)
  • 🟥 build/module/Mathlib.AlgebraicGeometry.IdealSheaf.Subscheme//instructions: +1.6G (+1.97%)
  • 🟥 build/module/Mathlib.AlgebraicGeometry.ProjectiveSpectrum.Functor//instructions: +7.7G (+4.55%)
  • 🟥 build/module/Mathlib.CategoryTheory.Limits.Presheaf//instructions: +1.2G (+2.07%)
  • 🟥 build/module/Mathlib.Geometry.RingedSpace.PresheafedSpace.HasColimits//instructions: +643.2M (+1.83%)
  • 🟥 build/module/Mathlib.Geometry.RingedSpace.PresheafedSpace//instructions: +824.4M (+2.09%)
  • 🟥 build/module/Mathlib.GroupTheory.SchurZassenhaus//instructions: +402.4M (+2.73%)
  • ✅ build/module/Mathlib.LinearAlgebra.BilinearForm.TensorProduct//instructions: -1.5G (-3.46%)
  • ✅ build/module/Mathlib.LinearAlgebra.Dual.Defs//instructions: -1.2G (-4.23%)
  • ✅ build/module/Mathlib.NumberTheory.NumberField.CanonicalEmbedding.PolarCoord//instructions: -667.1M (-2.48%)
  • 🟥 build/module/Mathlib.RingTheory.LaurentSeries//instructions: +3.1G (+3.16%)
  • ✅ build/module/Mathlib.RingTheory.TensorProduct.DirectLimitFG//instructions: -1.3G (-4.14%)
  • ✅ build/module/Mathlib.Topology.Category.CompHausLike.EffectiveEpi//instructions: -697.7M (-12.16%)
  • ✅ build/module/Mathlib.Topology.Homotopy.Lifting//instructions: -1.4G (-2.99%)

@mathlib-merge-conflicts mathlib-merge-conflicts Bot added the merge-conflict The PR has a merge conflict with master, and needs manual merging. (this label is managed by a bot) label Sep 3, 2026
@mathlib-merge-conflicts

Copy link
Copy Markdown

This pull request has conflicts, please merge master and resolve them.

@wwylele

wwylele commented Sep 3, 2026 •

Copy link
Copy Markdown
Collaborator

exact congr(...) and refine congr(...) can be replaced by congrm ... . Shall we also do that?

@github-actions github-actions Bot removed the merge-conflict The PR has a merge conflict with master, and needs manual merging. (this label is managed by a bot) label Sep 4, 2026
@mathlib-merge-conflicts

Copy link
Copy Markdown

This pull request has conflicts, please merge master and resolve them.

@mathlib-merge-conflicts mathlib-merge-conflicts Bot added the merge-conflict The PR has a merge conflict with master, and needs manual merging. (this label is managed by a bot) label Sep 4, 2026
@YaelDillies YaelDillies added the LLM-generated PRs with substantial input from LLMs - review accordingly label Sep 5, 2026
@github-actions github-actions Bot removed the merge-conflict The PR has a merge conflict with master, and needs manual merging. (this label is managed by a bot) label Sep 7, 2026
@mathlib-merge-conflicts mathlib-merge-conflicts Bot added the merge-conflict The PR has a merge conflict with master, and needs manual merging. (this label is managed by a bot) label Sep 11, 2026
@mathlib-merge-conflicts

Copy link
Copy Markdown

This pull request has conflicts, please merge master and resolve them.

@github-actions github-actions Bot removed the merge-conflict The PR has a merge conflict with master, and needs manual merging. (this label is managed by a bot) label Sep 14, 2026
@riccardobrasca

Copy link
Copy Markdown
Member

!radar

@leanprover-radar

leanprover-radar commented Sep 14, 2026 •

Copy link
Copy Markdown

Benchmark results for 2639c0b against cf6bde1 are in. There are significant results. @riccardobrasca

  • 🟥 build//instructions: +14.2G (+0.01%)

Large changes (2🟥)

  • 🟥 build/module/Mathlib.RingTheory.MvPowerSeries.Expand//instructions: +6.6G (+41.99%)
  • 🟥 build/module/Mathlib.RingTheory.PowerSeries.Expand//instructions: +6.4G (+75.23%)

Medium changes (6✅, 3🟥)

  • 🟥 build/module/Mathlib.AlgebraicGeometry.Modules.Sheaf//instructions: +22.1G (+8.73%)
  • ✅ build/module/Mathlib.AlgebraicGeometry.Sites.Representability//instructions: -2.2G (-11.84%)
  • ✅ build/module/Mathlib.AlgebraicTopology.SimplicialSet.StdSimplexOne//instructions: -3.5G (-36.77%)
  • ✅ build/module/Mathlib.CategoryTheory.Sites.DenseSubsite.Basic//instructions: -3.0G (-8.13%)
  • 🟥 build/module/Mathlib.CategoryTheory.Sites.Descent.DescentDataAsCoalgebra//instructions: +5.4G (+7.52%)
  • 🟥 build/module/Mathlib.Data.List.PeriodicityLemma//instructions: +2.5G (+13.57%)
  • ✅ build/module/Mathlib.LinearAlgebra.QuadraticForm.TensorProduct.Isometries//instructions: -4.7G (-8.65%)
  • ✅ build/module/Mathlib.LinearAlgebra.TensorProduct.Graded.External//instructions: -3.9G (-7.12%)
  • ✅ build/module/Mathlib.RingTheory.TensorProduct.DirectLimitFG//instructions: -1.3G (-4.24%)

Small changes (11✅, 6🟥)

  • 🟥 build/module/Mathlib.Algebra.Category.Grp.EpiMono//instructions: +809.4M (+4.04%)
  • 🟥 build/module/Mathlib.AlgebraicGeometry.ProjectiveSpectrum.Functor//instructions: +7.9G (+4.72%)
  • 🟥 build/module/Mathlib.Geometry.RingedSpace.PresheafedSpace.HasColimits//instructions: +652.0M (+1.86%)
  • 🟥 build/module/Mathlib.Geometry.RingedSpace.PresheafedSpace//instructions: +645.2M (+1.64%)
  • 🟥 build/module/Mathlib.GroupTheory.SchurZassenhaus//instructions: +407.6M (+2.80%)
  • ✅ build/module/Mathlib.LinearAlgebra.Basis.Exact//instructions: -162.1M (-1.52%)
  • ✅ build/module/Mathlib.LinearAlgebra.BilinearForm.TensorProduct//instructions: -1.4G (-3.41%)
  • ✅ build/module/Mathlib.LinearAlgebra.Dual.Defs//instructions: -1.3G (-4.34%)
  • ✅ build/module/Mathlib.NumberTheory.NumberField.CanonicalEmbedding.PolarCoord//instructions: -660.9M (-2.49%)
  • ✅ build/module/Mathlib.Order.KonigLemma//instructions: -215.0M (-2.76%)
  • ✅ build/module/Mathlib.RingTheory.Flat.EquationalCriterion//instructions: -358.8M (-1.55%)
  • ✅ build/module/Mathlib.RingTheory.Idempotents//instructions: -376.7M (-1.09%)
  • 🟥 build/module/Mathlib.RingTheory.LaurentSeries//instructions: +3.1G (+3.16%)
  • ✅ build/module/Mathlib.Topology.Category.CompHausLike.EffectiveEpi//instructions: -690.4M (-12.09%)
  • ✅ build/module/Mathlib.Topology.ContinuousMap.Bounded.ArzelaAscoli//instructions: -273.8M (-3.65%)
  • ✅ build/module/Mathlib.Topology.Homotopy.Lifting//instructions: -1.3G (-2.84%)
  • ✅ build/module/Mathlib.Topology.TietzeExtension//instructions: -633.9M (-3.04%)

@SnirBroshi

Copy link
Copy Markdown
Collaborator

Some of these seem really nice, such as

  • Unnecessary \cdot: congrArg (a * ·) h → congr(a * $h)
  • Unnecessary lambda: congrArg (fun x ↦ a * x) h → congr(a * $h)
  • Dot-notation wins: congrArg Subtype.val h → congr(($h).val)

But some of these are of the form congrArg f <| ... → congr(f $(...)) which seem like they were better before, where we avoided lots of parens, but instead we've gained 1 or 2 new pairs of parens here, obscuring the expression.

For example congr_arg Int.cast (Int.natAbs_of_nonneg num_pos.le).symm seems better than
congr(Int.cast $((Int.natAbs_of_nonneg num_pos.le).symm))

There are also some congrArg f h → congr(f $h), but these seem okay I think. Although I don't see the gain.

Wdyt?

@YaelDillies

YaelDillies commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor Author

Some of these seem really nice [...]

Do you want me to remove the not-really-nice ones for now and put them in a separate PR?

For example congr_arg Int.cast (Int.natAbs_of_nonneg num_pos.le).symm seems better than
congr(Int.cast $((Int.natAbs_of_nonneg num_pos.le).symm))

Do you have another example? Turns out the Int.cast was unnecessary here.

@mathlib-merge-conflicts mathlib-merge-conflicts Bot added the merge-conflict The PR has a merge conflict with master, and needs manual merging. (this label is managed by a bot) label Sep 16, 2026
@mathlib-merge-conflicts

Copy link
Copy Markdown

This pull request has conflicts, please merge master and resolve them.

@SnirBroshi

Copy link
Copy Markdown
Collaborator

Do you have another example? Turns out the Int.cast was unnecessary here.

Not having to specify the cast seems like a win for congr!

It's the usages of congr which only elaborate a single function application, such as:

congr_arg f (tmul_comm R 1 a)             →   congr(f $(tmul_comm R 1 a))
congr_arg op <| comap_op_mul _ _          →   congr(op $(comap_op_mul ..))
congr_arg length hb                       →   congr(length $hb)
congr_arg (φ.hom.app M) (one_smul R x)    →   congr(φ.hom.app M $(one_smul R x))

The last one does remove one set of parentheses which is nice, so we're left with the same amount, but now they're nested.

I also found another nice one, where it's technically a single function application, but congr lets us use syntax:

congr_arg Neg.neg (singleton_sub_eq a r)  →   congr(-$(singleton_sub_eq a r))

Do you want me to remove the not-really-nice ones for now and put them in a separate PR?

I'm on the fence about this opinion, so perhaps we should have a second opinion.

After this PR, would congrArg (etc) be considered deprecated? Should we lint against it?

@YaelDillies

Copy link
Copy Markdown
Contributor Author

After this PR, would congrArg (etc) be considered deprecated? Should we lint against it?

I don't see why we should. It is still useful in very early files before the elaborator is available, and I expect people will naturally migrate to congr() once they see it used in mathlib.

@mathlib-merge-conflicts mathlib-merge-conflicts Bot added merge-conflict The PR has a merge conflict with master, and needs manual merging. (this label is managed by a bot) and removed merge-conflict The PR has a merge conflict with master, and needs manual merging. (this label is managed by a bot) labels Sep 17, 2026
@mathlib-merge-conflicts

Copy link
Copy Markdown

This pull request has conflicts, please merge master and resolve them.

@github-actions github-actions Bot removed the merge-conflict The PR has a merge conflict with master, and needs manual merging. (this label is managed by a bot) label Sep 25, 2026
@riccardobrasca

Copy link
Copy Markdown
Member

Let's merge this, otherwise @YaelDillies has to go through an infinite sequence of conflicts. Thanks!

bors d+

@mathlib-bors

mathlib-bors Bot commented Sep 25, 2026

Copy link
Copy Markdown
Contributor

✌️ YaelDillies can now approve this pull request until 2026-10-09 16:02 UTC (in 2 weeks). To approve and merge, reply with bors r+. More detailed instructions are available here.

⚠️ This delegation only covers changes within Archive/**, Counterexamples/**, docs/**, DownstreamTest/**, Mathlib/**, MathlibTest/**, Wanted/**, widget/**, Archive.lean, Counterexamples.lean, docs.lean, Mathlib.lean, Wanted.lean; an author commit touching anything else will revoke it. Bors also revokes it if a later push changes too many files for it to check the full list — even if it stays within scope.

@mathlib-bors mathlib-bors Bot added the delegated This pull request has been delegated to the PR author (or occasionally another non-maintainer). label Sep 25, 2026
@YaelDillies

Copy link
Copy Markdown
Contributor Author

Thank you!

bors merge

@mathlib-bors mathlib-bors Bot added ready-to-merge This PR has been sent to bors. awaiting-requeue This PR was on the bors queue but came off after a build failure or other issue. labels Sep 25, 2026
@mathlib-bors

mathlib-bors Bot commented Sep 25, 2026

Copy link
Copy Markdown
Contributor

Merge conflict.

Merge or rebase master into this PR and resolve the conflict, then someone with permission can run bors r+ or bors retry.

@mathlib-bors mathlib-bors Bot removed the ready-to-merge This PR has been sent to bors. label Sep 25, 2026
@mathlib-merge-conflicts mathlib-merge-conflicts Bot added the merge-conflict The PR has a merge conflict with master, and needs manual merging. (this label is managed by a bot) label Sep 25, 2026
@mathlib-merge-conflicts

Copy link
Copy Markdown

This pull request has conflicts, please merge master and resolve them.

@YaelDillies

Copy link
Copy Markdown
Contributor Author

bors merge

@mathlib-bors

mathlib-bors Bot commented Sep 26, 2026

Copy link
Copy Markdown
Contributor

👎 Rejected by label

@YaelDillies YaelDillies removed the merge-conflict The PR has a merge conflict with master, and needs manual merging. (this label is managed by a bot) label Sep 26, 2026
@YaelDillies

Copy link
Copy Markdown
Contributor Author

bors merge

@mathlib-bors mathlib-bors Bot added ready-to-merge This PR has been sent to bors. and removed awaiting-requeue This PR was on the bors queue but came off after a build failure or other issue. labels Sep 26, 2026
mathlib-bors Bot pushed a commit that referenced this pull request Sep 26, 2026
Replace most uses of `congr_fun`, `congr_arg`, `DFunLike.congr_fun`, `DFunLike.congr_arg`, etc... by uses of the `congr()` elaborator. Some uses were silly and have been replaced by the `congr` or `congr!` tactic?

Generated by Claude Opus, painstakingly reviewed and improved line-by-line by myself.

Assisted-by: Claude Opus 5
@mathlib-bors mathlib-bors Bot added the bors-staging This PR is currently being built by bors on the staging branch. label Sep 26, 2026
@mathlib-bors

mathlib-bors Bot commented Sep 26, 2026

Copy link
Copy Markdown
Contributor

@mathlib-bors mathlib-bors Bot changed the title chore: use congr() much more widely [Merged by Bors] - chore: use congr() much more widely Sep 26, 2026
@mathlib-bors mathlib-bors Bot closed this Sep 26, 2026
@mathlib-bors mathlib-bors Bot removed the delegated This pull request has been delegated to the PR author (or occasionally another non-maintainer). label Sep 26, 2026
@YaelDillies
YaelDillies deleted the no_congr_arg branch September 26, 2026 13:15
ocfnash added a commit to ocfnash/mathlib4 that referenced this pull request Dec 2, 2026
- Regenerate `VecNotation.lean` as a pure move from `master`'s `Notation.lean`, restoring
  upstream changes that had been reverted (leanprover-community#44933, leanprover-community#43918, leanprover-community#44513, leanprover-community#43408, leanprover-community#42318); in
  particular `cons_transpose`, `head_transpose` and `tail_transpose` are no longer simp.
- Fix the `!![...]` delaborator for literals with more than 32 entries, whose list literals
  contain `let`s and are too deep to delaborate as `#[...]`: delaborate entries one at a
  time. Move `listLitElems?` to `Notation/Basic.lean` and reuse it in the tactic parser.
  Add a 6x6 delaborator test.
- Remove `@[simp]` from `transposeArray_size` and `submatrixArray_size` (simpNF).
- Drop `@[expose]` from `Notation.lean` and `Notation/Basic.lean`.
- Add the new modules to `Mathlib.lean`.
- Nits: avoid shadowing in `List.tendsto_getD`, split tactic one-liners, merge `simp` calls
  in `CanonicalEmbedding/Basic.lean`, simplify the `Modular.lean` literal products, and
  replace `simp? says` with `simp` in `MathlibTest/matrix.lean`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bors-staging This PR is currently being built by bors on the staging branch. LLM-generated PRs with substantial input from LLMs - review accordingly ready-to-merge This PR has been sent to bors. 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.

5 participants