Lectures onType Theory
Proof production, metaprogramming, levels, and generated actions
appendix sectionrules

Proof production, metaprogramming, levels, and generated actions

Tactic validations and replay

A goal is g=(ΓG). A validation from g1,,gn to g is a partial meta-level function V satisfying (Γipi:Gi for every i)ΓV(p1,,pn):G. The primitive validations are tacticsubgoalsvalidationexact(q)()()qintro(Γ,x:AB)pλx.psplit(ΓA),(ΓB)(p,q)(p,q)assumption()()xwhere x:G is first in Γ. Sequencing composes a first validation V with the subgoal validations Wi as (q1,,qn)V(W1(q1),,Wn(qn)). A successful replay must end by checking Γp:G for its completed proof term in the unchanged kernel. The tactic semantics has separate success and failure judgments, T@g(h,V) and fails(T,g). Choice therefore commits to its left branch only on success:

T@g(h,V)
(TorelseU)@g(h,V)
Tac-Or-Left
fails(T,g)U@g(h,V)
(TorelseU)@g(h,V)
Tac-Or-Right
fails(T,g)fails(U,g)
fails(TorelseU,g)
Tac-Or-Fail

For a state S=(g1,,gn;V), a repeat step evaluates T on g1, composes its validation into V, and is admitted only when the lexicographic measure (c(g1),n) strictly decreases. The closure has Rep-Done exactly when the state is empty, the first tactic application fails, or no successful application decreases the measure, and Rep-More for one decreasing step followed by the closure. Thus repeat(T)@g(h,V)RepT((g;pp),(h;V)).

Certified simplification and reflection

A database entry is a typed equality q:IdA(,r) oriented only when its well-founded measure decreases after every admitted instantiation. The contextual rewriting judgment is generated by

rootD(t)=(rρ,qρ)
Rw(Γ;=;t;rρ;qρ)
Rw-Root
Γt:AΓreflexR:x:ARxx
Rw(Γ;R;t;t;reflexRt)
Rw-Atom
Rw(Γ;RARB;f;f;vf)Rw(Γ;RA;a;a;va)
Rw(Γ;RB;fa;fa;vfaava)
Rw-App
Rw(Γ,x:A,y:A,p:RAxy;RB;b;b;v)
Rw(Γ;RARB;λx.b;λy.b;λx.λy.λp.v)
Rw-Lam

Here RARB is the binary respectful relation: its witness maps x,y,p:RAxy to a proof of RB(fx)(fy). It is not the pointwise unary relation. The substitution rule composes an R-certificate with a checked implication into a relation S. Reflection reifies a commutative-monoid expression, computes its finite multiplicity map, and accepts the result only after the kernel checks the produced equality proof.

Hygienic and phase-indexed expansion

A raw binder is aβ, and a raw reference aβω carries both its stable occurrence token ω and its lexical target token β. An expanded reference has the form aS[o;src(ω)] or aS[o;new(ot)]: S is its finite scope set, o is its resolved origin, and the final marker records copied provenance or a declared constructed target. Transformer output marks every node as substituted or constructed; substituted syntax retains caller scopes, whereas constructed syntax receives a fresh introduction scope. Each free constructed reference declares a target origin, and expansion rejects an unresolved, ambiguous, or provenance-mismatched reference. The source judgment E0;Γnsrcr:A includes

E0(β)=osΓ(os)=A@n
E0;Γnsrcaβω:A
Src-Var
βdomE0os freshE0,βos;Γ,os:A@nnsrcr:B
E0;Γnsrcλ(aβ:A).r:AB
Src-Lam
E0;Γnsrcr1:ABE0;Γnsrcr2:A
E0;Γnsrcr1r2:B
Src-App

Src-Macro checks only a declared source arity and type together with the argument typings. It does not trust a transformer contract. After expansion, the staged target checker and provenance judgment independently check the output, as required by definition 116.11. The core phase rules are

Γn+1e:A
Γnquote(e):Code(A)
Q-Quote
Γne:Code(A)
Γn+1splice(e):A
Q-Splice
(x:A@n)Γ
Γnx:A
Q-Var

Generated commands expose a scoped declaration and a closed ordinary term; only that term crosses the kernel boundary.

