Lectures onType Theory
Chapter 96
Chapter 96Optional

CDLE and Cedille: Lambda-Encoded Induction, Recursion, and Zero-Cost Reuse

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

The Church numeral n is an iterator: n:X:.X(XX)X. It can compute n applications of a step, but its result type cannot state a property of the numeral n itself. Replacing X by a motive P:Nat is ill typed: X has kind , while P has kind Nat. The missing information is not another iterator but evidence that the same erased numeral satisfies its own induction principle.

The Cedille Core contract

Convention 96.1 — Frozen later CDLE

The working calculus is the Cedille Core of Stump and Jenkins, not the earlier 2017 lifting calculus. It is an extrinsic Calculus of Constructions with retained products Πx:T.T, erased products x:T.T and X:κ.T, dependent intersections, untyped equality {tt}, type ascription, equality rewriting, direct computation, and the separation axiom δ. It has one kind of types and dependent kind products. Conversion of types uses call-by-name weak-head reduction followed by beta conversion of types and beta-eta conversion of erased terms. The semantic metatheorems below apply to this exact core.

The annotated terms and their erasures are t::=xλx.ttuΛX.ttTΛx.ttu[t,u]t.1t.2β{u}δtρp @xu.Ttϕpt{u}χTt, with erase(ΛX.t)=erase(t),erase(tT)=erase(t),erase(Λx.t)=erase(t),erase(tu)=erase(t),erase([t,u])=erase(t),erase(t.1)=erase(t.2)=erase(t),erase(β{u})=erase(u),erase(δt)=λx.x,erase(ρp @xu.Tt)=erase(t),erase(ϕpt{u})=erase(u),erase(χTt)=erase(t). Here tu is application to an erased term argument; it is not subtraction. The two terms on either side of need only have their free variables declared; equality is heterogeneous and untyped.

Definition 96.2 — Core type formation

The type formers used in the chapter have the following formation rules:

ΓTΓ,x:TT
ΓΠx:T.T
CDLE-Π-F
ΓTΓ,x:TT
Γx:T.T
CDLE–F
ΓTΓ,x:TT
Γιx:T.T
CDLE-Isect-F
FV(t,t)dom(Γ)
Γ{tt}
CDLE-Eq-F

Type and kind quantification has the corresponding rule Γ,X:κT over a well-formed κ.

The retained and erased functions differ at runtime. Their rules are given in formation, introduction, elimination, and computation order.

TcbnΠx:T1.T2Γ,x:T1tT2
Γλx.tT
CDLE-Π-I
ΓfΠx:T1.T2ΓuT1
ΓfuT2[u/x]
CDLE-Π-E
(λx.t)ut[u/x]
CDLE-Π-β
Tcbnx:T1.T2Γ,x:T1tT2xFV(erase(t))
ΓΛx.tT
CDLE–I
Γfx:T1.T2ΓuT1
ΓfuT2[u/x]
CDLE–E
erase((Λx.t)u)=erase(t)
CDLE–β

Dependent intersections repeat the same-erasure condition of chapter 37 in bidirectional form.

Tcbnιx:T1.T2Γt1T1Γt2T2[t1/x]erase(t1)=βηerase(t2)
Γ[t1,t2]T
CDLE-Isect-I
Γtιx:T.T
Γt.1T
CDLE-Isect-E_1
Γtιx:T.T
Γt.2T[t.1/x]
CDLE-Isect-E_2
erase([t1,t2].1)=erase(t1)=βηerase(t2)=erase([t1,t2].2)
CDLE-Isect-β

Definition 96.3 — Equality and direct computation

The equality introduction, rewrite, direct-computation, separation, and ascription rules are

Tcbn{t1t2}FV(u)dom(Γ)erase(t1)=βηerase(t2)
Γβ{u}T
CDLE-Eq-I
Γp{t1t2}erase(t2)=βηerase(t2)ΓT[t2/x]ΓuT[t2/x]T[t1/x]T
Γρp @xt2.TuT
CDLE-Eq-E
Γp{tu}ΓtTFV(u)dom(Γ)
Γϕpt{u}T
CDLE-φ
Γp{λx.λy.xλx.λy.y}
ΓδpT
CDLE-δ
ΓTΓtT
ΓχTtT
CDLE-Ascribe

The proof β{u} may erase to an unrelated term u. This Kleene trick classifies every closed untyped term at a true equality type. Rule CDLE-ϕ instead changes the erased program to u after an equality proof. Neither rule is an MLTT identity eliminator.

For a neutral intersection variable n, the projections n.1 and n.2 do not reduce. Both erase to n, and their types provide the two views needed below.

