Lectures onType Theory
Chapter 97
Chapter 97Optional

The lambda-Pi-Calculus Modulo Rewriting

Prerequisites. Direct starred prerequisites: none. No later core chapter depends on this route.

A logical framework can represent an object theory while failing to compute with it. If natural-number addition is encoded by a constant, the term plus(sz)(sz) is stuck until a proof explicitly rewrites it. The λΠ-calculus modulo rewriting instead admits selected equations as part of conversion. This makes an encoded theory calculate, but it transfers a proof obligation to the signature: an ill-typed, nonconfluent, or nonterminating rule set can destroy the kernel properties on which checking depends.

The obstruction is therefore not the absence of computation but the absence of a disciplined boundary around computation. A typed rewrite signature supplies that boundary: its rules preserve classifiers, its overlaps are joinable, and its reduction relation terminates whenever conversion is to be decided by normal forms.

A typed rewrite signature

Definition 97.1 — Raw terms and signatures

Terms are t,u,A,B::=xcTypex:ABλx:A.ttu. A global signature Σ is an ordered list of constant declarations c:A and rewrite rules r. A local context Γ is an ordered list of variable declarations. Constants declared later may use earlier constants but not conversely.

The core typing rules are

x:AΓ
Σ;Γx:A
Mod-Var
c:AΣ
Σ;Γc:A
Mod-Const
Σ;Γ ctx
Σ;ΓType:Kind
Mod-Type
Σ;ΓA:TypeΣ;Γ,x:AB:s
Σ;Γx:AB:s
Mod-Pi
Σ;ΓA:TypeΣ;Γ,x:At:BBKind
Σ;Γλx:A.t:x:AB
Mod-Lam
Σ;Γf:x:ABΣ;Γu:A
Σ;Γfu:B[u/x]
Mod-App

where s{Type,Kind}. The product rule therefore forms both ordinary dependent functions and kind-level families such as propType. The symbol Kind itself receives no type, which is why Mod-Lam excludes B=Kind. Conversion is

Σ;Γt:AAβΣBΣ;ΓB:s
Σ;Γt:B
Mod-Conv

The relation βΣ is the compatible, reflexive, symmetric, transitive closure of beta reduction and the user rules in Σ. It is a judgment of the framework, not an object-level equality type.

For a first derivation, assume Nat:Type,z:Nat,s:NatNat,plus:NatNatNat. Rule Mod-Const types plus, Mod-App twice types pluszn, and Mod-Var supplies the final argument. Rule Mod-Pi forms the arrow types, while Mod-Lam types the beta redex (λx:Nat.x)n. Thus every rule on the card has a concrete use before rewrite rules enter the signature.

Definition 97.2 — Algebraic rule card

A rule r is admitted to the local algebraic fragment when there are a telescope Δ and a type T such that FV()=dom(Δ),Σ;Δ:T,Σ;Δr:T. The head of is a constant, contains no lambda abstraction, no variable from Δ occurs in function position, and each variable of Δ occurs exactly once in . The last two conditions are algebraicity and left-linearity, respectively. Raw reduction is independent of typing:

rΣθ:dom(Δ)Term
C[θ]ΣC[rθ]
Mod-Rewrite
C[(λx:A.t)u]βC[t[u/x]]
Mod-Beta

Here C[] is a capture-avoiding one-hole raw-term context and θ is an arbitrary capture-avoiding raw substitution. Write βΣ for βΣ. Typing constrains these raw steps only in the preservation theorem.

Add the two rules plusznn,plus(sm)ns(plusmn). The first telescope is n:Nat; the second is m:Nat,n:Nat. Both sides of each rule have type Nat. The two roots are disjoint and left-linear. The calculation plus(sz)(sz)Σs(plusz(sz))Σs(sz) uses Mod-Rewrite twice. By contrast, plusxn is stuck when x is neutral: neither left-hand side matches. Rule Mod-Beta separately contracts (λx:Nat.sx)z to sz.

Substitution and preservation

Lemma 97.3 — Typed substitution

If Σ;Γ,x:A,Δt:T and Σ;Γu:A, then Σ;Γ,Δ[u/x]t[u/x]:T[u/x].

Proof of Lemma 97.3 — Typed substitution

Proof. Induct on the typing derivation. The variable case is the supplied judgment when the variable is x, and otherwise follows from the correspondingly substituted declaration. Constants and sorts are unchanged. For Mod-Pi and Mod-Lam, alpha-rename the bound variable away from FV(u), apply the induction hypothesis to the domain and body premises, and rebuild the same rule. The Mod-App case uses (B[v/y])[u/x]=B[u/x][v[u/x]/y], the capture-avoiding substitution-composition equation. In the Mod-Conv case, compatibility of βΣ with substitution transports AβΣB to A[u/x]βΣB[u/x], after which Mod-Conv rebuilds the conclusion. ◻

Lemma 97.4 — A typed rule remains typed after matching

Under definition 97.2, write θ:ΔΓ when every declaration in Δ is sent to a term of its successively substituted type in Γ. If θ:ΔΓ, then Σ;Γθ:TθandΣ;Γrθ:Tθ.

