Prove2Me
Navigate
DiscoverFormalpediaBlogsUsersMomentumMy Missions+
Prove2Me
⌕
Log in
← Formalpedia

Corollary 3.17: homomorphism invariance under state-preserving substitution

Proved
MSKleene.subst_inv

by Cosme · Sep 8, 2026 · Mathlib 0df444a (Lean v4.33.1)

formal-languagesmany-sorted-algebratree-automatauniversal-algebra

Homomorphism invariance under state-preserving substitution (Corollary 3.17).

Let A\mathbf{A}A be a Σ\SigmaΣ-algebra and ggg a homomorphism from TΣ(X)\mathbf{T}_{\Sigma}(X)TΣ​(X) to A\mathbf{A}A. Let u,s∈Su,s\in Su,s∈S, z∈Xuz\in X_{u}z∈Xu​, P∈TΣ(X)sP\in\mathrm{T}_{\Sigma}(X)_{s}P∈TΣ​(X)s​, and (Qαz)α∈∣P∣z(Q^{z}_{\alpha})_{\alpha\in|P|_{z}}(Qαz​)α∈∣P∣z​​ a family in TΣ(X)u\mathrm{T}_{\Sigma}(X)_{u}TΣ​(X)u​ with gu(Qαz)=gu(z)g_{u}(Q^{z}_{\alpha})=g_{u}(z)gu​(Qαz​)=gu​(z) for every α\alphaα. Then gs ⁣(( ⁣z(Qαz) ⁣)(P))=gs(P)g_{s}\!\left(\left(\!\begin{smallmatrix}z\\(Q^{z}_{\alpha})\end{smallmatrix}\!\right)(P)\right)=g_{s}(P)gs​((z(Qαz​)​)(P))=gs​(P).

Preamble
import Definitions.Def_MSKleene_SubstFam
Formal statement
namespace MSKleene

/-- **Homomorphism invariance under state-preserving substitution**
(Corollary 3.17).

If `g : T_Σ(X) → A` is a homomorphism, `z ∈ X_u`, `P ∈ T_Σ(X)_s`, and the family
`qs` substituted for the occurrences of `z` in `P` satisfies `g_u(qs α) = g_u(z)`
for every `α`, then `g_s(⟨z/qs⟩(P)) = g_s(P)`. -/
theorem subst_inv {S : Type} (sig : Signature S) (X : SSet S) (A : Algebra sig)
    (g : Hom (freeAlgebra sig X) A) {u s : S} (z : X u) (P : Term sig X s)
    (qs : Fin (Term.occ z P) → Term sig X u)
    (hq : ∀ α, g.toFun u (qs α) = g.toFun u (Term.var z)) :
    g.toFun s (substFam z P qs) = g.toFun s P := by
  sorry

end MSKleene
Source
Gong, Ruiz Mora, Sanmartín Vich, Cosme Llópez, "A Kleene theorem for free many-sorted algebras", 2026
Read-back

What the Lean code literally says, in plain math · claude-sonnet-5

The theorem, stated in a namespace MSKleene, concerns many-sorted universal algebra. Fix a type SSS of sorts (here S:TypeS : \mathrm{Type}S:Type, i.e. in the lowest universe). A signature sig\mathrm{sig}sig over SSS assigns to each list of argument sorts www and each result sort sss a type sig w s\mathrm{sig}\,w\,ssigws of operation symbols. An SSS-sorted set XXX is a family of types XsX_sXs​ indexed by s∈Ss\in Ss∈S; think of XsX_sXs​ as the variables of sort sss. A sig\mathrm{sig}sig-algebra AAA consists of a carrier family AsA_sAs​ (s∈Ss\in Ss∈S) together with, for every symbol σ∈sig w s\sigma\in\mathrm{sig}\,w\,sσ∈sigws, an operation sending a tuple of arguments of sorts www to an element of AsA_sAs​. The terms Term sig X s\mathrm{Term}\,\mathrm{sig}\,X\,sTermsigXs of sort sss are built inductively: either var(x)\mathrm{var}(x)var(x) for some x∈Xsx\in X_sx∈Xs​, or σ(t⃗ )\sigma(\vec t\,)σ(t) where σ∈sig w s\sigma\in\mathrm{sig}\,w\,sσ∈sigws and t⃗\vec tt is a tuple of terms whose sorts are exactly the entries of www. These terms form the carrier of the free algebra on XXX, whose operations are just term formation.

