GLOBAL KNOWLEDGE ARK

Mathematics · Article

Type theory and computer-assisted proof

Build dependent types and equality proofs, verify indexed computations and trace what a proof assistant checks.

Back to Mathematics

After reading, you can

  • Read judgments and dependent contexts and carry out capture-avoiding substitution.
  • Construct dependent functions and pairs, and verify indexed vector operations.
  • Use natural induction and identity elimination to derive equality and transport terms.
  • Distinguish type and proof universes and track the permitted target of each eliminator.
  • Follow explicit proof terms, tactic instructions and checked Boolean reflection.
  • Verify a unit-indexed calculation and identify the mathematical assumptions of a formal certificate.
01

Types that record mathematical information

A vector can carry its length in its type. That gives the checker enough information to require a valid index and verify the length of an append operation.

Develop the rules that make these examples work. Build dependent functions, witness pairs and identity proofs, and follow the exact computation of transport and induction.

Apply the same reasoning to proof assistants. A tactic can produce a proof term, and a checker can verify that term under the actual rules and assumptions.

02

Read a judgment in its context

Context formation starts with the empty context, then allows a fresh variable x:A when A is a well-formed type in the prior context. Start with n:Nat and extend by v:Vec(Bool,n). Its declaration type exists because the prior n is a natural number and Bool is a small type.

In the resulting context the variable rule gives Γ⊢v:Vec(Bool,n). Reading this judgment requires the n declared earlier. If the declarations are reversed, the occurrence of n in the type of v would lack a prior binding, and the proposed context is not well formed.

The judgment Γ⊢Vec(Bool,n):Type_0 classifies a type, whereas Γ⊢v:Vec(Bool,n) classifies an inhabitant. Neither asserts that n has any specified numeral value. Contextual terms may depend on the variables without discharging their assumptions.

An expression Γ⊢t≡u:A compares two well-typed terms at a common type by the calculus's judgmental equality. A term Γ⊢p:Id_A(t,u) instead inhabits the equality type. Keep the ambient context, the assigned type, and the status of each equality explicit. Related reading: [Hypothetical judgments and substitution](https://ncatlab.org/nlab/files/MartinLofIntuitionisticTypeTheory.pdf), [Typing, conversion and capture avoidance](https://people.csail.mit.edu/jgross/tmp/hott-book-html/hott-html.html), [Dependent products, family arguments and universes](https://people.csail.mit.edu/jgross/tmp/hott-book-html/hott-html.html), [Polymorphic types and elaboration in Lean](https://lean-lang.org/theorem_proving_in_lean4/Dependent-Type-Theory/). Type a later variable only after its dependent declaration type is well formed in the prior context.

03

Prove the substitution rule for basic dependent judgments

Suppose Γ⊢u:A and Γ,x:A,Δ⊢t:B, where declarations in Δ may depend on x. Capture-avoiding substitution gives Γ,Δ[u/x]⊢t[u/x]:B[u/x]. Each declaration type in the suffix is substituted in order, so earlier entries remain available when checking later entries.

In the variable case, if t is x the new term is u at type A, weakened to the substituted suffix. For a variable declared earlier than x, its original declaration type is unchanged. A variable from Δ keeps its name and uses the substituted declaration type.

If the last rule applies f:Π y:C.D(y) to v:C, the induction hypotheses give the two substituted judgments. The application type is obtained by substituting v[u/x] for the freshly named y in D[u/x]. This agrees up to renaming with substituting u into the original type D[v/y].