Proof of Lemma 97.4 — A typed rule remains typed after matching

Proof. Apply lemma 97.3 once for each declaration in the telescope Δ, from left to right. Dependency forces this order: a later component of θ is checked only after the earlier components have been substituted into its type. ◻

Theorem 97.5 — Subject reduction for the algebraic fragment

Let Σ be a well-formed global context in Saillard’s sense: every rewrite declaration is permanently well typed in product-compatible well-formed extensions. Assume product compatibility: x:A1B1βΣx:A2B2A1βΣA2 and B1βΣB2. If Σ;Γt:A and tβΣt, then Σ;Γt:A.

Proof of Theorem 97.5 — Subject reduction for the algebraic fragment

Proof. This is Saillard’s Subject Reduction Theorem 2.1 at the raw relation βΣ [Sai15]. Its induction is on the raw reduction derivation. Product compatibility supplies beta preservation under binders, and permanent well-typedness supplies user-rule preservation in every enclosing declaration context. Lemma 97.3, Lemma 97.4 are the corresponding local substitution mechanisms; they do not replace the permanent-extension hypothesis. ◻

The product-compatibility premise is not decoration. Without injectivity of dependent products modulo conversion, inversion of application does not identify the argument domain required by the lambda body. Likewise, well-typedness of a rule only in its declaration context is insufficient when later declarations can change conversion; Saillard therefore uses permanent well-typedness over well-formed extensions.

Confluence is not an algorithm

Theorem 97.6 — The conditional metatheorem chain

For a well-formed global context in Saillard’s calculus:

  1. confluence of the combined beta-and-rule relation implies product compatibility;

  2. product compatibility and permanently well-typed rules imply subject reduction and uniqueness of types modulo βΣ;

  3. if βΣ is confluent and terminating and the finite set of one-step reducts of each term is computable, conversion is decidable by comparing normal forms.

None of the first two items implies the termination premise of the third.

Proof of Theorem 97.6 — The conditional metatheorem chain

Proof. For (1), reduce convertible products to a common reduct. A product at the head cannot be erased by an algebraic root; comparing the common product gives convertible domains and codomains. Item (2) is theorem 97.5 plus induction on two typing derivations: after conversion is pushed to their leaves, product compatibility makes the function domains agree. For (3), termination produces a normal form, confluence makes it unique up to alpha-equivalence, and computable finite branching makes normalization effective. Conversely, a confluent relation may admit an infinite reduction path, so confluence alone supplies no normalizer. Items (1) and (2) are Saillard’s Theorems 2.3 and 2.1–2.2; item (3) is the effective normal-form corollary, whose extra hypotheses are stated here explicitly [Sai15]. ◻

For the addition rules, the number of leading successors in the first argument decreases at the recursive root, so the user-rule relation Σ terminates. The rules are left-linear and have no critical pair, so that relation is confluent. Saillard’s imported Theorem 2.4 states that a left-algebraic, left-linear, confluent user relation makes the combined beta-and-user relation confluent [Sai15]. It does not transfer termination: no termination proof for βΣ has been supplied here, so the normal-form decision procedure in item (3) is not discharged for this signature.

Left-hand lambdas require rewriting modulo beta

Ordinary matching treats beta-equivalent left sides as different syntax. A rule headed by a pattern containing an abstraction can therefore overlap with beta reduction even when its intended higher-order pattern is unambiguous. Writing the combined relation merely as βΣ hides that overlap.

Definition 97.7 — Saillard's modulo-beta step

Translate a λΠ-pattern and its candidate instance to Nipkow’s higher-order rewrite-system representation. Define tΣbu when the translations make one higher-order rewrite step at base term type. For a source rule r, the three admissibility conditions are: is a lambda-Pi pattern; FV(r)FV(); and every free variable in and r is applied to the same number of arguments. In particular, each pattern-variable occurrence is applied only to distinct bound variables. This is not matching after arbitrary beta normalization; the HRS translation fixes the binding discipline and the substitution recovered from a match.

Theorem 97.8 — Modulo-beta boundary

For a well-formed global context of lambda-Pi patterns:

  1. Σb preserves typing;

  2. the union βΣb generates the same congruence βΣ;

  3. confluence of the translated HRS implies product compatibility;

  4. the paper’s pattern-typing hypotheses make an added rule permanently well typed.

Consequently subject reduction and uniqueness of types follow under those combined hypotheses. No claim is made for an arbitrary higher-order left-hand side.

Proof of Theorem 97.8 — Modulo-beta boundary

Proof. Item (1) is Saillard’s Theorem 6.1: the HRS step factors into beta expansions, one typed rule instance, and beta contractions, with a well-typed intermediate chosen for a well-typed source. Lemma 6.1 defines the combined relation used in item (2), and Theorem 6.2 proves that it generates βΣ. Confluence then gives product compatibility by Theorem 6.3, and the lambda-Pi-pattern criterion is Theorem 6.4 [Sai15]. Combining these results with theorem 97.6 gives the conclusion. The proof does not replace HRS confluence by ordinary union confluence. ◻

