Commit 2025-07-31 09:17 8495a95a
View on Github →feat(gcongr): also use more general lemmas, closing extra goals with rfl (#26907)
This PR fixes an annoyance in tagging gcongr lemmas: if your function has n arguments in which to use congruence, then you would need to provide 2^n-1 gcongr lemmas. Now, it suffices to only tag the most general gcongr lemma, and in more specific cases, the extra goals will be closed using rfl.
While working on this, more issues with gcongr came up, and these all needed to be dealt with in the same PR:
- When applying a
gcongrlemma, this should be done in thereducibletransparency. The transparency was already bumped formdefaulttoinstancesafter a zulip discussion (#mathlib4 > gcongr unfold DFunLike.coe). But I found that the same issue appears atinstancestransparency instead ofreducible. MWE:
import Mathlib
open MeasureTheory
variable {α : Type*} (a : Set α) {μ : OuterMeasure α} {μ' : OuterMeasure α}
@[gcongr] -- remove this tag to make the last example work
lemma mono_outerMeasure (h : μ ≤ μ') : μ a ≤ μ' a := h a
example (h : μ ≤ μ') : μ a ≤ μ' a := by gcongr
variable [MeasurableSpace α] {ν : Measure α} {ν' : Measure α}
@[gcongr]
lemma mono_measure (h : ν ≤ ν') : ν a ≤ ν' a := h a
example (h : ν ≤ ν') : ν a ≤ ν' a := by
with_reducible apply mono_outerMeasure
set_option trace.Meta.isDefEq true in
with_reducible gcongr
This aligns with the congr! tactic
- Using
reducibletransparency is not compatible with the approach of matchingvaryingArgs, because when comparing instance arguments, we need to use at leastinstancestransparency. So, instead of storing the lemmas byvaryingArgs, we sort them by the number of varying arguments, and simply try applying all the lemmas (which should be cheap inreducibletransparency). This aligns withcongr/congr!(/simp) which also tries all of the lemmas for the given constant. - As a result of sorting the lemmas in the same way as
congrlemmas, more recently added lemmas are now tried before older ones. This causes an issue which has to be solved by implementing a priority argument for thegcongrtag (similar to howinstanceandsimpwork), e.g.@[gcongr high]. This aligns with the@[congr]tag.