First-class level rules

The principal noncumulative calculus adds

Γ ctx
ΓLevel:U0
Level
Γ ctx
Γ0:Level
L-Zero
Γt:Level
Γt+:Level
L-Suc
Γt:LevelΓu:Level
Γtu:Level
L-Join
Γt:Level
ΓUt:Ut+
L-Univ

Join is associative, commutative, idempotent, and has zero as left identity; successor preserves join and satisfies tt+t+. Explicit lifts have

ΓA:Ut
ΓLiftuA:Utu
Lift-F
Γa:A
Γlifta:LiftuA
Lift-I
Γb:LiftuA
Γlowerb:A
Lift-E

The beta rule contracts lower after lift; the extensional eta rule identifies two lifted terms when their lowerings are equal.

Sort abstraction and elimination

SortPoly judgments have shape ΣΘΓt:A, with prenex sort and level variables in Θ. Sort variables have no constraints in the principal system. Every case rule retains the premise ΣΘelim(I,sP) allowed. Same-sort elimination is the universal clause

Θs sort(I declared at codomain sort s)Σ
ΣΘelim(I,s) allowed
Same-Sort

Ground policies may add only their stated clauses, such as singleton elimination from Prop. Monomorphization duplicates each global declaration at all well-formed ground instantiations and deletes only the sort binders; it retains level binders and constraints. The independent subStraTT boundary instead enforces dependency strata:

ΔΓ
Δ;Γ:k
DT-Type
Δ;ΓA:jΔ;Γ,x:jAB:kj<k
Δ;Γx:jA:B:k
DT-Pi
Δ;Γb:kx:jABΔ;Γa:jAj<k
Δ;Γba:kB[a/x]
DT-AppTy

The bounded SortPoly comparison puts edges edgeΘ(s,t) in the sort context. Validity requires: every ground path is already generated by ground edges; a reflexive initial ground sort lies below each ground sort incident with a nonground edge; and every dominated sort variable has a reflexive dominant ground sort above every other ground predecessor. Only a valid context admits the dominant ground substitution and the proved preservation, principality, monomorphization, and conditional equiconsistency package.

Coercion paths and insertion

The generated paths contain identities, declared edges, and composition: progidA=λx.x,progqp=λx.progq(progpx). Path coherence requires equal cast programs for every pair of parallel paths. Insertion occurs only at the synthesis-to-checking boundary:

(x:A)Γ
ΓxAx
Coe-Var
Γe1x:ABt1Γe2At2
Γe1e2B[t2/x]t1t2
Coe-App
Γ,x:AeBt
Γλx.ex:ABλx.t
Coe-Lam
ΓeAtpCoe(A,B)
ΓeBprogpt
Coe-Insert

Annotations and pairs retain the syntax-directed rules printed in definition 119.6; no other rule consumes a path. The determinacy proof additionally assumes that target definitional equality is stable under substitution and that dependent products are injective: equality of Πx:A1.B1 and Πx:A2.B2 yields equality of the domains and, after context conversion, equality of the codomains. Path coherence alone cannot discharge the Coe-App case.

Generated positive action

Positive descriptions are generated by 1,K(A),X,×,+, and dependent sum. Their action is structural: constants are fixed, the parameter clause applies f, products act componentwise, sums preserve the injection, and dependent sums preserve their first component. Indexed descriptions replace X by X(j) and apply the corresponding family map fj. The judgmental functor equations are mapF(id)(x)x,mapF(f)(mapF(g)(x))mapF(fFFg)(x). On a neutral n, weak-head reduction compacts the second equation to one outer map; the identity equation remains conversion and is not oriented as an expanding reduction. Constructor-headed inputs use only the structural computation equations. Neutral identity and composition are the deliberate definitional-equality delta Desc-Map-Id/Desc-Map-Comp; the latter may be oriented as weak-head reduction only on a neutral argument. Generated action commutes with every well-typed simultaneous substitution, and this substitution lemma proves that constructor computation, the two equality rules, and neutral compaction remain well typed after substitution. Dependent sums act by (g,f)(x,y)=(g(x),f(x)(y)); their identity and composition laws reduce by projection and pair computation rather than by the neutral delta.

Search the book

Type to search the local edition.