An implicational encoding

Let the signature contain prop:Type,prf:propType,imp:proppropprop and the rule (Imp)prf(imp A B)prf(A)prf(B). The rule is typed in A:prop,B:prop. A natural- deduction introduction Γ,ABΓAB is represented by lambda abstraction. If p:prf(A)t:prf(B), then Mod-Lam gives λp:prf(A).t:prf(A)prf(B), and Mod-Conv with (Imp) gives it type prf(imp A B). Elimination is ordinary Mod-App. A neutral proof variable remains stuck; only an application of an introduced implication produces a beta redex.

Theorem 97.9 — Adequacy for normal implicational derivations

Let Ξ=A1:prop,,Am:prop declare the propositional atoms, and let Γ=Ξ,p1:prf(H1),,pn:prf(Hn), where every Hi and A is an implicational formula over Ξ. Alpha-equivalence classes of term-level beta-eta-long normal terms Σ;Γt:prf(A), with classifiers normalized by rule (Imp), are in bijection with normal natural-deduction derivations of A from hypotheses H1,,Hn.

Proof of Theorem 97.9 — Adequacy for normal implicational derivations

Proof. Map hypothesis Hi to its proof variable pi, implication introduction to lambda, and implication elimination to application. Rule (Imp) makes the introduction and elimination classifiers definitionally equal to the corresponding function types. Conversely, canonical-form inversion at prf(imp A B) exposes a lambda, while a neutral proof exposes a head assumption followed by applications. Induction on the normal term reconstructs the unique normal derivation. The two maps commute with alpha-renaming; beta-eta-longness removes the administrative redex and eta-short alternatives. The theorem is restricted to this signature and normal forms, so it asserts neither conservativity of every encoding nor normalization of arbitrary rewrite signatures. ◻

A concrete rule-registration boundary

Cockx’s Agda interface accepts a declaration with schema Δ. fp¯:Av. Patterns are unapplied variables or applications of declared symbols to patterns. Registration checks that the pattern binds the variables of Δ, that both sides have the displayed type A, and that the left side is neutral. Non-linear occurrences become equality constraints during matching. These are the source’s concrete syntax and local admissibility checks [Coc20].

In the retained observational-type-theory Agda case, a proved equality is registered so that its left head and argument patterns populate fp¯, its right side populates v, and its equality proof supplies the same-type check. The example then computes coercion equations through the registered rules. Registration establishes scope, typing, and a usable head pattern; it establishes neither confluence nor termination. Those global obligations remain exactly the hypotheses separated in theorem 97.6.

Dedukti and Lambdapi impose their own concrete parser and rule-admissibility contracts [Ded22, Ded25]. Their retained accept/reject tests are implementation evidence, not proofs of confluence, termination, adequacy, or conservativity. The Kappa companion below checks a finite first-order certificate boundary; it does not implement dependent conversion or higher-order matching.

Exercise 97.1

★☆☆ Add a constant double:NatNat with rules at zero and successor. Calculate double(s(sz)) and identify the stuck form at a neutral argument.

Exercise 97.2

★★☆ Prove lemma 97.4 for a two-variable dependent telescope x:A,y:B(x). State the type required of the second substitution component after the first is installed.

Exercise 97.3

★★☆ Add the rule plusmzm. List every root overlap with the two original addition rules and join the resulting critical pairs. Explain why this calculation alone does not prove termination.

Exercise 97.4

★★☆ Give a confluent but nonterminating rewrite relation. Use it to refute the claim that confluence alone yields a normal-form conversion algorithm.

Exercise 97.5

★★★ Carry out both directions of theorem 97.9 for (AB)AB, including the normal-form inversion used in the reverse direction.

None of these problems is a prerequisite for a later chapter.

Suggested first pass.

Begin with exercise 97.1, exercise 97.3; then separate the mathematical conditions in theorem 97.6 before running exercise 97.6.

Exercise 97.6

★★★ Practical project.lambda-pi-modulo-certificate-checker Run the chapter’s Kappa certificate checker. Require acceptance of the orthogonal addition card, rejection of an ill-typed right side, detection of one dishonest certificate containing an unjoinable root overlap at fuel 12, and refusal to advertise decidable conversion when termination is absent. Mutate the overlap traversal to return true without normalization; the named dishonest-certificate oracle must fail. Explain why the finite checker proves none of theorem 97.5, theorem 97.8.

Bibliographic notes

The rule and theorem boundary follows Saillard’s public EPTCS paper [Sai15]; its printed pp. 92 and 98 were inspected directly for Theorems 2.1–2.5 and 6.1–6.4. Blanqui’s course provides the longer implementation sequence [Bla25]. Dedukti and Lambdapi are pinned implementation evidence, not theorem owners. Cockx owns the Agda rule-registration boundary [Coc20]. Rewriting in conversion is not tactic rewriting, a quotient path constructor, or permission to add unchecked recursive equations.

Search the book

Type to search the local edition.