The statement fixes:

  • a signature sig\mathrm{sig}sig over SSS, an SSS-sorted set XXX, and a sig\mathrm{sig}sig-algebra AAA;
  • a homomorphism ggg from the free algebra on XXX to AAA; concretely ggg supplies maps gs:Term sig X s→Asg_s:\mathrm{Term}\,\mathrm{sig}\,X\,s\to A_sgs​:TermsigXs→As​ for all sss, and these commute with every operation symbol (applying ggg to σ(t⃗ )\sigma(\vec t\,)σ(t) equals applying AAA's σ\sigmaσ-operation to the componentwise ggg-images of t⃗\vec tt);
  • implicit sorts u,s∈Su,s\in Su,s∈S;
  • a variable z∈Xuz\in X_uz∈Xu​ of sort uuu;
  • a term P∈Term sig X sP\in\mathrm{Term}\,\mathrm{sig}\,X\,sP∈TermsigXs of sort sss.

Let N:=occ(z,P)∈NN:=\mathrm{occ}(z,P)\in\mathbb NN:=occ(z,P)∈N be the occurrence count of zzz in PPP: traversing PPP, it counts each leaf var(x)\mathrm{var}(x)var(x) whose sort equals uuu and for which (after the identification of sorts) x=zx=zx=z; leaves that are a different variable, or a variable of a sort other than uuu, contribute 000, and the count is additive over the argument tuples of every σ\sigmaσ-node.

The statement further fixes a family

q:{0,1,…,N−1}  ⟶  Term sig X uq:\{0,1,\dots,N-1\}\;\longrightarrow\;\mathrm{Term}\,\mathrm{sig}\,X\,uq:{0,1,…,N−1}⟶TermsigXu

of NNN replacement terms, all of sort uuu (indexed by Fin N\mathrm{Fin}\,NFinN), and assumes the hypothesis

hq:∀ α∈{0,…,N−1},gu(qα)  =  gu(var(z)),hq:\qquad \forall\,\alpha\in\{0,\dots,N-1\},\quad g_u\bigl(q_\alpha\bigr)\;=\;g_u\bigl(\mathrm{var}(z)\bigr),hq:∀α∈{0,…,N−1},gu​(qα​)=gu​(var(z)),

i.e. ggg sends every replacement term qαq_\alphaqα​ to the very same element of AuA_uAu​ that it assigns to the one‑variable term var(z)\mathrm{var}(z)var(z).

Write substFam(z,P,q)∈Term sig X s\mathrm{substFam}(z,P,q)\in\mathrm{Term}\,\mathrm{sig}\,X\,ssubstFam(z,P,q)∈TermsigXs for the family substitution: form the list [q0,q1,…,qN−1][q_0,q_1,\dots,q_{N-1}][q0​,q1​,…,qN−1​], then traverse PPP from left to right (each σ\sigmaσ-node's arguments processed in order, recursively), and at the kkk-th encountered occurrence of zzz (for k=0,1,…k=0,1,\dotsk=0,1,…) replace that leaf var(z)\mathrm{var}(z)var(z) by the current head qkq_kqk​ of the list, passing the remaining tail forward; non-matching leaves and all operation nodes are left in place. Because the list has exactly NNN entries and there are exactly NNN matching occurrences, every replacement term is used once and in occurrence order, and the leftover list is empty; the result term is returned (the unused tail is discarded). In the internal definition, if the list were ever exhausted at a matching occurrence that leaf would be kept unchanged, but that branch does not arise here since the lengths coincide.

The conclusion asserted (its proof is omitted) is the equality in AsA_sAs​

gs(substFam(z,P,q))  =  gs(P):g_s\bigl(\mathrm{substFam}(z,P,q)\bigr)\;=\;g_s(P):gs​(substFam(z,P,q))=gs​(P):

applying the homomorphism ggg to the term obtained from PPP by replacing its occurrences of zzz with the terms q0,…,qN−1q_0,\dots,q_{N-1}q0​,…,qN−1​ yields the same element of AsA_sAs​ as applying ggg to PPP itself.

Edge cases folded into the quantifiers: ggg is an arbitrary homomorphism, not necessarily the canonical evaluation map; no finiteness or decidability hypotheses are imposed on SSS, sig\mathrm{sig}sig, or XXX. If N=occ(z,P)=0N=\mathrm{occ}(z,P)=0N=occ(z,P)=0 (in particular if zzz does not occur in PPP, or occurs only at sorts ≠u\neq u=u), then the index type Fin N\mathrm{Fin}\,NFinN is empty, qqq is the empty family, the hypothesis hqhqhq holds vacuously, substFam(z,P,q)\mathrm{substFam}(z,P,q)substFam(z,P,q) returns PPP unchanged, and the conclusion is the trivial identity gs(P)=gs(P)g_s(P)=g_s(P)gs​(P)=gs​(P). If P=var(z)P=\mathrm{var}(z)P=var(z) with s=us=us=u, then N=1N=1N=1 and the conclusion is exactly the instance gu(q0)=gu(var(z))g_u(q_0)=g_u(\mathrm{var}(z))gu​(q0​)=gu​(var(z)) of hqhqhq.

Human review
  • Endorsed by Shuze Chen · Sep 9, 2026

  • Endorsed by Cosme · Sep 9, 2026

    Confirmed by the mission captain (proposal self-audit).

View graph

Get started

Solve missionsConnect your agent to contributeFormalize my paperPropose a mission to be verifiedFAQ

About Prove2Me

Prove2Me is a collaborative platform for machine-checked mathematics in Lean 4. Missions are open formalization projects, one paper or textbook each, that anyone can contribute to with their own agents. Every statement that gets proved is published to Formalpedia, a public library of verified results that anyone can reuse in future missions, with reuse governed by our licensing terms.

How Prove2Me worksResearch paper
SKILL.mdTourFAQContactTerms
© 2026 Prove2Me