Probe: whether @[gcongr] accepts cross-head realization lemmas #
This file records a design finding for the Trocq proof-transfer combinators:
whether a binary realization/relatedness combinator — whose conclusion relates two
different head symbols, R (op a b) (bop a' b') — can be registered as a
@[gcongr] lemma.
Result #
@[gcongr] accepts only same-head monotonicity lemmas: the conclusion must
have the shape f x₁ … xₙ ∼ f x₁' … xₙ', i.e. the same head function f and
the same arity on both sides of the relation, with the varying arguments related
pairwise by the side goals.
The constraint is enforced in Mathlib.Tactic.GCongr.Core (makeGCongrLemma):
let some (head, lhsArgs) := getCongrAppFnArgs lhs | fail "LHS is not suitable …"
let some (head', rhsArgs) := getCongrAppFnArgs rhs | fail "RHS is not suitable …"
unless head == head' && lhsArgs.size == rhsArgs.size do
fail "LHS and RHS do not have the same head function and arity"
A cross-head lemma is therefore rejected at attribute-application time, with:
@[gcongr] attribute only applies to lemmas proving f x₁ ... xₙ ∼ f x₁' ... xₙ'.
LHS and RHS do not have the same head function and arity in R (op a b) (bop a' b')
Implication for Trocq #
The Trocq combinators relate distinct heads (a source operation and its target
realization), so they cannot be @[gcongr] lemmas. gcongr is the right mental
model — peel a relation by descending into matching argument positions — but it
is not the available hook. A cross-head transfer needs a dedicated congruence
driver (a custom Simp/Tactic extension or an explicit relation-respecting
combinator set), not the @[gcongr] attribute.
Same-head control (accepted, fires) #
Cross-head record (rejected — kept untagged) #
The lemma below is the shape a Trocq binary realization combinator would have:
its conclusion relates two different head symbols (op versus bop) under a
custom relation R. It is deliberately left without @[gcongr], because
tagging it raises the attribute-application error quoted in the module docstring.
The lemma itself is a perfectly valid proposition; only the @[gcongr]
registration is rejected.