For function introduction, rename the bound y fresh for the free variables of u, then apply the induction hypothesis in the extended context. Abstraction discharges that same fresh declaration with its substituted domain. Formation and conversion cases carry substitution through the component judgments and rules such as β, using the same capture-avoidance convention. Related reading: [Hypothetical judgments and substitution](https://ncatlab.org/nlab/files/MartinLofIntuitionisticTypeTheory.pdf), [Typing, conversion and capture avoidance](https://people.csail.mit.edu/jgross/tmp/hott-book-html/hott-html.html), [Dependent products, family arguments and universes](https://people.csail.mit.edu/jgross/tmp/hott-book-html/hott-html.html), [Substitution and scope in first-order syntax](https://builds.openlogicproject.org/open-logic-complete.pdf#page=236). Substitution must reach the type of every later declaration and avoid capturing values under binders.

04

Explain weakening and variable freshness

For weakening, extend a well-formed context Γ with y:C where C is a type in Γ and y is fresh. A derivation using only old variables can be lifted to the larger context by induction on its rules. Its old variable lookups and formation judgments still have the declared types.

When a rule introduces a binder, rename that binder to avoid y before extending the corresponding premise. Both the introduced variable and y are then legal in the relevant extended context. The original term and type do not acquire a free occurrence of y.

For a substitution illustration assume free x,y:A. In λy:A.x the displayed y is bound and a separate free y is the replacement for x. Rename the bound variable to z fresh, obtaining λz:A.x before carrying out [y/x].

The correct result is λz:A.y, the constant function with the given free value y. Applying it to a:A reduces to y. Naively returning λy:A.y would make the former free replacement into a bound use and change the function to identity. Related reading: [Hypothetical judgments and substitution](https://ncatlab.org/nlab/files/MartinLofIntuitionisticTypeTheory.pdf), [Typing, conversion and capture avoidance](https://people.csail.mit.edu/jgross/tmp/hott-book-html/hott-html.html), [Substitution and scope in first-order syntax](https://builds.openlogicproject.org/open-logic-complete.pdf#page=236). Weakening preserves old derivations under a fresh well-formed extension; alpha conversion concerns the bound occurrence alone.

05

Check β reduction and conversion

Suppose Γ⊢F:Π x:A.B(x) and Γ⊢a:A. The application F a has type B(a), the capture-avoiding substitution of a into the family. A dependent codomain still permits ordinary β reduction at a lambda.

For instance take F=λn:Nat.⟨n,refl_n⟩ at type Π n:Nat.Σ m:Nat.Id_Nat(m,n). At n=succ 0 its application type is Σ m:Nat.Id_Nat(m,succ 0). The β step gives ⟨succ 0,refl_(succ 0)⟩ with that same type.

For conversion, let a term v have type Vec(A,n) in a context containing n:Nat. The type Vec(A,addL(0,n)) reduces to Vec(A,n) because addL recurses on its first argument. Type formation at both indices is valid in the stated context.

Reduce the root redex without capturing a free variableRename y before substituting the free y; The intermediate row shows the binding-preserving rename before substitution when needed. The left child is λx.λy.x and the right child is free y. Renaming the inner y binder keeps the inserted y free.Reduce the root redex without capturing a free variablePhaseTerm or conditionOriginal(λx. λy. x) yRoot redexYes; argument yα-renaming(λx. λy′. x) yAfter at most one stepλy′. yFree before: y · Free after: yFunction binder y at left/body; free y at right.The x bound by λx occurs at left/body/body; substitute free y there.
The intermediate row shows the binding-preserving rename before substitution when needed. The left child is λx.λy.x and the right child is free y. Renaming the inner y binder keeps the inserted y free.

A free variable of an argument must remain free wherever it is inserted. Renaming a conflicting inner binder changes the binding names without changing their meaning.

Exact β-reduction
QuantityExact result
Variables usedx, y
Free variables beforey
Root beta redexTrue
Intermediate after α-renaming(λx. λy′. x) y
One-step resultλy′. y
Free variables aftery
Exact inputs and supporting calculations
Declared inputs
ParameterValue
term["app",["lam","x",["lam","y","x"]],"y"]

The conversion rule therefore also checks v at Vec(A,addL(0,n)), with the same term v. This step uses judgmental equality from a computation rule. An arbitrary term of an identity type does not by itself modify that definitional equality. Related reading: [Hypothetical judgments and substitution](https://ncatlab.org/nlab/files/MartinLofIntuitionisticTypeTheory.pdf), [Typing, conversion and capture avoidance](https://people.csail.mit.edu/jgross/tmp/hott-book-html/hott-html.html), [Dependent products, family arguments and universes](https://people.csail.mit.edu/jgross/tmp/hott-book-html/hott-html.html). Application substitutes its actual argument into the fiber. Conversion only uses the definitional relation of the calculus.

06

Turn a logical implication into a term

Interpreting implication as a function type, assume p:P in a context, construct q:Q, and discharge p by λp.q of type P→Q. Given f:P→Q and p:P, the application f p has type Q. These operations implement implication introduction and elimination.

For conjunction use a product. From p:P and q:Q the pair ⟨p,q⟩ inhabits P×Q. Its first projection has type P and its second Q. Applied to a displayed pair, these projections compute back to the components.

Given f:P→Q and g:Q→R, the composition λp:P.g(f p) has type P→R. Under the assumption p:P, first use f p:Q and then g(f p):R. Discharging the two functional premises gives a term for (P→Q)→(Q→R)→(P→R).

Interpret falsity by an empty type 0. Its eliminator takes an inhabitant of 0 to any stipulated type T, since there are no constructor cases. It does not create an inhabitant of 0. The constructive negation type of P is P→0. Related reading: [Typing, conversion and capture avoidance](https://people.csail.mit.edu/jgross/tmp/hott-book-html/hott-html.html), [Products, dependent pairs and coproducts](https://people.csail.mit.edu/jgross/tmp/hott-book-html/hott-html.html), [The intuitionistic excluded-middle countermodel](https://lclem.github.io/logic_course/book/logic_book_2020-03-15.pdf), [Lean's proof irrelevance and implication proofs](https://lean-lang.org/theorem_proving_in_lean4/Propositions-and-Proofs/), [Introduction and elimination in proof rules](https://builds.openlogicproject.org/open-logic-complete.pdf#page=142). Implication and conjunction use the specified function and product rules, with falsity given an empty eliminator.

07

Eliminate a sum by cases

The type A+B has constructors inl(a) for a:A and inr(b) for b:B. To define a map to B+A it suffices to give target terms in the respective left and right contexts. Use inr(a):B+A in the first and inl(b):B+A in the second.

Let swap(s) be the sum eliminator using those two branches on s. It is well typed for every inhabitant of A+B because each branch returns the very same specified codomain B+A, regardless of which constructor appeared.

By the left computation rule swap(inl(a))≡inr(a). By the right computation rule swap(inr(b))≡inl(b). The labels inl and inr refer to the ordered component types in the result, so the old A component deliberately uses the new right constructor.

An eliminator missing a branch would leave the corresponding constructor without a result. Even if an empty summand makes its case impossible, that type information must be represented, for example by using empty elimination for its branch. Related reading: [Products, dependent pairs and coproducts](https://people.csail.mit.edu/jgross/tmp/hott-book-html/hott-html.html), [Lean's proof irrelevance and implication proofs](https://lean-lang.org/theorem_proving_in_lean4/Propositions-and-Proofs/), [Introduction and elimination in proof rules](https://builds.openlogicproject.org/open-logic-complete.pdf#page=142). Both sum constructors require a branch in their respective contexts and the common stated target.

08

Locate the constructive boundary of excluded middle

In the intuitionistic propositional fragment, read A+¬A as constructive disjunction and assume the standard soundness of intuitionistic derivations for monotone Kripke models. Take two worlds w₀≤w₁. Force an atomic proposition A at w₁ only and do not force falsity at either world.

For intuitionistic negation a world forces ¬A when every greater or equal world forcing A also forces falsity. The extension w₁ forces A and does not force falsity, so w₀ does not force ¬A. By construction w₀ itself does not force A.

Forcing a disjunction at a world requires one of the two disjuncts there. Thus w₀ does not force A∨¬A. By the stated soundness, no theorem of this bare intuitionistic propositional logic gives that disjunction for all atomic choices. This is scope for the given core logic, without a further classical constant.

If A has an actual decision term, its positive branch carries a proof a:A and its negative branch a function A→0. In either case one can form the corresponding constructor of A+¬A. This particular supplied proof is fully compatible with the countermodel for an arbitrary A. Related reading: [The intuitionistic excluded-middle countermodel](https://lclem.github.io/logic_course/book/logic_book_2020-03-15.pdf), [Reflection and decidability instances](https://lean-lang.org/doc/reference/latest/Tactic-Proofs/Tactic-Reference/). Use soundness only of the intuitionistic propositional fragment. A supplied decision handles the exact instance.

09

Define total recursion on naturals

For fixed n use natural recursion in the first variable m, with base result n and step taking the previous result r to succ r. The two defining equations are addL(0,n)≡n and addL(succ m,n)≡succ(addL(m,n)). A step invokes only the result for the immediate predecessor of its first argument.

For addL(succ(succ 0),0), one step yields succ(addL(succ 0,0)). The next gives succ(succ(addL(0,0))), then the base rule gives succ(succ 0). Every occurrence is a natural number term.

For addL(succ 0,succ(succ 0)), the step produces succ(addL(0,succ(succ 0))). The base returns succ(succ 0) in the inner position, so the full term reduces to the numeral three.

Termination of this recursion on a natural numeral follows because the first argument loses one successor each time until zero. The second argument is held fixed. For a symbolic first argument n, a particular branch of the recursor may remain blocked until that variable is known. Related reading: [Natural recursion and dependent induction](https://people.csail.mit.edu/jgross/tmp/hott-book-html/hott-html.html), [Indexed vector constructor cases in Lean](https://lean-lang.org/theorem_proving_in_lean4/Induction-and-Recursion/), [Structural recursion and partial definitions](https://lean-lang.org/doc/reference/latest/Definitions/Recursive-Definitions/). The first-argument natural recursion is an explicit lesson definition and has exact constructor computations.

10

Use a dependent induction motive

The dependent eliminator for naturals has a motive P:Nat→Type_i, a base term p₀:P(0) and a step term s:Π n:Nat.P(n)→P(succ n). It returns a term in P(n) at every n. Its computation chooses the base or the step according to the natural constructor.

For the theorem use P(n)=Id_Nat(addL(n,0),n). At zero the left side reduces to zero, so refl_0 checks at P(0) by conversion. The motive's index is part of both the equation and the result type.

Suppose the induction hypothesis h proves addL(n,0)=n. Equality elimination gives congruence of successor, turning h into a proof of succ(addL(n,0))=succ n. The step goal's left side addL(succ n,0) reduces to that same source endpoint.

The dependent step therefore supplies P(succ n) and the eliminator gives the result for arbitrary n. Reflexivity proves the base by direct computation. The step needs the induction hypothesis for the variable predecessor, rather than an assumed rule reducing addL(n,0) when n is arbitrary. Related reading: [Natural recursion and dependent induction](https://people.csail.mit.edu/jgross/tmp/hott-book-html/hott-html.html), [Indexed vector constructor cases in Lean](https://lean-lang.org/theorem_proving_in_lean4/Induction-and-Recursion/). Induction uses a type family and the target's translated induction hypothesis under the successor equation.

11

Use a dependent function to return indexed data

To introduce a term of Π x:A.B(x), give a term b(x):B(x) under the additional assumption x:A and abstract it. To eliminate it at a:A, apply the function and obtain B(a). For an explicit abstraction, β computation gives (λx.b(x)) a≡b(a).

Take A=Nat and let B(n)=Fin(succ n). The zero-index constructor belongs to Fin(succ n) for each n, regardless of the value of n. It supplies the body of F=λn:Nat.zeroIndex(n).

Applying F to the ordinary numeral two gives a term at Fin(succ 2)=Fin(3). The β rule makes this term the zero constructor of that type. The family controls the type while the constructor still chooses ordinal zero as its value.

This is a dependent result even though its numeric position is always zero. A mere function into unindexed Nat would not itself express the upper-bound inhabitance. Choosing a family does not assert a definitional equality between different Fin indices. Related reading: [Dependent products, family arguments and universes](https://people.csail.mit.edu/jgross/tmp/hott-book-html/hott-html.html), [Polymorphic types and elaboration in Lean](https://lean-lang.org/theorem_proving_in_lean4/Dependent-Type-Theory/). Applying a dependent function selects one fiber. Its index fixes the type of the resulting datum.

12

Use a dependent pair to package a witness

For a family B over A, form Σ x:A.B(x). To introduce a pair choose a:A and b:B(a), then write ⟨a,b⟩. The second component is checked in the fiber selected by the first component.

From p:Σ x:A.B(x), the projection fst p has type A. The dependent projection snd p has type B(fst p), which can be formed as soon as fst p is known to have type A. The types of the two projections therefore track the dependency.

For p=⟨a,b⟩, the first projection reduces to a and the second to b. The assigned type B(fst p) for the second term reduces correspondingly to B(a). This conversion uses the actual first projection computation.

For B(n)=Vec(Bool,n), the pair ⟨0,nil⟩ and the pair ⟨1,cons true nil⟩ both inhabit Σ n:Nat.B(n). The first forces the second component to length zero and the second forces length one. A pair ⟨0,cons true nil⟩ fails the type check in that family. Related reading: [Products, dependent pairs and coproducts](https://people.csail.mit.edu/jgross/tmp/hott-book-html/hott-html.html). The second projection lies in the fiber of the actual first projection.

13

Separate finite indices from raw numerals

Use the indexed constructors nil:Vec(A,0) and cons:A→Vec(A,n)→Vec(A,succ n) for each n. Fin at zero has no constructor. At succ n it has zero and the successor of any term of Fin(n), with constructor results at Fin(succ n).

At length zero, no Fin value can be built by a constructor, since both stated result indices for constructors are successors. This is the impossible branch used by the finite-index dependent eliminator. The zero natural number is available as Nat and is not an index of Fin(0).

Take a,b,c:A. Starting at nil, form cons c nil at length one, cons b (cons c nil) at length two, and cons a (cons b (cons c nil)) at length three. The result length follows by the displayed constructor indices.

Prove the index bound before using the lookupRead the last valid index; Green marks an actual admissible slot. Failing the bound blocks formation of a Fin(n) argument.Prove the index bound before using the lookup492Each declared slot has one index and one value.i=0i=1i=2Requested i=2 · Required 0≤i<3 · AdmittedSelected element 2.
Green marks an actual admissible slot. Failing the bound blocks formation of a Fin(n) argument.

A rejected index is a type-level precondition failure. An empty vector has no valid index, so there is no value to fetch and no missing or reserved data value.

Exact index certificate
QuantityExact result
Vector[4, 9, 2]
n3
i2
Forms Fin(n)True
Value2
Exact inputs and supporting calculations
Declared inputs
ParameterValue
xs[4,9,2]
i2

The final legal position is two in zero-based numbering: start with zero:Fin(1), then apply the index-successor constructor to obtain position one in Fin(2) and again to obtain position two in Fin(3). A numeric value alone would require a bound proof before replacing these typed constructors. Related reading: [Dependent products, family arguments and universes](https://people.csail.mit.edu/jgross/tmp/hott-book-html/hott-html.html), [Indexed vector constructor cases in Lean](https://lean-lang.org/theorem_proving_in_lean4/Induction-and-Recursion/). Constructor indices determine the empty Fin(0) case and bound the displayed positions.

14

Prove safe indexing by dependent recursion

Define get_n:Vec(A,n)→Fin(n)→A by recursion on the vector, with the index supplied in its dependent motive. For nil the index type is Fin(0). Use the empty-index eliminator, so there is no returned element branch at an impossible index.

For cons a xs of length succ n, the zero constructor gives result a. An index succ i arises from i:Fin(n). Pass xs:Vec(A,n) and i to the recursive call get_n xs i, which has type A.

The recursive call uses the tail as a strict substructure of the input vector. All defined branches use matching indices. Hence the total indexed function requires neither a default element of A nor a runtime case for an out-of-range numeral.

For v=cons a (cons b (cons c nil)) and the position-one index succ zero at length three, one reduction gives get at length two on the tail with zero index. The next computation gives b. Both actual argument types match each recursive premise. Related reading: [Natural recursion and dependent induction](https://people.csail.mit.edu/jgross/tmp/hott-book-html/hott-html.html), [Indexed vector constructor cases in Lean](https://lean-lang.org/theorem_proving_in_lean4/Induction-and-Recursion/), [Structural recursion and partial definitions](https://lean-lang.org/doc/reference/latest/Definitions/Recursive-Definitions/). Recursion reduces the vector and finite index consistently; the absent constructor case uses an empty eliminator.

15

Type append by a matching length recursion

Fix ys:Vec(A,n) and recurse on xs:Vec(A,m) with motive Vec(A,addL(m,n)). When xs=nil, m is refined to zero. The result type reduces to Vec(A,n) by the defining addL equation, so return ys directly.

When xs=cons a zs with zs:Vec(A,m′), use the recursive result append zs ys:Vec(A,addL(m′,n)). Applying cons gives Vec(A,succ(addL(m′,n))). This matches the expected length addL(succ m′,n) by the successor equation.

The constructor calculation describes exactly the dependent motive, including the case that n is an unknown variable. The recursion terminates because the tail is a strict structural subterm. A concrete nil argument produces the original ys as its computed output.

Append by recursion on the first vectorAppend two nonempty vectors; The base case returns the entire right vector. Each step adds one left constructor and one to the result length. Recursive descent removes the left head until nil; the rows show each return while rebuilding.Append by recursion on the first vectorLeft lengthRight lengthReturned lengthReturned vector033[7, 8, 9]134[2, 7, 8, 9]235[1, 2, 7, 8, 9]Unwinding recursion on the left vector0 + m = m; (n+1)+m = (n+m)+1Final vector: [1, 2, 7, 8, 9] · length 5Descent: [1, 2] → [2] → nil → return right vector
The base case returns the entire right vector. Each step adds one left constructor and one to the result length. Recursive descent removes the left head until nil; the rows show each return while rebuilding.

The convention reduces the left index first. A transport for a different orientation of the length equality must be justified explicitly.

Exact appended vector
QuantityExact result
Left[1, 2]
Right[7, 8, 9]
Concatenation[1, 2, 7, 8, 9]
Result length2 + 3 = 5
Exact inputs and supporting calculations
Declared inputs
ParameterValue
xs[1,2]
ys[7,8,9]
Recursive results
Left lengthRight lengthOutput lengthOutput values
033[7, 8, 9]
134[2, 7, 8, 9]
235[1, 2, 7, 8, 9]

Using addL(n,m) for the result instead would give the base target addL(n,0), which remains a blocked recursion for a variable n. The corresponding right-zero identity and right-successor identity can be proved and used by transport. They are additional proof steps for that orientation. Related reading: [Natural recursion and dependent induction](https://people.csail.mit.edu/jgross/tmp/hott-book-html/hott-html.html), [Indexed vector constructor cases in Lean](https://lean-lang.org/theorem_proving_in_lean4/Induction-and-Recursion/), [Structural recursion and partial definitions](https://lean-lang.org/doc/reference/latest/Definitions/Recursive-Definitions/). Align the append motive with the first argument inspected by addL. Reversing the arithmetic direction can require transport.

16

Use a motive to preserve dependent indices in a match

Consider a vector v:Vec(A,n). Define a case-analysis result with family C(n)=Id_Nat(n,0)+Σ k:Nat.Id_Nat(n,succ k). Its left side records the zero case and its right side carries a predecessor index with evidence for the successor case.

In the nil branch the actual index is zero. The motive specializes to C(0), so inl(refl_0) produces the left component at the required equality type. The generic index has been replaced by the constructor's index in the branch.

In the cons branch the constructor exposes m and sets the actual index to succ m. Return inr(⟨m,refl_(succ m)⟩), which is in the right component of C(succ m). Both branches construct only evidence valid for their refined index.

The indexed eliminator reassembles the branch results into a term of C(n) for the original input. Replacing n by a guessed numeral in the generic context would change the target without a computation rule or an equality proof. Branch specialization follows the declared constructor types. Related reading: [Dependent products, family arguments and universes](https://people.csail.mit.edu/jgross/tmp/hott-book-html/hott-html.html), [Products, dependent pairs and coproducts](https://people.csail.mit.edu/jgross/tmp/hott-book-html/hott-html.html), [Indexed vector constructor cases in Lean](https://lean-lang.org/theorem_proving_in_lean4/Induction-and-Recursion/). Dependent match branches inherit the constructor equality of indices and a corresponding specialized motive.

17

State and use equality elimination

Fix a:A. For y:A and p:Id_A(a,y), let C(y,p) be a well-formed family of types in those two variables. Given d:C(a,refl_a), the identity eliminator J_a(C,d,y,p) has type C(y,p). This is the based form of path induction.

The introduction rule supplies refl_a:Id_A(a,a). Substituting y=a and p=refl_a into the eliminator gives the definitional computation J_a(C,d,a,refl_a)≡d. Thus evidence at the reflexive case provides the branch from which elimination is built.

The motive may refer to the endpoint y and the path term p separately. To prove a family of equations, choose C to be the equation type with its actual endpoints and use computation to check the base proof.

J may return an inhabitant of a new type computed from p. It does not make a and a variable y judgmentally equal in the ambient context. For an abstract path p the eliminator can remain as a proof term until a computation rule applies. Related reading: [Identity elimination, symmetry and path composition](https://people.csail.mit.edu/jgross/tmp/hott-book-html/hott-html.html), [Equality substitution and the existential target](https://lean-lang.org/theorem_proving_in_lean4/Quantifiers-and-Equality/). J uses a fixed source endpoint and a motive varying over endpoint and path. Reflexivity supplies its base.

18

Derive congruence of a function

Given f:A→B and p:Id_A(x,y), take the motive C(y,p)=Id_B(f x,f y) with x fixed. At y=x and p=refl_x set d=refl_(f x), which lies in C(x,refl_x).

Define ap_f(p) by J with this motive and base. It has the desired equality type in B. At reflexivity the computation rule gives ap_f(refl_x)≡refl_(f x), so the congruence proof computes in the constructor case.

If f instead has dependent signature Π x:A.B(x), the endpoints f x and f y lie in B(x) and B(y). A homogeneous identity type requires both of its endpoints at one common type.

Use transport in family B along p to place f x in B(y). The dependent congruence conclusion is Id_(B(y))(transport_B(p,f x),f y). A second J proof with this motive has reflexive base because transport on reflexivity computes to the original term. Related reading: [Identity elimination, symmetry and path composition](https://people.csail.mit.edu/jgross/tmp/hott-book-html/hott-html.html), [Transport and application to equality proofs](https://people.csail.mit.edu/jgross/tmp/hott-book-html/hott-html.html), [Equality substitution and the existential target](https://lean-lang.org/theorem_proving_in_lean4/Quantifiers-and-Equality/). Homogeneous equality requires endpoints in one fiber; dependent congruence uses transport.

19

Transport an inhabitant across an index equality

Let B:A→Type_i and u:B(x). In J based at x choose C(y,p)=B(y), which can ignore the path variable while retaining its endpoint. At the reflexive case the given u has exactly the required type B(x).

Thus transport_B(p,u)=J_x(C,u,y,p) has type B(y) for p:Id_A(x,y). The computation rule at refl_x makes transport_B(refl_x,u)≡u. This supplies a usable operation on a proof term.

For the natural index take h:Id_Nat(addL(n,0),n) and v:Vec(A,addL(n,0)). The family B(k)=Vec(A,k) gives transport_B(h,v):Vec(A,n). The source and destination fibers match the endpoints of h.

Transport indexed data only with an equality proofReflexivity at length two; Actual transport along refl preserves the elements. The dashed line marks a rejected transport.Transport indexed data only with an equality proofVec at index 2[1, 2]reflTarget index 2[1, 2]Both closed numeral indices are 2.Reflexivity transports the same value.
Actual transport along refl preserves the elements. The dashed line marks a rejected transport.

Reflexivity supplies identity only for the same numeral. It cannot supply an equality between distinct closed numerals.

Exact transport decision
QuantityExact result
Source index2
Target index2
Given witnessrefl
Certificate acceptedTrue
Transported result[1, 2]
Exact inputs and supporting calculations
Declared inputs
ParameterValue
xs[1,2]
m2
proofrefl

For variable n the two indices need not be judgmentally convertible. The term transport uses this propositional equality, while the special case in which the path reduces to reflexivity can compute away its transport. Related reading: [Identity elimination, symmetry and path composition](https://people.csail.mit.edu/jgross/tmp/hott-book-html/hott-html.html), [Transport and application to equality proofs](https://people.csail.mit.edu/jgross/tmp/hott-book-html/hott-html.html), [Equality substitution and the existential target](https://lean-lang.org/theorem_proving_in_lean4/Quantifiers-and-Equality/). The identity proof supplies the direction from the source fiber to the target fiber.

20

Compose and reverse equality proofs

For p:Id_A(a,b), define sym(p) by J at a with C(y,h)=Id_A(y,a). Its base is refl_a at y=a and h=refl_a. The resulting term has type Id_A(b,a).

The computation rule gives sym(refl_a)≡refl_a, as both slot values then coincide by computation. For a general variable p the source and target identities are still explicit.

For p:Id_A(a,b) and q:Id_A(b,c), eliminate q by J at b with motive D(z,h)=Id_A(a,z) and base p. This produces trans(p,q):Id_A(a,c). At q=refl_b the computation is trans(p,refl_b)≡p.

These operations transform proof terms. The endpoints of the resulting identities need only have the common assigned type A. Transport lets such proofs affect a term's type while judgmental conversion continues to obey the calculus's own rules. Related reading: [Identity elimination, symmetry and path composition](https://people.csail.mit.edu/jgross/tmp/hott-book-html/hott-html.html), [Equality substitution and the existential target](https://lean-lang.org/theorem_proving_in_lean4/Quantifiers-and-Equality/). Symmetry eliminates the given path and the displayed composition eliminates the second path.

21

Prove commutation using propositional equalities

Write z(m):Id_Nat(addL(m,0),m), obtained by induction on m. Also prove s(m,n):Id_Nat(addL(m,succ n),succ(addL(m,n))) by induction on m. At m=0 both sides reduce to succ n. At m=succ k, apply congruence of successor to s(k,n) and use the defining equations on both sides.

To prove commutativity use motive C(m)=Π n:Nat.Id_Nat(addL(m,n),addL(n,m)). At m=0 the left side is judgmentally n, and sym(z(n)) proves n=addL(n,0), giving the base for all n.

In the successor step the left side addL(succ m,n) reduces to succ(addL(m,n)). Apply successor congruence to the induction proof at n to obtain equality to succ(addL(n,m)). The symmetric path sym(s(n,m)) then reaches addL(n,succ m).

Transitivity combines the two displayed paths at the same type Nat. Induction gives C(m) for every m. Only the recursions on constructor first arguments are definitional steps. Congruence of the induction proof and the zero and successor-right identities supply the arithmetic content on arbitrary variables. Related reading: [Natural recursion and dependent induction](https://people.csail.mit.edu/jgross/tmp/hott-book-html/hott-html.html), [Identity elimination, symmetry and path composition](https://people.csail.mit.edu/jgross/tmp/hott-book-html/hott-html.html). Commutativity uses propositional induction lemmas on the variable actions of the recursion.

22

Explain rewriting without equality reflection

Let p:Id_A(x,y) and t:B(x) in a well-formed context. The motive B yields a transport term t′=transport_B(p,t) whose assigned type is B(y). For a path built by reflexivity, its computation reduces t′ to t by the identity eliminator.

Consider the open context n:Nat,m:Nat,h:Id_Nat(n,m),v:Vec(A,n). The neutral indices n and m have different free names and no defining equation connecting them. The declaration of h supplies a term at an identity type.

Consequently a request to check v directly as Vec(A,m) is not justified by conversion of the displayed indices. The checked term is transport_(λk.Vec(A,k))(h,v). The family is well formed at both endpoints, and the result of its eliminator has the target type.

Many rewrite interfaces insert such a transport or an equivalent eliminator behind their surface syntax. The calculus specified here has no equality-reflection rule turning every identity inhabitant into judgmental equality of its endpoints. Related reading: [Typing, conversion and capture avoidance](https://people.csail.mit.edu/jgross/tmp/hott-book-html/hott-html.html), [Identity elimination, symmetry and path composition](https://people.csail.mit.edu/jgross/tmp/hott-book-html/hott-html.html), [Transport and application to equality proofs](https://people.csail.mit.edu/jgross/tmp/hott-book-html/hott-html.html), [Equality substitution and the existential target](https://lean-lang.org/theorem_proving_in_lean4/Quantifiers-and-Equality/). An identity variable justifies an eliminator term. It does not change the calculus's conversion rules.

23

Compare pointwise and functional equality

Let f,g:Π x:A.B(x) and fix a:A. Evaluation ev_a sends a function h to h(a):B(a). It is an ordinary function of h since the choice of a is fixed. Given p:Id(f,g), apply ap_(ev_a) to obtain Id_(B(a))(f(a),g(a)).

Abstract over a to get the family of pointwise identities, with the correct target fiber for each application. At p=refl_f, congruence computation gives the reflexive proof at each f(a). No principle of function extensionality is used in this direction.

The reverse principle, dependent function extensionality, takes h:Π a:A.Id_(B(a))(f(a),g(a)) to a term of Id_(Π x:A.B(x))(f,g). State that principle explicitly if using it. Its arguments are the two functions and their pointwise path family.

The result of the reverse direction is a proof term at a function identity type. The rule as stated supplies propositional equality. It adds no definitional conversion making all extensionally equal functions reduce to the same expression. Related reading: [Identity elimination, symmetry and path composition](https://people.csail.mit.edu/jgross/tmp/hott-book-html/hott-html.html), [Transport and application to equality proofs](https://people.csail.mit.edu/jgross/tmp/hott-book-html/hott-html.html), [Equality substitution and the existential target](https://lean-lang.org/theorem_proving_in_lean4/Quantifiers-and-Equality/). Application of a path gives pointwise equality. The reverse uses the explicitly named extensionality principle.

24

Qualify proof irrelevance and identity uniqueness

Suppose a chosen universe Prop of proof types has judgmental proof irrelevance: if p,q:P with P:Prop then p≡q at P. This rule speaks about two proofs of one proposition. It is not a statement about arbitrary inhabitants of a data type.

Under that premise the term refl_p:Id_P(p,p) also checks at Id_P(p,q) by conversion. Thus for every pair of proofs of that P there is an explicit identity term between them, and these proof comparisons supply no distinct data values.

If a particular identity type Id_A(x,y) belongs to such a Prop, apply the previous argument with P=Id_A(x,y). It gives equality of each pair of paths p and q in that exact type. This is the uniqueness-of-identity-proofs conclusion for those identity types.

In the declared general intensional calculus Id_A(x,y) can be a type in Type_i independent of a proof-irrelevant Prop. Its formation rules alone do not give the displayed proof-irrelevance premise. When discussing a concrete assistant, identify which universe contains its equality proofs before transferring the conclusion. Related reading: [Identity elimination, symmetry and path composition](https://people.csail.mit.edu/jgross/tmp/hott-book-html/hott-html.html), [Lean's proof irrelevance and implication proofs](https://lean-lang.org/theorem_proving_in_lean4/Propositions-and-Proofs/), [Normalization and natural-number canonicity](https://people.csail.mit.edu/jgross/tmp/hott-book-html/hott-html.html). Uniqueness of equality proofs follows in the declared proof-irrelevant proposition case, without a rule for arbitrary Type identities.

25

Distinguish an existential proposition from a data pair

A data witness type Σ x:A.B(x) contains a pair whose first component is returned by fst. Its dependent second projection proves or supplies B(fst p) in the exact fiber. For computational extraction these projections are part of the given type's elimination rules.

Now take a separate proposition-level existence encoding Ex(P):Prop with elimination restricted to proposition targets. From ex:Ex(P), a proposition Q and branches Π x:A.P(x)→Q, that eliminator returns a proof of Q. The result type Q satisfies its rule.

An attempt to set the result type to A for arbitrary data A asks for an elimination target beyond Prop and fails the stated target premise. In a system with a separately stated choice axiom, one can first prove a proposition of nonemptiness and then obtain an element using that axiom. The resulting witness relies on that additional principle.

The witness types may express related mathematical information. Their differing elimination rules determine whether the term interface returns a selected datum with its evidence. A proof of a Prop-only encoding alone does not give the two projections of a data pair. Related reading: [Products, dependent pairs and coproducts](https://people.csail.mit.edu/jgross/tmp/hott-book-html/hott-html.html), [Transport and application to equality proofs](https://people.csail.mit.edu/jgross/tmp/hott-book-html/hott-html.html), [Data witnesses and type-level choice](https://people.csail.mit.edu/jgross/tmp/hott-book-html/hott-html.html), [Equality substitution and the existential target](https://lean-lang.org/theorem_proving_in_lean4/Quantifiers-and-Equality/). The chosen existential elimination target is a proposition. A data pair supplies usable projections.

26

Construct the dependent choice function available from witness data

Let p:Π x:A.Σ y:B(x).R(x,y) in the dependent calculus, with the displayed families well formed. Define f(x)=fst(p x). Its type is B(x), which comes from the first component of the dependent pair for x.

Define r(x)=snd(p x). The assigned type is R(x,fst(p x)), hence R(x,f(x)) by computation of the definition of f. After abstraction r has type Π x:A.R(x,f(x)).

The pair ⟨f,r⟩ is therefore a term of Σ f:(Π x:A.B(x)).Π x:A.R(x,f(x)). This gives the chosen function and its proof family without an extra choice axiom. For an explicit input witness pair, both projections compute to its supplied components.

The construction is possible because the premise gives data-level dependent pairs for each x. If the premise gives only a proof of restricted proposition-level existence, projecting an actual y is unavailable without another permitted rule. Related reading: [Products, dependent pairs and coproducts](https://people.csail.mit.edu/jgross/tmp/hott-book-html/hott-html.html), [Data witnesses and type-level choice](https://people.csail.mit.edu/jgross/tmp/hott-book-html/hott-html.html). Extract a witness and evidence from the same data pair at each input.

27

Show what a constructive double-negation proof provides

With ¬U defined as U→0, suppose h:(A+¬A)→0. Define n:A→0 by n(a)=h(inl a). Every application has type 0 because inl a belongs to the sum on which h acts.

Then inr n:A+¬A. Applying h again gives h(inr n):0. Abstracting over h yields a term of ((A+¬A)→0)→0, which is the displayed double-negated statement.

The abstraction has a function type accepting a refuter. Its body produces a contradiction from that refuter, without being a constructor of the unnegated sum. Eliminating double negation in general would need an additional principle beyond this proof.

If a certified decision procedure on the specified proposition returns either a witness a:A or a verified refuter n:A→0, return inl a or inr n according to its branch. The separate decision premise yields a term of the sum directly. Related reading: [Products, dependent pairs and coproducts](https://people.csail.mit.edu/jgross/tmp/hott-book-html/hott-html.html), [The intuitionistic excluded-middle countermodel](https://lclem.github.io/logic_course/book/logic_book_2020-03-15.pdf), [Data witnesses and type-level choice](https://people.csail.mit.edu/jgross/tmp/hott-book-html/hott-html.html), [Lean's proof irrelevance and implication proofs](https://lean-lang.org/theorem_proving_in_lean4/Propositions-and-Proofs/), [Reflection and decidability instances](https://lean-lang.org/doc/reference/latest/Tactic-Proofs/Tactic-Reference/). Constructing a double-negation term gives a refuter-to-false function, whereas a decision gives a witnessed constructor.

28

Track universes when forming dependent types

Use Nat:Type_0. A product whose domain is Nat and whose codomain is Nat belongs to Type_0 by the stated product formation. A small indexed family B supplies a type B(n):Type_0 for every n.

The type Nat→Type_0 of such a family lies in Type_1 because Type_0 itself is an object of Type_1. This universe level describes the whole collection of family values, while each fiber remains small by hypothesis.

For a type-polymorphic function the type Π A:Type_0.A→A has a binder ranging over small types. The binder domain Type_0 has type Type_1 and each A→A is in Type_0, so the full product is in Type_1 by the max-level product rule.

The hierarchy assigns Type_i to Type_(i+1), and any declared cumulativity moves upward. No formation rule gives Type_i:Type_i. All the sample terms fit the displayed levels without using a self-membership judgment. Related reading: [Dependent products, family arguments and universes](https://people.csail.mit.edu/jgross/tmp/hott-book-html/hott-html.html), [Polymorphic types and elaboration in Lean](https://lean-lang.org/theorem_proving_in_lean4/Dependent-Type-Theory/), [Normalization and natural-number canonicity](https://people.csail.mit.edu/jgross/tmp/hott-book-html/hott-html.html). Use the specified max-level product rule and the universe's own next-higher membership.

29

Check what a chosen eliminator permits

For naturals the declared inductive eliminator accepts a type-family motive. For example choose P(n)=Vec(Bool,n). Give nil:P(0) and the step taking v:P(n) to cons true v:P(succ n). Induction produces a vector at each n.

By its computation the zero branch returns nil and a successor elaborates to an actual cons term on the previous vector. That output is data, allowed because the chosen natural eliminator ranges over the given type universe.

For a proposition-only existential ex:Ex(P) and Q:Prop, a branch Π x:A.P(x)→Q gives a valid term of Q through its stated eliminator. A proposition-valued conclusion such as nonemptiness can fit this rule.

An expression eliminating ex directly into an arbitrary data type A has a motive outside the displayed rule. Matching the existence constructor in surface syntax does not independently authorize that motive. The witness pair or an explicitly permitted data-recovery principle supplies a different term. Related reading: [Natural recursion and dependent induction](https://people.csail.mit.edu/jgross/tmp/hott-book-html/hott-html.html), [Data witnesses and type-level choice](https://people.csail.mit.edu/jgross/tmp/hott-book-html/hott-html.html), [Equality substitution and the existential target](https://lean-lang.org/theorem_proving_in_lean4/Quantifiers-and-Equality/), [Indexed vector constructor cases in Lean](https://lean-lang.org/theorem_proving_in_lean4/Induction-and-Recursion/). The natural eliminator targets data families in its permitted universe. The chosen existential eliminator has a proposition-only target.

30

Explain the role of termination

In structural recursion on a natural, a constructor branch may call the same function on the constructor's immediate predecessor. A computation starting at any closed numeral can therefore revisit this rule only finitely often, because each call decreases the natural value.

In addL the base supplies the final result and the only recursive branch refers to the smaller first argument. An open variable may block which branch fires, without defining a separate nonterminating computation. This is an example of a structurally accepted definition.

Suppose unrestricted recursive term formation admitted loop:0 with body loop itself. Then there would already be a closed inhabitant of the empty type in the logic, whether or not any evaluation produced a constructor. Empty elimination would turn that inhabitant into a term of any target type.

A system can keep a nonterminating executable outside transparent total proof construction, for example by limiting unfolding and allowing its declared logical inhabitance only under separate conditions. Existence of an executable partial function does not license treating it as an arbitrary transparent proof term. Related reading: [Natural recursion and dependent induction](https://people.csail.mit.edu/jgross/tmp/hott-book-html/hott-html.html), [Indexed vector constructor cases in Lean](https://lean-lang.org/theorem_proving_in_lean4/Induction-and-Recursion/), [Structural recursion and partial definitions](https://lean-lang.org/doc/reference/latest/Definitions/Recursive-Definitions/), [Normalization and natural-number canonicity](https://people.csail.mit.edu/jgross/tmp/hott-book-html/hott-html.html). Structural recursion decreases on the declared argument; execution with unrestricted recursion has separate logical conditions.

31

Separate normalization, canonicity and a finite reduction trace

At the declared addL equations, addL(succ 0,succ 0) reduces to succ(addL(0,succ 0)) and then to succ(succ 0). This particular well-typed reduction reaches a constructor numeral in two displayed steps.

A normalization property says every well-typed term in the specified calculus has a reduction to normal form. Strong normalization makes the additional claim that every reduction sequence terminates. Neither global property follows from the finite trace of one closed term.

Natural-number canonicity says each closed term of type Nat computes to a numeral in the specified pure calculus. To infer it from normalization, classify closed normal terms of type Nat. In the fragment with only the stated inductive primitives and no additional opaque Nat constants, the relevant typing and normal-form classification leaves constructors.

If the normal form is zero then it is already a numeral. If it is succ u, apply the closed-normal-form classification recursively to u. Neutrals from unfilled variables cannot supply a closed Nat case, and a recursor on a constructor would still reduce. Added opaque constants or different reduction rules require a fresh canonicity argument. Related reading: [Natural recursion and dependent induction](https://people.csail.mit.edu/jgross/tmp/hott-book-html/hott-html.html), [Structural recursion and partial definitions](https://lean-lang.org/doc/reference/latest/Definitions/Recursive-Definitions/), [Normalization and natural-number canonicity](https://people.csail.mit.edu/jgross/tmp/hott-book-html/hott-html.html). The canonical-form consequence requires normalization and the no-closed-neutral classification for the given pure rule set.

32

Check types with explicit arguments and elaborate omitted ones

Fix a universe level i and a type parameter A:Type_i. The variable rule under x:A gives x:A, so abstraction produces λx:A.x of type A→A. Abstract again over A to obtain a term of Π A:Type_i.A→A.

When the type parameter is explicit, applying this polymorphic identity to Nat and then to 3 produces an inhabitant of Nat. Applying it instead to Bool and true produces an inhabitant of Bool. Each application supplies the correct substituted result type.

An empty list literal may elaborate as List.nil with inferred parameter Nat when List Nat is expected, or with parameter Bool when List Bool is expected. The unannotated absence of elements supplies no type parameter by itself. An expected type or explicit annotation determines the intended core application.

The core checker receives the resolved term, including implicit arguments introduced by elaboration. It verifies its type and conversion obligations using the rules for the resulting term. Elaboration can search for missing data, while the stated typing derivation checks a specific resolved expression. Related reading: [Typing, conversion and capture avoidance](https://people.csail.mit.edu/jgross/tmp/hott-book-html/hott-html.html), [Dependent products, family arguments and universes](https://people.csail.mit.edu/jgross/tmp/hott-book-html/hott-html.html), [Polymorphic types and elaboration in Lean](https://lean-lang.org/theorem_proving_in_lean4/Dependent-Type-Theory/), [Tactic instructions and the checked term](https://lean-lang.org/theorem_proving_in_lean4/Tactics/), [Proof checking under declared assumptions](https://lean-lang.org/doc/reference/latest/ValidatingProofs/). Elaboration solves surface omissions before the core checker examines resolved terms.

33

Read a proof checker’s judgment

In a context p:P×Q, the first projection fst p has type P. Abstracting over p gives λp.fst p of type (P×Q)→P. A checker establishes the premise by the variable and projection rules and closes the context through function introduction.

If the declared target type's P component is expressed by a different definitionally equal type, the checker can use conversion. This appeals to the calculus's definitional relation. A tactic can choose this same proof by inspecting the goal, yet the typing obligation concerns the final term.

Checking a new declaration requires its declared type to be well formed and its body to have that type under the existing environment. Imported constants are resolved through that environment. If there is a declared axiom a:P, the constant rule can check a at P using that declaration.

Type check each application from the inside outTwo well-typed applications; An argument must have the exact domain type. If it matches, the codomain is the result type.Type check each application from the inside outContext: f:A→B, g:B→C, a:A, b:B.ApplicationFunction typeArgumentResult(f a)A→BAB(g (f a))B→CBCInner f(a) returns B, which is the input type required by g; result C.Check the displayed term from its inner applications outward.
An argument must have the exact domain type. If it matches, the codomain is the result type.

The context and expression are explicit. This finite check verifies a typed certificate rather than searching for a term of a desired type.

Exact derived type
QuantityExact result
Term(g (f a))
Output typeC
First failed applicationNone
Domain/argument comparisonInner f(a) returns B, which is the input type required by g; result C.
Exact inputs and supporting calculations
Declared inputs
ParameterValue
term["app","g",["app","f","a"]]
Application derivation
ApplicationFunction typeArgument typeResult
(f a)A→BAB
(g (f a))B→CBC

Such acceptance says the term derives its type in the declared environment. The mathematical interpretation includes the axiom used. The small example has an explicit projection proof, so it uses the product rules and its named premises, without adding an axiom of P. Related reading: [Typing, conversion and capture avoidance](https://people.csail.mit.edu/jgross/tmp/hott-book-html/hott-html.html), [Products, dependent pairs and coproducts](https://people.csail.mit.edu/jgross/tmp/hott-book-html/hott-html.html), [Polymorphic types and elaboration in Lean](https://lean-lang.org/theorem_proving_in_lean4/Dependent-Type-Theory/), [Lean's proof irrelevance and implication proofs](https://lean-lang.org/theorem_proving_in_lean4/Propositions-and-Proofs/), [Indexed vector constructor cases in Lean](https://lean-lang.org/theorem_proving_in_lean4/Induction-and-Recursion/), [Tactic instructions and the checked term](https://lean-lang.org/theorem_proving_in_lean4/Tactics/), [Proof checking under declared assumptions](https://lean-lang.org/doc/reference/latest/ValidatingProofs/), [Normalization and natural-number canonicity](https://people.csail.mit.edu/jgross/tmp/hott-book-html/hott-html.html), [Introduction and elimination in proof rules](https://builds.openlogicproject.org/open-logic-complete.pdf#page=142). Core checking is under the actual environment. A declared axiom is a premise of the resulting proof.

34

Compare tactic syntax and the constructed term

Consider the goal P→Q→P for P,Q:Prop, with arrows associating to the right. The explicit Lean proof term fun hp hq => hp has expected type P→(Q→P). The first binder has type P, and the second has type Q.

The tactic form is a by block with intro hp hq followed by exact hp. Introducing hp changes the goal to Q→P in the context hp:P. Introducing hq leaves goal P in the context hp:P and hq:Q.

The term hp is a proof of the final goal by the variable rule. Discharging hq gives Q→P, and discharging hp gives the original goal. Unused hq is legitimate because weakening preserved the proof of P in the enlarged context.

The assistant elaborates the displayed syntax to a term whose type satisfies the same kernel checks. The tactic instructions are a method for producing the term. A source-level proof script alone does not replace term formation and type verification. Related reading: [Lean's proof irrelevance and implication proofs](https://lean-lang.org/theorem_proving_in_lean4/Propositions-and-Proofs/), [Tactic instructions and the checked term](https://lean-lang.org/theorem_proving_in_lean4/Tactics/), [Proof checking under declared assumptions](https://lean-lang.org/doc/reference/latest/ValidatingProofs/). Each tactic step transforms the local goal and the resulting proof must check at the exact target.

35

Rewrite a dependent target without erasing its index

Given h:Id_Nat(m,n) and v:Vec(A,m), the expression transport_(λk.Vec(A,k))(h,v) inhabits Vec(A,n). Every endpoint used in the family is specified by the type of h.

An eliminator-based rewriting command can build the same application of identity elimination, oriented from the original index m to the requested index n. Switching the direction would require sym(h) and a source value in the opposite fiber.

For h=refl_m and n definitionally m, the transport reduces to v. For an abstract h whose term cannot be reduced, the target type still follows from the typing rule, with the transport retained as part of the term.

Indexed data retain their index in the type of the transformed value. The proof justifies the exact change of fiber. It is not an untyped replacement of numeral names, and it does not make all arrays definitionally have a chosen length. Related reading: [Identity elimination, symmetry and path composition](https://people.csail.mit.edu/jgross/tmp/hott-book-html/hott-html.html), [Transport and application to equality proofs](https://people.csail.mit.edu/jgross/tmp/hott-book-html/hott-html.html), [Equality substitution and the existential target](https://lean-lang.org/theorem_proving_in_lean4/Quantifiers-and-Equality/), [Tactic instructions and the checked term](https://lean-lang.org/theorem_proving_in_lean4/Tactics/). Transport uses the given orientation of the path, and computation on reflexivity preserves the original value.

36

Separate Boolean calculation from a reflected proof

Define isZero:Nat→Bool by isZero(0)≡true and isZero(succ n)≡false. The Boolean computation is total by case analysis on the natural number. Its intended semantic property is the equivalence between isZero(n)=true and n=0.

At n=0 both equality types are reflexive. The two implication directions can return the corresponding reflexive proof. At n=succ k, a premise isZero(n)=true would give false=true, ruled out by Boolean constructor disjointness.

In the opposite successor branch a premise succ k=0 is ruled out by natural constructor disjointness. Use empty elimination to get the required conditional result in either impossible premise case. Constructor disjointness follows by transporting from a family distinguishing the two constructors, such as unit at one and the empty type at the other.

At n=3 the calculation gives false. If 3=0, the proved reverse implication would give isZero(3)=true, hence false=true. Constructor disjointness rules this out, giving 3≠0. One needs the proved correspondence and the checked finite computation. A raw unverified Boolean result alone does not inhabit the equality proposition. Related reading: [Natural recursion and dependent induction](https://people.csail.mit.edu/jgross/tmp/hott-book-html/hott-html.html), [Reflection and decidability instances](https://lean-lang.org/doc/reference/latest/Tactic-Proofs/Tactic-Reference/), [Normalization and natural-number canonicity](https://people.csail.mit.edu/jgross/tmp/hott-book-html/hott-html.html), [Finite certificates and decidable checking](https://builds.openlogicproject.org/open-logic-complete.pdf). Proof of the reflection equivalence and constructor discrimination justify reading the calculated decision.

37

Use reflexivity only with the declared conversion

Define the Lean-style function addL : Nat → Nat → Nat with equations | 0, n => n and | Nat.succ m, n => Nat.succ (addL m n). Only the first input is inspected to select a recursive branch. These are the lesson's definitions.

The equation addL 0 n = n is closed by reflexivity even for a variable n, because unfolding the first equation makes its two endpoints definitionally equal. Similarly addL (Nat.succ 0) n reduces to Nat.succ n through the successor and zero equations.

For the true statement addL n 0 = n at a variable n, the first argument is neither a displayed zero nor a displayed successor. The recursor remains blocked. Reflexivity is not justified by the equations for this open term.

Induction supplies the missing proof. The base checks by computation. In the successor case map the induction equality through successor and use the stated equations to check both endpoints. This argument concerns addL and does not rely on guessing how a built-in addition recurses. Related reading: [Natural recursion and dependent induction](https://people.csail.mit.edu/jgross/tmp/hott-book-html/hott-html.html), [Equality substitution and the existential target](https://lean-lang.org/theorem_proving_in_lean4/Quantifiers-and-Equality/), [Indexed vector constructor cases in Lean](https://lean-lang.org/theorem_proving_in_lean4/Induction-and-Recursion/), [Structural recursion and partial definitions](https://lean-lang.org/doc/reference/latest/Definitions/Recursive-Definitions/), [Normalization and natural-number canonicity](https://people.csail.mit.edu/jgross/tmp/hott-book-html/hott-html.html). The permitted reflexivity examples depend only on the stated first-argument equations and not on library addition.

38

Use indexed types to state a scientific unit invariant

Represent a physical dimension by d=(ℓ,m,t)∈ℤ³, the exponents of chosen length, mass and time bases. A quantity of dimension d has type Qty(d) and a magnitude in a declared common unit scale. Addition is typed Qty(d)×Qty(d)→Qty(d).

Define multiplication at dimensions d,e to return Qty(d+e) and division by a nonzero magnitude of dimension e to return Qty(d−e). The corresponding numerical operations on magnitudes are well defined under the declared scaling and nonzero divisor.

Length has index (1,0,0) and time (0,0,1), so their quotient has (1,0,−1). For 12 metres divided by 3 seconds, the result is magnitude 4 in metres per second at that index. Two velocities in the same unit scale can be added using the equal index.

Check the exact dimension before computing a magnitudeAdd two lengths at the same scale; This explorer spells out mass, length and time. The manuscript writes its first two coordinates in the order length, mass.Check the exact dimension before computing a magnitudeQuantityMass MLength LTime TMagnitudeLeft0103Right0102Result0105Explorer order M,L,T swaps the first two manuscript coordinates.Addition requires equal dimensions and a common coherent scale.
This explorer spells out mass, length and time. The manuscript writes its first two coordinates in the order length, mass.

Dimension agreement permits addition after magnitudes use a common coherent scale. Products multiply magnitudes and add their dimension vectors.

Exact quantity indices
QuantityExact result
Operationadd
Coordinate orderM,L,T
Input dimensions[0, 1, 0] and [0, 1, 0]
Operation availableTrue
Result dimensions[0, 1, 0]
Result magnitude5
Exact inputs and supporting calculations
Declared inputs
ParameterValue
opadd
a[3,[0,1,0]]
b[2,[0,1,0]]

Dimension agreement is a necessary type condition for this addition. A common numerical scale and a physical meaning for the operation are also required. A type system that tracks only dimension does not by itself distinguish all different kinds of observables with the same dimension. Related reading: [Static unit expressions and dimension checks](https://typesatwork.imm.dtu.dk/material/TaW_Paper_TypesAtWork_Kennedy.pdf), [Quantity scales and coherent derived SI units](https://www.bipm.org/documents/20126/41483022/SI-Brochure-9.pdf/fcf090b2-04e6-88cc-1149-c3e029ad8232). Dimension exponent arithmetic and normalization of the numerical unit scale are distinct requirements.

39

Distinguish a certificate from trust in its producer

Take the claim addL(2,1)=3 in the declared natural-number calculus. A candidate certificate is a finite sequence of correctly typed reductions ending at the numeral 3. An independent checker validates each local contraction and the exact start and end terms.

The certificate begins with the successor equation, giving succ(addL(1,1)), then succ(succ(addL(0,1))), and finally succ(succ 1)=3. Check each redex against the recursion scheme and leave the enclosing succ constructors unchanged.

Soundness of this certificate checker follows because every accepted step is a permitted definitional equality, and equality composes through the finite sequence. The core proof can then use a reflexive equality with endpoints convertible by that sequence. An external producer need only emit evidence.

The result relies on correct verification and the declared rules and imported constants. A heuristic or search engine may fail to find a certificate, without making a discovered valid certificate less checkable. A purported proof with an unchecked assertion adds that assertion to the logical trust requirements. Related reading: [Tactic instructions and the checked term](https://lean-lang.org/theorem_proving_in_lean4/Tactics/), [Proof checking under declared assumptions](https://lean-lang.org/doc/reference/latest/ValidatingProofs/), [Reflection and decidability instances](https://lean-lang.org/doc/reference/latest/Tactic-Proofs/Tactic-Reference/), [Finite certificates and decidable checking](https://builds.openlogicproject.org/open-logic-complete.pdf). A certificate attests to the actual formal statement only when its exact local proof rules and declared assumptions are checked.

Check types and proof terms, compare scope and indices, and work through concrete proof certificates.

Beta reduction substitutes a term at the bound variable

Rename y before substituting the free y

Reduce the root redex without capturing a free variableRename y before substituting the free y; The intermediate row shows the binding-preserving rename before substitution when needed. The left child is λx.λy.x and the right child is free y. Renaming the inner y binder keeps the inserted y free.Reduce the root redex without capturing a free variablePhaseTerm or conditionOriginal(λx. λy. x) yRoot redexYes; argument yα-renaming(λx. λy′. x) yAfter at most one stepλy′. yFree before: y · Free after: yFunction binder y at left/body; free y at right.The x bound by λx occurs at left/body/body; substitute free y there.
The intermediate row shows the binding-preserving rename before substitution when needed. The left child is λx.λy.x and the right child is free y. Renaming the inner y binder keeps the inserted y free.

A free variable of an argument must remain free wherever it is inserted. Renaming a conflicting inner binder changes the binding names without changing their meaning.

Exact β-reduction
QuantityExact result
Variables usedx, y
Free variables beforey
Root beta redexTrue
Intermediate after α-renaming(λx. λy′. x) y
One-step resultλy′. y
Free variables aftery
Exact inputs and supporting calculations
Declared inputs
ParameterValue
term["app",["lam","x",["lam","y","x"]],"y"]

An index inhabits Fin(n) only inside the declared range

Read the last valid index

Prove the index bound before using the lookupRead the last valid index; Green marks an actual admissible slot. Failing the bound blocks formation of a Fin(n) argument.Prove the index bound before using the lookup492Each declared slot has one index and one value.i=0i=1i=2Requested i=2 · Required 0≤i<3 · AdmittedSelected element 2.
Green marks an actual admissible slot. Failing the bound blocks formation of a Fin(n) argument.

A rejected index is a type-level precondition failure. An empty vector has no valid index, so there is no value to fetch and no missing or reserved data value.

Exact index certificate
QuantityExact result
Vector[4, 9, 2]
n3
i2
Forms Fin(n)True
Value2
Exact inputs and supporting calculations
Declared inputs
ParameterValue
xs[4,9,2]
i2

Appending indexed vectors carries a length equation

Append two nonempty vectors

Append by recursion on the first vectorAppend two nonempty vectors; The base case returns the entire right vector. Each step adds one left constructor and one to the result length. Recursive descent removes the left head until nil; the rows show each return while rebuilding.Append by recursion on the first vectorLeft lengthRight lengthReturned lengthReturned vector033[7, 8, 9]134[2, 7, 8, 9]235[1, 2, 7, 8, 9]Unwinding recursion on the left vector0 + m = m; (n+1)+m = (n+m)+1Final vector: [1, 2, 7, 8, 9] · length 5Descent: [1, 2] → [2] → nil → return right vector
The base case returns the entire right vector. Each step adds one left constructor and one to the result length. Recursive descent removes the left head until nil; the rows show each return while rebuilding.

The convention reduces the left index first. A transport for a different orientation of the length equality must be justified explicitly.

Exact appended vector
QuantityExact result
Left[1, 2]
Right[7, 8, 9]
Concatenation[1, 2, 7, 8, 9]
Result length2 + 3 = 5
Exact inputs and supporting calculations
Declared inputs
ParameterValue
xs[1,2]
ys[7,8,9]
Recursive results
Left lengthRight lengthOutput lengthOutput values
033[7, 8, 9]
134[2, 7, 8, 9]
235[1, 2, 7, 8, 9]

Transport uses equality of indices rather than unchecked casting

Reflexivity at length two

Transport indexed data only with an equality proofReflexivity at length two; Actual transport along refl preserves the elements. The dashed line marks a rejected transport.Transport indexed data only with an equality proofVec at index 2[1, 2]reflTarget index 2[1, 2]Both closed numeral indices are 2.Reflexivity transports the same value.
Actual transport along refl preserves the elements. The dashed line marks a rejected transport.

Reflexivity supplies identity only for the same numeral. It cannot supply an equality between distinct closed numerals.

Exact transport decision
QuantityExact result
Source index2
Target index2
Given witnessrefl
Certificate acceptedTrue
Transported result[1, 2]
Exact inputs and supporting calculations
Declared inputs
ParameterValue
xs[1,2]
m2
proofrefl

Dimension-indexed operations make illegal sums visible

Add two lengths at the same scale

Check the exact dimension before computing a magnitudeAdd two lengths at the same scale; This explorer spells out mass, length and time. The manuscript writes its first two coordinates in the order length, mass.Check the exact dimension before computing a magnitudeQuantityMass MLength LTime TMagnitudeLeft0103Right0102Result0105Explorer order M,L,T swaps the first two manuscript coordinates.Addition requires equal dimensions and a common coherent scale.
This explorer spells out mass, length and time. The manuscript writes its first two coordinates in the order length, mass.

Dimension agreement permits addition after magnitudes use a common coherent scale. Products multiply magnitudes and add their dimension vectors.

Exact quantity indices
QuantityExact result
Operationadd
Coordinate orderM,L,T
Input dimensions[0, 1, 0] and [0, 1, 0]
Operation availableTrue
Result dimensions[0, 1, 0]
Result magnitude5
Exact inputs and supporting calculations
Declared inputs
ParameterValue
opadd
a[3,[0,1,0]]
b[2,[0,1,0]]

A completed term has a type only if application checks its argument

Two well-typed applications

Type check each application from the inside outTwo well-typed applications; An argument must have the exact domain type. If it matches, the codomain is the result type.Type check each application from the inside outContext: f:A→B, g:B→C, a:A, b:B.ApplicationFunction typeArgumentResult(f a)A→BAB(g (f a))B→CBCInner f(a) returns B, which is the input type required by g; result C.Check the displayed term from its inner applications outward.
An argument must have the exact domain type. If it matches, the codomain is the result type.

The context and expression are explicit. This finite check verifies a typed certificate rather than searching for a term of a desired type.

Exact derived type
QuantityExact result
Term(g (f a))
Output typeC
First failed applicationNone
Domain/argument comparisonInner f(a) returns B, which is the input type required by g; result C.
Exact inputs and supporting calculations
Declared inputs
ParameterValue
term["app","g",["app","f","a"]]
Application derivation
ApplicationFunction typeArgument typeResult
(f a)A→BAB
(g (f a))B→CBC

Worked examples

Check a dependent context

In Γ containing n:Nat and v:Vec Bool n, derive the type of v and of the pair ⟨n,v⟩. Explain why typing v does not assert n=0 or n=1.

  1. The variable n has type Nat. Consequently the indexed family at n gives the well-formed type Vec Bool n. From the declaration of v the variable rule now derives v:Vec Bool n.
  2. For a dependent pair use the family B(k)=Vec Bool k. The first component n has its required type Nat. The second is v at B(n), the fiber determined by that chosen component.
  3. The introduction rule gives ⟨n,v⟩:Σ k:Nat.Vec Bool k. This judgment is valid across admissible substitutions for the two context entries. The type of v changes with the value assigned to n under such a substitution.
  4. The typing derivation contains no premise or conclusion with n=0 or n=1. It expresses a length relation in the type, and the symbolic numerical value of the length is retained.

The judgments are v:Vec Bool n and ⟨n,v⟩:Σ k:Nat.Vec Bool k in the stated context.

Avoid capture during substitution

Substitute the free variable y for x in the function λy:A.x, where both variables initially have type A. Derive the standard α-renamed expression and evaluate it on z:A.

  1. The original abstraction λy:A.x has bound variable y and free variable x. The replacement is the free y from the outer context. Substitution must preserve that free occurrence.
  2. Choose y′ fresh for the context and rewrite the abstraction by α conversion as λy′:A.x. The bound name y′ occurs in neither the replacement nor the original free body.
  3. Substituting [y/x] now gives λy′:A.y. The body has type A by the outer declaration of y. Abstracting over y′ gives a function A→A.
  4. On application to z:A, the β step replaces bound y′ by z throughout the body y. There is no occurrence to replace, so the result is y. The choice of input z does not affect the constant output.

Rename the bound y first. The result is λy′:A.y and it evaluates at z to the original free y.

Eliminate a product explicitly

For P,Q:Prop give a function P∧Q→Q∧P and trace its reduction on ⟨p,q⟩. Supply the type of each selected component.

  1. Assume w:P∧Q and use the product interpretation of conjunction in the chosen proof universe. The first projection gives fst w:P and the second gives snd w:Q.
  2. The target conjunction is Q∧P, so its first component must prove Q and its second must prove P. The constructor forms ⟨snd w,fst w⟩ with this assigned type.
  3. Abstracting over w gives a function P∧Q→Q∧P. On the explicit pair ⟨p,q⟩ with p:P and q:Q, β reduction introduces those two particular projection computations.
  4. Their equations give fst ⟨p,q⟩≡p and snd ⟨p,q⟩≡q. Thus the result is ⟨q,p⟩, with the same target type verified by its exact component order.

Use w↦⟨snd w,fst w⟩. Applied to ⟨p,q⟩ it gives ⟨q,p⟩.

Evaluate the left-recursive addition

Reduce addL(succ(succ 0), succ 0) one defining step at a time. Indicate which step makes the first argument zero and state the final numeral.

  1. Write one as succ 0 and two as succ(succ 0). The first argument is a successor, so the first step is succ(addL(succ 0,succ 0)).
  2. In the inner call the first argument is still a successor. The next step gives succ(succ(addL(0,succ 0))). The first input of that remaining call has become zero.
  3. Apply the defining zero rule, replacing addL(0,succ 0) by succ 0. The surrounding two successor constructors stay in their original order.
  4. The final result is succ(succ(succ 0)). Every displayed expression is a term of Nat, and each computation uses the recursor equation selected by the first argument.

The term reduces to succ(succ(succ 0)), the numeral three.

Check the type of the second projection

For B(n)=Vec Bool n, take p=⟨2,cons true (cons false nil)⟩. Type both projections and show the second one computes to a specific vector at the correct index.

  1. The inner cons false nil has length one. Prepending true gives cons true (cons false nil) of type Vec Bool 2. This exactly matches B(2) for the selected family.
  2. The dependent-pair introduction produces p:Σ n:Nat.Vec Bool n. Its first projection fst p is assigned Nat and its computation yields 2.
  3. The second projection has type Vec Bool(fst p). Since the first projection computes to 2, that type is definitionally equal to Vec Bool 2. The second projection computes to the stored vector cons true (cons false nil) in that exact fiber.
  4. Thus the returned vector has two Boolean entries true and false in that order. The second projection's index comes from the first projected value, not from a separate guessed index.

fst p:Nat computes to 2. snd p:Vec Bool(fst p) computes to the displayed two-element vector.

Index a concrete vector safely

For v=[false,true,false] at length 3, reduce get v (succ zero) by its declared indexed branches. State the required length on each recursive call.

  1. Represent v as cons false (cons true (cons false nil)) at length three. The indicated input index is the successor constructor at Fin(3) applied to zero in Fin(2).
  2. The get rule for a successor index on a nonempty vector consumes the head and applies get at the tail's index. The tail cons true (cons false nil) has length two and its supplied index is now zero:Fin(2).
  3. At the next call the zero-index branch on a nonempty vector returns its head, which is true. There is no additional recursive call on the length-one suffix.
  4. The initial and recursive calls have matching vector and index lengths. In particular the branch never tries to use the original Fin(3) argument directly with the length-two tail.

The result is true. The recursive call uses the length-two tail and its zero index.

Derive the length at an append branch

In the successor branch with a head a and tail xs:Vec A m, type cons a (append xs ys) for ys:Vec A n. Reduce the expected index under addL to compare it.

  1. Let xs:Vec A m and ys:Vec A n. By the recursive premise append xs ys has type Vec A(addL(m,n)). The head a is an inhabitant of A.
  2. Applying cons a to that recursive result gives type Vec A(succ(addL(m,n))). This uses the indexed cons constructor at its exact predecessor length.
  3. The successor branch is called with original input vector cons a xs, of length succ m. Its stipulated result index is addL(succ m,n). The first-argument recursion reduces it to succ(addL(m,n)).
  4. Conversion therefore matches the assigned type of the cons result to the target. No arithmetic equality proof is necessary for this explicit constructor reduction.

Both indexes reduce to succ(addL(m,n)), so the cons expression has the successor branch type.

Transport a concrete value at a reflexive path

Let h=refl_2 and v:Vec Bool 2. Type transport (λn.Vec Bool n) h v and compute it. Contrast the term form when h is an abstract variable between n and m.

  1. Let B(k)=Vec Bool k. The input v has B(2), and h=refl₂ has identity type Id_Nat(2,2). The transport rule moves an inhabitant from the fiber of the first endpoint to the fiber of the second.
  2. Both endpoints are 2 in this instance. The result's assigned type is B(2)=Vec Bool 2. Identity elimination computes its reflexive branch and returns the supplied v.
  3. For an abstract identity h:Id_Nat(n,m) and u:B(n), the same construction yields transport_B(h,u):B(m). The typing conclusion follows from the motive and does not require simplifying h.
  4. If h is not displayed as reflexive or definitionally reducible to it, that computation rule need not apply. The retained transport records exactly which propositional equality justified the changed index.

Transport at refl₂ checks at Vec Bool 2 and reduces to v. For abstract h it retains the transport term.

Use a pointwise view of an equality of functions

Given h:Id_(Nat→Nat)(f,g), produce the proof of Id_Nat(f(3),g(3)) by congruence with evaluation. Compute the result when h is reflexive.

  1. Define ev₃:(Nat→Nat)→Nat by ev₃(k)=k(3). The expression is well typed since the displayed function domain is Nat for every candidate k.
  2. Given h:Id_(Nat→Nat)(f,g), use ap_(ev₃)(h). The result is Id_Nat(ev₃(f),ev₃(g)). Unfolding ev₃ gives the requested endpoints f(3) and g(3).
  3. If h=refl_f, the endpoints are both ev₃(f). The computation rule for congruence gives refl_(ev₃(f)), which is definitionally refl_(f(3)).
  4. No reverse conversion from pointwise to functional equality was invoked. This direction uses equality elimination applied to one ordinary evaluation function.

Apply congruence to evaluation at 3. At a reflexive input the result is refl_(f 3).

Extract a typed witness function

For each n suppose p(n):Σ m:Nat.Id_Nat(m,succ n). Construct F and evidence that F(n)=succ n using p's projections, then evaluate in the explicit witness example p(n)=⟨succ n,refl⟩.

  1. The input family gives p(n) at Σ m:Nat.Id_Nat(m,succ n). Its first projection is a natural number. Define F:Nat→Nat by abstracting that first projection over n.
  2. The second projection has type Id_Nat(fst(p n),succ n). Substitution of the definition of F yields Id_Nat(F(n),succ n). Abstracting over n gives the requested family e.
  3. In the explicit example p(n)=⟨succ n,refl_(succ n)⟩, the first projection computes to succ n. The second computes to refl_(succ n), which now checks because both endpoints reduce to succ n.
  4. This procedure returns a witness function because the premise supplies dependent pairs as data. Each value of the function and its proof are determined from one supplied pair at the same n.

Take F(n)=fst(p n) and e(n)=snd(p n). In the explicit pair example they compute to succ n and refl.

Check a proof term produced by two tactics

For P,Q:Prop give a Lean term and a by block for P→Q→P, using intro and exact. Show the type of the term after each introduction.

  1. The expected type is P→(Q→P). Under the first binder hp:P, the remaining target is Q→P. This is the state of the tactic proof after introducing the first premise.
  2. Under the second binder hq:Q the target is P. The term hp still has type P in the enlarged context by weakening. Giving it directly solves the remaining goal.
  3. In the term form, abstraction over hq yields a term Q→P under hp:P. Abstraction over hp yields the full assigned type. Using an unused hq is allowed by the context rules.
  4. The two-line tactic sequence asks for these introductions and then that exact final term. The mathematical proof term and the tactic-generated term have the same checking obligation at P→Q→P.

Use fun hp hq => hp, or a by block with intro hp hq followed by exact hp.

Compare two same-dimension quantities

Give the dimension index of length divided by time using a tuple ordered length, mass, time. Check the type of adding two values at that velocity index and explain why numerical units still require a common scale.

  1. Length has dimension vector (1,0,0) and time has (0,0,1) in the stated base order. Division subtracts the denominator's dimension coordinate by coordinate.
  2. The result is (1,0,−1). Both velocity quantities therefore inhabit Qty(1,0,−1), so the same-index addition accepts them and returns that same indexed type.
  3. If the first value is 3 m/s and the second is 36 km/h, the dimensions agree but raw numeric addition is inappropriate across the unit scales. Convert 36 km/h to 36·1000/3600=10 m/s.
  4. With both expressed in metres per second, the magnitudes add to 13 m/s when the physical operation is appropriate. The index verifies the shared dimension. Numerical normalization and the application meaning are separate premises.

Velocity has dimension (1,0,−1). Add two such values only after their numerical scales agree.

Try it yourself

  1. Classify Γ⊢n:Nat, Γ⊢Nat:Type_0, Γ⊢addL(0,n)≡n:Nat and Γ⊢p:Id_A(x,y). Explain which one supplies an equality proof term.

    Show the answer and reasoning

    They respectively type a term, type an object universe member, assert judgmental equality and give a term of an identity type.

    In Γ⊢n:Nat the term n has the natural-number type under the stated context. In Γ⊢Nat:Type_0 the object Nat is a type in the specified lower universe. The judgment Γ⊢addL(0,n)≡n:Nat compares two terms at Nat by definitional equality. It follows from reduction of the first argument of addL at zero. The judgment Γ⊢p:Id_A(x,y) assigns a type to p. Since that type is the identity type for x and y at A, p is the required explicit equality proof term. The third judgment can authorize a proof of a corresponding identity by conversion from reflexivity. The fourth already displays such a term as part of the judgment. These uses of equality have different rule premises.

  2. Assume x,y:A. Substitute y for the free x in λy:A.x, and show what goes wrong with naive textual substitution.

    Show the answer and reasoning

    The correct result is λz:A.y for a fresh z, which keeps the outer y free.

    Treat the binder y in λy:A.x as local to its body. The replacement y from the context is a different, free variable occurrence. A textual replacement under the binder would capture it. Choose a fresh z:A and rename the local binder. The original abstraction is α-equivalent to λz:A.x and keeps x as its free body. Substitute y for x in that expression to obtain λz:A.y, still with the original free y. Its application to an arbitrary a:A returns that y. Naive substitution would produce λy:A.y, whose application returns its supplied argument. The behavior depends on the captured variable instead of remaining constant, so that expression is not the capture-avoiding result.

  3. For f:A→B and g:B→C derive the type of λx.g(f x) and evaluate it on a:A. Identify the two uses of implication elimination.

    Show the answer and reasoning

    The composition has type A→C and evaluates at a to g(f a).

    Extend the given context by x:A. From f:A→B and x:A derive f x:B by ordinary function application, which implements implication elimination for the first premise. From g:B→C and f x:B derive g(f x):C by the second function application. The output assigned to this body is independent of any choice of name for x. Abstract over x using the function introduction rule. This gives λx.g(f x):A→C, discharging exactly the newly added x and retaining f and g. Applying the abstraction to a:A substitutes a into its body. The computation gives g(f a), with final type C by the same two application judgments.

  4. Give the second case of the map A+B→B+A and show its reduction. Explain why a program containing only the first branch would not define the whole function.

    Show the answer and reasoning

    Send inr(b) to inl(b). The former B summand becomes the left B summand.

    An input inr(b) in A+B contains b:B. In the target B+A the left constructor expects a B term and the right constructor expects an A term. Thus the correct second branch is b↦inl(b):B+A. The computation rule of the sum eliminator reduces the whole map on inr(b) to that output. The first branch for inl(a) gives inr(a). These two clauses supply terms of the common codomain under their respective case contexts. Leaving out the second would leave every input built by inr without a case rule. A rule for a special empty summand would need an explicit elimination of its impossibility, which is not a premise for arbitrary B.

  5. In w₀≤w₁ force A only at w₁. Check the forcing of A, ¬A and A∨¬A at w₀ and state the hypothesis connecting the model to unprovability in intuitionistic logic.

    Show the answer and reasoning

    At w₀ none of A, ¬A, or A∨¬A is forced by the displayed model.

    Use the monotone valuation marking A true at w₁ only. The accessibility relation is reflexive and includes w₀≤w₁. At w₀ the atomic forcing rule therefore gives no proof of A. Negation requires that every accessible extension forcing A also force falsity. The extension w₁ forces A and, by premise, does not force falsity. This witness rules out forcing ¬A at w₀. Disjunction forcing at one world requires that one side be forced at that world. Neither side is forced at w₀, so their disjunction fails there. Intuitionistic propositional derivations are sound for these monotone Kripke models. A theorem would therefore be forced at w₀ in this model. The calculation rules out such a theorem in the bare constructive fragment.

  6. Prove addL(m,succ n)=succ(addL(m,n)) by induction on m, writing each base and step equality under the given recursion.

    Show the answer and reasoning

    Induct on the first argument m using congruence of successor in its step.

    For m=0, addL(0,succ n) reduces to succ n. The other endpoint succ(addL(0,n)) also reduces to succ n. The two endpoints match definitionally, so use reflexivity. For m=succ k, the left expression becomes succ(addL(k,succ n)). The right expression becomes succ(succ(addL(k,n))) by reducing its inner first argument. The induction premise proves addL(k,succ n)=succ(addL(k,n)). Apply the equality congruence of successor to obtain equality of the two displayed successor endpoints. Conversion identifies those endpoints with the exact step goal. The natural induction rule now gives the equality for arbitrary m and n, allowing n to remain fixed throughout the induction.

  7. Give one value of Fin(1) and show why the successor constructor cannot give another without an inhabitant of Fin(0). Check the result of indexing a full singleton.

    Show the answer and reasoning

    Zero is a valid Fin(1) value and indexes a singleton's head.

    Write 1=succ 0. The zero-index constructor with predecessor length zero gives zero:Fin(succ 0), hence Fin(1). The other constructor at this same result index would require i:Fin(0) as its argument. Fin(0) has no constructor, so this branch is impossible in the stated indexed eliminator. For any a:A the input singleton is cons a nil, of type Vec(A,1). The call get on that vector and the zero index is therefore well formed. The defining get rule for zero on a cons returns a. This is an exact constructor computation. It does not create a default value for an attempted Fin(0) call.

  8. For xs=nil and ys:Vec A n, show that returning ys has target Vec A(addL(0,n)). Explain the status of an opposite-order index for variable n.

    Show the answer and reasoning

    Returning ys checks after reducing addL(0,n) to n.

    With xs=nil, the first vector length is zero. Substituting that branch index into the append motive gives Vec A(addL(0,n)). The first argument of addL is visible as zero, so the type reduces to Vec A n. The original ys inhabits that type and can be the base result by conversion. For the opposite target orientation, the base type would be Vec A(addL(n,0)). At an arbitrary n the recursion has no zero or successor equation that fires on its first argument. A proof z(n):Id_Nat(addL(n,0),n) supplies an equality for that orientation. Transport along sym(z(n)) moves ys from Vec A n to Vec A(addL(n,0)) and gives a valid base term.

  9. Given p:Id_A(a,b), build symmetry using the identity eliminator and state the type of its base branch. Compute sym(refl_a).

    Show the answer and reasoning

    Use motive C(y,h)=Id_A(y,a) and base refl_a; the displayed reflexive case computes to refl_a.

    Fix a:A and consider y:A with h:Id_A(a,y). The desired reversed path in each case is a term of C(y,h)=Id_A(y,a). This type is well formed at every permitted y. At the base y=a, h=refl_a, the motive is Id_A(a,a). The reflexive term refl_a inhabits it by the identity introduction rule. Apply J with this motive and base to p:Id_A(a,b). The result has type C(b,p)=Id_A(b,a). This is the stated symmetry proof. When p is refl_a its eliminator applies the base computation and reduces to refl_a with the same endpoints. A general variable p remains an argument of the eliminator.

  10. Given h:Id_Nat(n,m), define forward and backward functions for Vec A using transport and sym h. Prove their forward-then-backward composite agrees pointwise with identity by J.

    Show the answer and reasoning

    Transport forward using h and backward using sym(h). Their stated composite is pointwise identity by path induction.

    For family B(k)=Vec A k and h:Id_Nat(n,m), define F(v)=transport_B(h,v) from B(n) to B(m). Define G(w)=transport_B(sym(h),w) from B(m) back to B(n). The asserted equation for each v:B(n) is Id_(B(n))(G(F(v)),v). It depends on the endpoint m and the proof h through the two displayed terms, so it is a legal motive for J based at n. In the case m=n and h=refl_n, symmetry computes to refl_n and each transport reduces to its input. The composite therefore reduces to v and its identity with v has a reflexive proof. Applying J gives the pointwise equality for an arbitrary h and every v:B(n). This argument gives the specified componentwise identity and does not require a function extensionality premise.

  11. Starting with h:Π x:A.Id_B(f x,g x), state the type of its conversion to a function equality under funext. Give the reverse proof from equality without using funext.

    Show the answer and reasoning

    With function extensionality, h produces Id_(A→B)(f,g). The reverse direction follows by application congruence.

    The given h is a family of equality proofs h(x):Id_B(f x,g x) indexed by x:A. Treat f and g as terms inhabiting the function type A→B. The specified extensionality principle has result type Id_(A→B)(f,g) when supplied with this exact family. Invoke it as a separate principle. It returns an equality proof at the function type. For the reverse, let p be a proof of Id_(A→B)(f,g). For fixed x the function ev_x sends k to k x in B. Congruence of ev_x on p gives Id_B(f x,g x). Abstracting the reverse proof over x gives the required family. It uses the ordinary identity eliminator through congruence and needs no extensionality assumption. Neither direction changes the definitional conversion rules.

  12. Under a Prop-only existential eliminator, derive a proposition Q from a proof of ∃x:A.P(x) and terms P(x)→Q for each x. Explain why directly returning an x:A would need a different rule.

    Show the answer and reasoning

    Apply the existential eliminator with proposition motive Q and the supplied witnesses-to-Q branches.

    The data are a proof ex of the stated existential and a function selecting, for each x:A, a map from P(x) proofs to Q proofs. The result Q is explicitly a proposition. The proposition-only elimination rule opens one case with a hypothetical x:A and p:P(x). Apply the supplied branch to x and p to obtain Q in that case. Eliminating ex with that branch gives a proof of Q. Although the derivation reasons with the locally assumed witness, the resulting proposition Q does not expose it as computational data. Setting the target to an arbitrary data type A would change the motive and fail the stated proposition-only target condition. A data-level pair would allow first projection, or a different recovery principle would have to be supplied and stated.

  13. Give a term A→¬¬A, verify it against a hypothetical n:A→0 and state why this direction provides no law ¬¬A→A.

    Show the answer and reasoning

    The term is λa.λn.n(a), where n:A→0.

    Assume a:A and n:A→0. Ordinary function elimination gives n(a):0. The occurrence of n is used with its exactly declared input type. Abstract over n to obtain a term of (A→0)→0. This type is ¬¬A by the declared definition of negation. The assumption a:A remains available for this abstraction. Abstract over a to obtain a term of A→¬¬A. No call to a decision procedure or choice of truth value is made. The proof uses an actual element a before applying the refuting function. Starting only with ¬¬A would not supply that element through either application used in this proof. General double-negation elimination would be an additional principle.

  14. Assume Nat:Type_0. Give compatible universe levels for Nat→Nat, Type_0 and Π A:Type_0.A→A. Identify the enlarged domain in the final type.

    Show the answer and reasoning

    Nat→Nat belongs to Type_0. Type_0 belongs to Type_1. The polymorphic product shown also belongs to Type_1.

    Because Nat:Type_0, both the domain and codomain of Nat→Nat are small types. Product formation at the maximum of the two levels places it in Type_0. The universe object Type_0 has the next type Type_1 by the displayed universe rule. This judgment is different from membership of an inhabitant such as zero in Nat. In context A:Type_0, the type A→A itself lies in Type_0. The domain of the outer dependent product is the collection Type_0, whose type is Type_1. Applying dependent product formation at the maximum gives Π A:Type_0.A→A : Type_1. The outer binder's type collection accounts for the change of level.

  15. Compute addL(0,n) for variable n. Prove addL(n,0)=n by induction and identify why the latter does not reduce by the same first-step rule on an arbitrary variable.

    Show the answer and reasoning

    addL(0,n) converts immediately to n. The right-zero identity for a variable first argument uses induction.

    The left-zero term exposes the constructor zero in the position inspected by addL. Its defining rule immediately gives addL(0,n)≡n for every supplied n, including an open variable. For the proposed right-zero identity, use motive P(n)=Id_Nat(addL(n,0),n). At n=0 the same defining zero rule gives equality of the endpoints by computation. At n=succ k convert the first endpoint to succ(addL(k,0)). The induction premise is an identity of addL(k,0) and k. Applying successor congruence gives the exact target equation. Induction closes all natural n. The generic term addL(n,0), before the case split, has no known constructor in the first position. The right-zero theorem supplies proof where direct conversion did not.

  16. For isZero(succ k)=false, derive that equality to true is impossible using Boolean constructor disjointness. Deduce the corresponding case of the zero-test specification.

    Show the answer and reasoning

    In the successor branch isZero(succ k)=true would give false=true, which is impossible.

    The zero test computes to false at a successor, so an identity p:isZero(succ k)=true in this branch is definitionally a proof of Id_Bool(false,true). To see constructor disjointness, define a Boolean family with unit at false and the empty type at true. Transport along p would send the unit inhabitant to the empty fiber, a contradiction. For the other side of the equivalence, a proof of Id_Nat(succ k,0) is likewise impossible by a family with unit at each successor and empty at zero. Either assumption yields a term of the empty type. Empty elimination converts the contradiction from each premise to its corresponding target proposition. This proves both conditional directions at a successor and leaves the zero branch to reflexive equality.

  17. Using the dimension tuple (length,mass,time), compute the quotient of length by time squared and determine whether one can add it directly to velocity. Distinguish units from magnitude.

    Show the answer and reasoning

    Length divided by squared time has dimension (1,0,−2), so it does not pass the same-index addition rule with velocity.

    Start with length index (1,0,0) and time index (0,0,1). Multiplying two time quantities adds their indices, giving (0,0,2). Division subtracts this index from the length index. The outcome is (1,0,−2) with magnitude given by division of the numerical values on a common scale and a nonzero divisor. Velocity has index (1,0,−1). The last coordinates differ, so the displayed same-index addition cannot take these two values as its arguments without some different, separately meaningful operation. A magnitude such as 5 does not identify a dimension by itself. The index records the powers of the base units, whereas a magnitude measures amount on a chosen scale at that dimension.

  18. Suppose a term uses a separately declared axiom a:P to prove P. Describe what the kernel checks and what extra premise a reader must include in the mathematical interpretation. Compare a term constructed entirely by the rules.

    Show the answer and reasoning

    The term checks in a context that declares a:P. Its mathematical interpretation is conditional on that declaration.

    A declared axiom a:P supplies a constant entry in the environment. The checker verifies that P is a well-formed proposition and that mention of a has the declared type. Using a as the proof body yields a term typed at P by the constant rule. The checker does not derive a new proof of the axiom from earlier rules, because the declaration was supplied as a premise of that environment. A reader treating the theorem as mathematical evidence must include the declared axiom among the premises of the derivation. The theorem can inherit assumptions from other imported constants even if its surface text never names them directly. A term constructed from the stated constructors, eliminators and local hypotheses has a derivation from those rules. Its trust still includes correct implementation of the checker and its declared foundational rules, with no additional axiom for P used in this example.

What to carry forward

  • A dependent declaration can refer to a variable that already occurs in the context.
  • A definitionally equal index may be used by conversion. A proved identity can justify an explicit transport.
  • The result of a dependent function lies in the fiber selected by its actual argument.
  • Data-level witness pairs expose the witness and its evidence through their projections.
  • Induction supplies proofs about variable natural numbers that are beyond one constructor computation.
  • A proposition-only eliminator must obey its declared target restriction.
  • A proof assistant checks the resulting term in its declared environment.
  • Unit indices track dimension. A numerical calculation also needs compatible scales and physical meaning.

References

Sources for the concepts and teaching approaches in this article.

  1. Hypothetical judgments and substitutionPer Martin-LöfPrimary · PDFncatlab.orgRead source
  2. Typing, conversion and capture avoidanceThe Univalent Foundations ProgramPrimarypeople.csail.mit.eduRead source
  3. The intuitionistic excluded-middle countermodelLorenzo ClementePrimary · PDFlclem.github.ioRead source
  4. Lean documentation authors8 sources
    1. Polymorphic types and elaboration in LeanLean documentation authorsPrimarylean-lang.orgRead source
    2. Lean's proof irrelevance and implication proofsLean documentation authorsPrimarylean-lang.orgRead source
    3. Equality substitution and the existential targetLean documentation authorsPrimarylean-lang.orgRead source
    4. Indexed vector constructor cases in LeanLean documentation authorsPrimarylean-lang.orgRead source
    5. Tactic instructions and the checked termLean documentation authorsPrimarylean-lang.orgRead source
    6. Structural recursion and partial definitionsLean documentation authorsPrimarylean-lang.orgRead source
    7. Proof checking under declared assumptionsLean documentation authorsPrimarylean-lang.orgRead source
    8. Reflection and decidability instancesLean documentation authorsPrimarylean-lang.orgRead source
  5. Static unit expressions and dimension checksAndrew KennedyPrimary · PDFtypesatwork.imm.dtu.dkRead source
  6. Quantity scales and coherent derived SI unitsBureau International des Poids et MesuresPrimarybipm.orgRead source
  7. Open Logic Project2 sources
    1. Substitution and scope in first-order syntaxOpen Logic ProjectPrimary · PDFbuilds.openlogicproject.orgRead source
    2. Introduction and elimination in proof rulesOpen Logic ProjectPrimary · PDFbuilds.openlogicproject.orgRead source
  8. Finite certificates and decidable checkingOpen Logic Project authorsPrimary · PDFbuilds.openlogicproject.orgRead source