Inductive naturals as an intersection

Put NatC:=X:.X(XX)X,zeroC:=ΛX.λz.λs.z,sucC(n):=ΛX.λz.λs.s(nXzs). The type NatC supports iteration. It does not derive, for an arbitrary P:NatC, a term of P(n) from a base and step; the iterator quantifies over a single result type X. This nonderivability in second-order dependent type theory is the obstruction, not a missing clever choice of X.

Define the inductivity predicate IndNat(n):=P:NatC. P(zeroC)(m:NatC.P(m)P(sucC(m)))P(n). and the inductive type Nat:=ιn:NatC.IndNat(n).

The zero inductivity term is zeroI:=ΛP.λz.λs.z. Its erasure is λz.λs.z, exactly the erasure of zeroC. Therefore zero:=[zeroC,zeroI]:Nat by CDLE-Isect-I.

Assume n:Nat. Its second projection gives induction for n.1. Define sucI(n):=ΛP.λz.λs.sn.1(n.2Pzs). The argument n.1 to the step is erased. Hence erase(sucI(n))=λz.λs.s(erase(n)zs)=erase(sucC(n.1)). The dependent intersection suc(n):=[sucC(n.1),sucI(n)] therefore inhabits Nat.

Theorem 96.4 — Derived induction

The term indNat:=ΛP.λz.λs.λn.n.2Pzs has type P:NatC. P(zeroC)(m:NatC.P(m)P(sucC(m)))Πn:Nat.P(n.1), where the quantifier over P is erased.

Proof of Theorem 96.4 — Derived induction

Proof. Let n:Nat. Projection n.2 synthesizes IndNat(n.1). Instantiate that witness with P, then supply the zero and step premises. Its result is exactly P(n.1). Abstract over n, s, z, and the erased motive P. A predicate on represented naturals is obtained only by composition with the first projection. This domain is deliberate: the stored witness proves induction for the Church subject of an intersection inhabitant, not an unrestricted eliminator for arbitrary host-language values. ◻

The computation claims have three different strengths. Untyped beta reduction gives erase(indNatPzszero)erase(z). Internal equality after rewriting gives indNatPzszero=P(zeroC)z. For neutral n, the term indNatPzsn has no native eliminator redex.

Exercise 96.1

★★☆ Expand sucI(n) and sucC(n.1) and give the full beta-eta chain proving that CDLE-Isect-I applies. Then calculate the erasure of two successive constructors.

Soundness without global normalization

Let R be the complete lattice of beta-eta-closed sets of closed untyped lambda terms. A retained product is interpreted as the set of lambdas mapping each argument candidate to the codomain candidate. An erased product is the intersection of all codomain candidates. The two clauses that do the new work are [[ιx:T.T]]σ,ρ={E[[T]]σ,ρE[[T]]σ[xζ(E)],ρ},[[{tu}]]σ,ρ={[L]βη,σerase(t)=βησerase(u),,otherwise, where ζ(E) chooses a representative of the nonempty equivalence class E and L is the set of closed untyped terms.

Theorem 96.5 — Cedille Core soundness and consistency

For every environment in the interpretation of Γ:

  1. kind formation is defined;

  2. a synthesized type belongs to the interpretation of its kind;

  3. a synthesized or checked term has its erased beta-eta class in the interpretation of its type;

  4. classifier conversion preserves interpretations.

Consequently, no closed term synthesizes X:.X.

Proof of Theorem 96.5 — Cedille Core soundness and consistency

Proof. The four semantic clauses are imported as Theorem 1 of Stump and Jenkins for the exact Cedille Core syntax and classification rules frozen in convention 96.1. Its hypotheses and conclusions are, respectively, an environment (σ,ρ)[[Γ]] and the four clauses displayed here. Lemmas 9–14 on page 10 establish nonemptiness, representative selection, term and type substitution, and invariance under type reduction; Appendix A, pages 10–15, proves every kinding, synthesis, and checking case by mutual induction. We import that complete proof rather than infer soundness from only the two clauses displayed above.

Theorem 2 of the same source has the exact closed consistency conclusion. Its local final step is the empty-candidate calculation: if a closed t had type X:.X, soundness would put its erasure in every candidate in R, including the empty candidate. No term belongs to the empty set, yielding a contradiction [SJ18]. ◻

Global normalization is false. If Top:={λx.xλx.x}, then β{Ω}:Top for Ω=(λx.xx)(λx.xx). Its erasure is Ω, which does not normalize. This does not contradict theorem 96.5: the greatest equality candidate contains non-normalizing terms. Closed functions retyped by an identity-erasing cast to a retained function type do satisfy the source’s qualified call-by-name normalization theorem; no stronger claim is used here.

Four encodings perform four operations

Encoding stored behavior representative operation cost boundary
Church fold iteration predecessor is linear
Parigot constructor plus recursive value primitive recursion larger constructor
Scott one-step case predecessor fold needs recursion
Mendler abstract recursive carrier structurally controlled fold algebra cannot inspect carrier

CDLE does not make these encodings definitionally equal. Dependent intersection can attach induction to each, and zero-cost casts can relate representations only when the two coercions erase to identity.

Monotone recursion and constant-time boundaries

Define a zero-cost cast Cast(A,B):=ιf:(AB).{fλx.x}. If c:Cast(A,B), then c.1:AB and erase(c.1)=βηλx.x. Casts form a preorder by identity and composition. A type scheme F: is monotone when it has monoF:A:.B:.c:Cast(A,B).Cast(F(A),F(B)). Write ClosedF(X):=Cast(F(X),X). Define the Tarski meet and its two universal casts by Rec(F):=X:.c:ClosedF(X).X,recLBF:X:.c:ClosedF(X).Cast(Rec(F),X),recGLBF:Y:.h:(X:.c:ClosedF(X).Cast(Y,X)).Cast(Y,Rec(F)). Both quantifiers in the definition of Rec are erased. Thus a term of Rec(F) is in every F-closed type without receiving a runtime dictionary.

Theorem 96.6 — Derived monotone recursive type

For every F and monoF in Cedille Core, the Tarski construction defines Rec(F): and casts recRoll(monoF):Cast(F(Rec(F)),Rec(F)),recUnroll(monoF):Cast(Rec(F),F(Rec(F))). Let roll:=recRoll(monoF).1 and unroll:=recUnroll(monoF).1. These retained functions erase to λx.x and are mutually inverse by internal equality. Under a cost model that counts erased beta steps and does not charge type checking, roll and unroll take constant time.

Proof of Theorem 96.6 — Derived monotone recursive type

Proof. For m:monoF, the two casts are constructed by recRoll(m):=recGLBF(ΛX.Λc.cCastm(recLBF(c))),recUnroll(m):=recLBF(m(recRoll(m))). Indeed, recLBF(c) casts Rec(F) to X; monotonicity casts F(Rec(F)) to F(X); composition with c:Cast(F(X),X) supplies the lower-bound family consumed by recGLBF. For unrolling, monotonicity sends the rolling cast to Cast(F(F(Rec(F))),F(Rec(F))), so the latter type is F-closed and recLBF applies.

These definitions, including the identity-erasure proofs inside recLB and recGLB, are the exact derived terms in Figure 12 of Jenkins and Stump; their greatest-lower-bound property is Theorem 8 on page 24. Figure 13 on page 25 defines retained roll and unroll by eliminating the two casts and proves both inverse equalities. Importing those derivations supplies the internal typing and equality premises omitted by the displayed mathematical notation. The erasure calculation is then (λx.x)(λx.x)βλx.x. At runtime a roll or unroll is the identity function, so a constant number of beta steps exposes its argument independently of the recursive value’s size [JS21]. ◻

Without monoF, the F-image of a cast is unavailable and the two Tarski inequalities cannot be constructed. Positivity is one sufficient way to derive monotonicity; it is not built into Rec as a syntactic oracle.

Exercise 96.2

★★☆ Given c:Cast(A,B) and d:Cast(B,C), construct dc:Cast(A,C). Type its function view and give the complete beta-eta calculation showing that its erasure is identity.

A simulated large elimination

Large elimination asks a datatype value to compute a type. Cedille Core has no native type-level case reduction on an encoded value. It can instead produce an extensional equivalence of the desired types.

Define TpEq(A,B):=ιc:Cast(A,B).Cast(B,A). The outer dependent intersection is nondependent in c, but its introduction rule forces the two cast witnesses to have the same identity erasure. If e:TpEq(A,B), the two coercions are the function views of e.1 and e.2, and both erase to λx.x.

The source’s first concrete simulation is the family of n-ary function types over a fixed T. Native large elimination would postulate Nary(0)T,Nary(Sn)TNary(n), but Cedille Core has no such type-level equations. Instead define a GADT-like relation by constructors naryRZ:X:.e:TpEq(X,T).NaryR(0,X),naryRS:I:.n:N.NaryR(n,I)X:.e:TpEq(X,TI).NaryR(Sn,X), and take Nary(n):=X:.r:NaryR(n,X).X.

Theorem 96.7 — Simulated Nary computation

There are derived witnesses naryZEq:TpEq(Nary(0),T) and narySEq:n:N.NaryR(n,Nary(n))TpEq(Nary(Sn),TNary(n)). Their two coercion directions erase to identity; neither conclusion is a judgmental type equation.

Proof of Theorem 96.7 — Simulated Nary computation

Proof. Figure 4 on page 5 of Jenkins, Marmaduke, and Stump defines NaryR. Figure 5 and Propositions 1–4 on pages 7–8 give the exact signatures of naryZEq and narySEq, prove respect and uniqueness of the type index, and construct naryREx(n):NaryR(n,Nary(n)). Their linked Cedille source supplies the mechanically checked derivations behind those signatures; we import them for the frozen CDLE calculus. Figure 6 on page 8 eliminates the witnesses to identity-erasing coercions. Thus either TpEq projection is zero cost, but no native case reduction is added [JMS22]. ◻

The generic construction extends this simulation to signatures with codes and interpretation, but its equation is extensional type equivalence, not an unrestricted equality of types. Some recursive examples expose only one simulated computation step before another explicit witness is required.

Zero-cost reuse

Assume an indexed vector encoding Vec(A,n) and a list encoding List(A) whose erased constructors are identical. The forgetful cast forgetn:Cast(Vec(A,n),List(A)) has function view λx.x. Suppose list map has type mapL:(AB)List(A)List(B) and its output length theorem permits the reverse cast into Vec(B,n). Define vector map by the two casts around list map. Its erasure is erase(mapV)=λf.λxs.(λx.x)(mapLf((λx.x)xs))λf.λxs.mapLfxs. Typing uses the length theorem; runtime uses exactly the list implementation. This is zero-cost reuse: the conversion functions erase to identity, not merely to linear traversals that happen to return equal data.

If vector and list constructors have different erasures, the cast equality premise is false and the reuse proof fails. Extensional isomorphism alone does not establish zero cost.

Exercise 96.3

★★☆ Compare an identity-erasing vector-to-list cast with a structurally recursive conversion that copies every constructor. Type both functions, compute their erasures on a two-element input, and identify the failed premise preventing the second function from inhabiting Cast.

Evidence from Cedille developments

The v1.1.2 Cedille checker and pinned developments check concrete induction, recursive-representation, large-elimination, and reuse files. Surface constructs map to the core as follows: erased braces map to and tu; intersection introductions map to [t,u]; equality proofs map to β, ρ, and ϕ; and casts map to dependent intersections whose function view erases to identity. The developments do not check an unprinted global normalization theorem, automatic large-elimination computation, or the consistency proof itself. The implementation bounds conversion search, so acceptance is relative to the configured budget.

The c2 redesign. The experimental c2 calculus replaces CDLE’s untyped equality interface with typed proof rules while retaining erasure, intersections, and casts. Its proved results include confluence and preservation, normalization of proof reduction by translation to Fω, a partial consistency translation to CDLE, and normalization of a strict cast-free erased fragment. For the full object language, normalization is conditional on an external ϕ-safety or contextual-equivalence hypothesis. The proposed characterization is conjectural, so checking is relative to an oracle for that hypothesis. Full object normalization is false. The later Lean repository contains hundreds of admitted declarations and is a proof roadmap, not mechanized evidence for these theorems.

Suggested first pass.

Begin with exercise 96.4, then complete exercise 96.6.

Exercise 96.4

★★☆ Reconstruct the zero and successor intersection introductions. Write each erasure. Use P(n):=n+0=n and distinguish erased computation from the equality rewrites in its result type.

Exercise 96.5

★★★ Write the intersection and equality cases of theorem 96.5. Instantiate X:.X with the empty candidate. Then type β{Ω}:Top and explain why it does not affect that argument.

Exercise 96.6

★★★ Practical project.cdle-zero-cost-runtime Implement in Kappa a finite model of Church observations, same-erasure admission, identity roll/unroll, and list-map reuse. Construct two successors, observe 2, preserve it through roll/unroll, and obtain [2,3]. Reject a copying/identity pair. Unconditional admission must make the test fail.

Sources. The later Cedille Core rules and erasure are Figures 1–6 on pages 2–4 of the syntax-and-semantics paper; the semantic clauses and exact consistency and normalization boundaries are on pages 5–8. The natural-number construction uses the realizability-to-induction development. The Tarski construction, constant-time roll/unroll, and recursive representations are from the monotone-recursive-types source; simulated large eliminations use TpEq from the TYPES development. The pinned Cedille Cast and development repositories check examples, not a stronger metatheory [Stu17, SJ18, JS21, JMS22, Ced25].

Search the book

Type to search the local edition.