Lectures onType Theory
Chapter 98
Chapter 98Optional

Linear Dependent Type Theory

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

A dependent type may inspect its argument more than once. A linear term, however, must use a linear argument exactly once. Combining these two clauses naively makes the type checker consume a run-time resource: if q:Qubit and a type contains B(q,q), then ordinary dependent substitution duplicates q. Declaring the two occurrences “static” does not repair the rule, because evaluating a general term in order to form a type may itself change the state.

The repair separates a resource-bearing value from the parameter that records its reusable shape. Types depend only on parameters; terms may still use state exactly once. The distinction is enforced by the judgments, not by an informal promise that the type checker will avoid dangerous evaluations.

Parameters and state

Definition 98.1 — Types, indices, and contexts

The selected calculus has types A,B::=C1!A(x:A)B[x](x:A)B[x](x:P1)P2[x], where C ranges over state types. Parameter types are generated by P::=1!A(x:P1)P2[x](x:P1)P2[x]. Terms include variables, unit, linear abstraction and application, pairs and pair elimination, liftM, and forceM. Parameter abstraction λx.R, parameter application R1@R2, and forceR form the parameter sublanguage.

A usage index is k{0,1,ω}. A context entry is x:kA; index ω is permitted only when A is a parameter type. A parameter context Φ is a context in which every variable whose type is not a parameter type has index 0. Thus Φ may contain a parameter at index 0, 1, or ω, but it cannot provide a state-bearing closure to a term.

The indices form the three-element usage algebra used in the source calculus. Zero is the additive identity, one is the multiplicative identity, k+=ω when k,0, and 0k=0, ωω=ω. Addition and scalar multiplication act pointwise on contexts with the same declaration spine. Consequently Γ1+Γ2 is defined only when corresponding variables have the same types and its result is a well-formed context.

Definition 98.2 — Shape

The shape operation Sh erases state while retaining parameter information. Its decisive clauses are Sh(C)=1,Sh(!A)=!A,Sh((x:A)B[x])=(x:Sh(A))Sh(B[x]),Sh((x:A)B[x])=(x:Sh(A))Sh(B[x]),Sh(P)=P,Sh(x)=x,Sh(λx.M)=λx.Sh(M),Sh(MN)=Sh(M)@Sh(N),Sh(liftM)=liftM,Sh(forceM)=forceSh(M). It acts componentwise on pairs, pair eliminations, and contexts. Shape is a meta-operation, like capture-avoiding substitution; it is not a run-time term constructor. It is idempotent on well-formed parameter syntax.

For example, a qubit has shape 1. A pair consisting of a natural parameter n and an n-wire register retains n but forgets the register state. Hence the shape may index a result type without giving the type checker permission to measure, copy, or discard the register.

The tempting replacement Sh(M)=M fails for state terms. If M allocates or measures a qubit, putting M into a type makes type formation stateful. The clause Sh(C)=1 is therefore load-bearing: it records that the state object exists while discarding the state itself.

Definition 98.3 — Kinding and context formation

Types are checked only in parameter contexts. The dependent linear formers have rules

Φ,x:Sh(A)B[x]:
Φ(x:A)B[x]:
LD-μltimap-F
Φ,x:Sh(A)B[x]:
Φ(x:A)B[x]:
LD-⊗-F

and the parameter function former has

Φ,x:P1P2[x]:
Φ(x:P1)P2[x]:
LD-→-F
ΦA:
Φ!A:
LD-!-F

A context extension Γ,x:kA is well formed when Γ is well formed, Sh(Γ)A:, and k=ω implies that A is a parameter type.

The premise of LD--F exposes the separation. The term-level argument has type A, but the codomain receives only an argument of type Sh(A). No linear resource occurs in the kinding context.

Exercise 98.1

★☆☆ Prove by structural induction on the syntax in definition 98.2 that Sh(Sh(A))=Sh(A) and likewise for parameter terms. State why the claim is not an equation asserting that a state term equals its shape.

Linear dependent functions and pairs

Definition 98.4 — Typing rule card

The rules that expose dependency and usage are

0Γ,x:1A,0Γ ctx
0Γ,x:1A,0Γx:A
LD-Var
Γ,x:kAM:B[x]k1A=P
Γλx.M:(x:A)B[x]
LD-Lam
Γ1M:(x:A)B[x]Γ2N:A
Γ1+Γ2MN:B[Sh(N)]
LD-App
Γ1M:AΓ2N:B[Sh(M)]
Γ1+Γ2(M,N):(x:A)B[x]
LD-Pair

Pair elimination splits the scrutinee context from the body context:

Γ1M:(x:A)B[x]Γ2,x:k1A,y:k2B[x]N:Ck1=0A=P1k2=0B[x]=P2[x]
Γ1+Γ2let(x,y)=MinN:C
LD-Let

Finally, lift may close only over a parameter context:

ΦM:A
ΦliftM:!A
LD-Lift
ΓM:!A
ΓforceM:A
LD-Force

The parameter sublanguage has its own introduction and elimination rules:

Φ,x:P1R:P2[x]
Φλx.R:(x:P1)P2[x]
LD-Param-Lam
ΦR1:(x:P1)P2[x]ΦR2:P1
ΦR1@R2:P2[R2/x]
LD-Param-App
ΦR:!A
ΦforceR:Sh(A)
LD-Param-Force

All displayed contexts must satisfy definition 98.3.

In LD-App, N occurs once in the program and Sh(N) may occur repeatedly in the classifier. The two uses are not two resource uses. The same distinction appears in LD-Pair: M contributes one state-bearing component, while its shape selects the second component’s type.

Take a base state type Cell, a parameter type Nat, and a family Ready:Nat. Suppose Γff:(z:Cell)Ready(s@z)andΓcc:Cell, where the codomain variable has type Sh(Cell)=1 and s:1Nat is a parameter-level summary. Then LD-App derives Γf+Γcfc:Ready(s@Sh(c)). The cell is consumed in fc; the reusable index is its unit-shaped summary. Since Sh(x)=x on variable syntax, the printed expressions s@Sh(c) and s@c coincide after applying the meta-operation. Their typing role is nevertheless fixed: the occurrence of c in the classifier has type Sh(Cell)=1, not Cell.

Proposition 98.5 — Shape preservation

If ΓM:A, then Sh(Γ)A:andSh(Γ)Sh(M):Sh(A).

Proof of Proposition 98.5 — Shape preservation

Proof. Induct on the typing derivation. In the variable case, applying shape to its declaration replaces the declared type by its parameter shape. For LD-App, the induction hypotheses give Sh(M):(x:Sh(A))Sh(B[x])andSh(N):Sh(A). Parameter application therefore has the type on the left in Sh(B)[Sh(N)/x]=Sh(B[Sh(N)/x]), where the equality follows by structural induction on B. The pair case uses the same commutation equation for the second component. Linear abstraction becomes parameter abstraction. Lift is fixed by shape, force becomes force, and pair elimination commutes componentwise with shape. These cases cover every constructor in definition 98.1. ◻

Exercise 98.2

★★☆ Assume u:1A,v:0DM:A, and u:0A,v:1DN:B[Sh(M)] uses only v. Write the two premise contexts and their pointwise sum in an application of LD-Pair. Explain why replacing the index 0 on the second occurrence of u by 1 makes the sum ill formed when A is a state type.

Three substitutions

Ordinary substitution conflates three operations. A parameter may be put in a type, a parameter may be put in a term, and a state-bearing value may be put in a term while only its shape is put in dependent types. The theorem must state all three because the third induction invokes the first two.

Theorem 98.6 — Substitution

The following judgments are admissible.

  1. If Φ,x:P,ΦB[x]: and ΦR:P, then Φ,Φ[R/x]B[R/x]:.

  2. If Φ,x:P,ΓM:B[x] and ΦR:P, then Φ,Γ[R/x]M[R/x]:B[R/x].

  3. If Γ1,x:kA,ΓM:B[x] and Γ2V:A, where V is a value, then Γ1+kΓ2, Γ[Sh(V)/x]M[V/x]:B[Sh(V)/x].

All sums and substituted contexts in the conclusions are required to be well formed.

Proof of Theorem 98.6 — Substitution

Proof. Prove the three clauses simultaneously by induction on the kinding and typing derivations. Parameter variables give clauses (1) and (2) by the usual variable split. Formation of either dependent linear former uses clause (1) under its parameter binder.

For clause (3), the variable case exposes the quantitative invariant. If the last rule selects x, then k=1 and the conclusion is precisely the given derivation Γ2V:A, weakened by the zero-use declarations on either side. If it selects another variable, the declaration for x has index zero in that branch; the induction conclusion adds 0Γ2, so no resource in V is consumed.

In the application case, split the premise occurrence of x:kA as x:k1A+x:k2A, where k=k1+k2. The two induction hypotheses produce contexts Δ1+k1Γ2 and Δ2+k2Γ2. Rebuilding LD-App is licensed by (Δ1+k1Γ2)+(Δ2+k2Γ2)=Δ1+Δ2+(k1+k2)Γ2. Its result type is correct because shape commutes with value substitution: Sh(N[V/x])=Sh(N)[Sh(V)/x]. The pair case has the same context equation, and the displayed shape equation aligns the second component’s type.

For linear abstraction, alpha-rename its binder away from V, apply the induction hypothesis under the binder, and rebuild LD-Lam. If the binder has index zero or ω, its parameter-type side condition is unchanged by substitution. Pair elimination splits k among the scrutinee and body and uses associativity and distributivity of context addition exactly as the application case. Lift has a parameter context, so a state-bearing substituted value can occur there only with scalar zero; force preserves the induction context. Parameter abstraction, parameter application, and force use clauses (1) and (2). Thus every formation and typing rule is rebuilt with the stated context. ◻

The value premise in clause (3) cannot be dropped for this call-by-value calculus. Substituting an arbitrary effectful computation duplicates or reorders its state transition when the variable occurs in a value body. The shape in the dependent suffix is equally necessary: replacing it by V would insert a state term into a kinding judgment.

Exercise 98.3

★★☆ Write the complete LD-Pair case of theorem 98.6(3). Name the two usage indices assigned to the substituted variable, derive the two component judgments, and show both the context-sum equation and the equation aligning the second component’s type.

Evaluation and semantic soundness

Definition 98.7 — Call-by-value evaluation

The evaluation judgment MV is defined on open terms. Its application and pair-elimination rules are

Mλx.MNVM[V/x]V
MNV
LD-Eval-App
L(V1,V2)M[V1/x][V2/y]V
let(x,y)=LinMV
LD-Eval-Let

Force evaluates a lifted body, and parameter application uses the corresponding parameter abstraction. Variables count as values so that type-level evaluation is defined on open parameter terms. Write RevR when both parameter terms evaluate to a common parameter value. Type conversion is driven by this symmetric computational equality:

ΓM:A[R]RevR
ΓM:A[R]
LD-ConvEval

Lemma 98.8 — Evaluation commutes with shape

If NV, then Sh(N)Sh(V).

Proof of Lemma 98.8 — Evaluation commutes with shape

Proof. Induct on the evaluation derivation. Application becomes parameter application, and the three induction hypotheses rebuild its evaluation rule. Pair elimination commutes with shape and with both substitutions. Force becomes force, whose evaluation rule returns the shaped lifted body. Values are fixed by their corresponding parameter-value rules. These are all rules in definition 98.7. ◻

Proposition 98.9 — Preservation for evaluation

Let LD1 be the fragment in which every abstraction evaluated by LD-Eval-App is derived by LD-Lam with binder index 1. If ΓM:A is an LD1 derivation and MV, then ΓV:A.

Proof of Proposition 98.9 — Preservation for evaluation

Proof. Induct on the evaluation derivation. In the application case, inversion of LD-App gives Γ1M:(x:B)A[x],Γ2N:B,Γ=Γ1+Γ2. The first two induction hypotheses type λx.M and V at those same types. Inversion of LD-Lam and the fragment boundary give Γ1,x:1BM:A[x]. Apply theorem 98.6(3) to obtain ΓM[V/x]:A[Sh(V)/x]. By lemma 98.8, Sh(N)Sh(V); rule LD-ConvEval aligns this with A[Sh(N)/x], since the shaped value evaluates to itself. The final induction hypothesis types the result. Pair elimination uses the two successive instances of the same substitution clause. The force and parameter-application cases use their corresponding substitution clauses. Values close the induction. ◻

The restriction is load-bearing. The unrestricted source syntax permits LD-Lam with k=0 or k=ω when the domain is a parameter type, whereas LD-App always contributes one copy of the argument context. The published application proof explicitly supposes k=1 [FKS22]. Consequently the present chapter does not claim operational preservation for the other two cases without an additional parameter-weakening or parameter-substitution rule that aligns the required contexts.

Definition 98.10 — Exact imported state–parameter signature

A state–parameter model is the fibration specified by Fu–Kishida–Selinger’s Definition 2.8 [FKS22]. Its signature is the following data and laws.

  1. The functor :EB is a pullback fibration. The base B is locally cartesian closed, the total category E is symmetric monoidal closed, and preserves the terminal object. In the equivalent adjunction presentation, has a full faithful right adjoint q, identity counit, unit η:idEq, and the specified pullbacks along arrows qf.

  2. The functor preserves the monoidal closed structure, and the tensor of cartesian arrows is cartesian.

  3. For A,BE/qX, the fibered objects AqXB and AqXB are the cartesian liftings of product and exponential in B/X, and qXAAqX.

  4. The parameterized-unit functor p:BE, obtained by cartesian lifting from the monoidal unit, has a right adjoint . Thus !=p has counit force:!idE.

These clauses are the source conditions (1)–(9), not a placeholder for unspecified “appropriate” structure. For XB, AE/qX, and BE/A, the source’s Theorem 2.14 constructs the dependent adjunction qXAΠqX,A and its counit ϵ:(ΠqX,AB)qXAB; this is a consequence of the signature, not an unnamed extra axiom.

Theorem 98.11 — Imported interpretation package

Every model of definition 98.10 admits the interpretation of Fu–Kishida–Selinger, Theorem 3.11 [FKS22], with the following exact signature:

  1. [[Γ]]E;

  2. [[ΦA:]] is an object over [[Φ]];

  3. [[ΓM:A]] is an arrow in E/[[Γ]] from η[[Γ]] to the interpreted type;

  4. [[Sh(Γ)]]=p[[Γ]], and the interpretations of Sh(A) and Sh(M) are respectively p[[A]] and p[[M]];

  5. parameter substitution in a type is the pullback of its display map along [[R]].

Moreover, [[Γ1+Γ2]][[Γ1]]qX[[Γ2]], where X=[[Γ1]]=[[Γ2]].

Proof of Theorem 98.11 — Imported interpretation package

Proof. This is the exact import of clauses (1)–(7) of source Theorem 3.11. The hypotheses of definition 98.10 match Definition 2.8 clause for clause; the source’s simultaneous induction supplies the five groups above and the displayed context equation. No normalization, canonicity, or completeness conclusion is imported. ◻

Lemma 98.12 — Imported semantic value substitution

Under theorem 98.11, suppose Γ1,x:1AM:B[x] and Γ2V:A. Then [[M[V/x]]] is the unique arrow into the pullback for B[Sh(V)/x]. Its upper path is [[M]](id[[Γ1]][[V]]).

Proof of Lemma 98.12 — Imported semantic value substitution

Proof. The imported result is the source’s value-substitution proposition [FKS22]. Its source diagram defines the arrow by the pullback universal property and defines the displayed arrow with precisely the domain printed above. This is the k=1, empty-suffix specialization; no undefined ω-fold tensoring operation is used. ◻

Theorem 98.13 — Soundness for LD^1

If ΓL:A is an LD1 derivation and LW, then every model of definition 98.10 satisfies [[L]]=[[W]].

Proof of Theorem 98.13 — Soundness for LD^1

Proof. Induct on the evaluation derivation. The application case contains the decisive step; its premises are Fλx.M0, NV, and M0[V/x]W. Typing inversion and proposition 98.9 give Γ1,x:1BM0:A[x],Γ2V:B,Γ=Γ1+Γ2. The three evaluation induction hypotheses give [[F]]=[[λx.M0]],[[N]]=[[V]],[[M0[V/x]]]=[[W]]. Application is interpreted by the counit ϵ. Semantic substitution and the counit equation therefore yield the annotated chain [[FN]]=IH[[(λx.M0)V]]=counit[[M0[V/x]]]=IH[[W]]. The middle equality is exactly lemma 98.12; its source object is [[Γ1]][[Γ2]], so no implicit contraction duplicates V.

For pair elimination, interpret pair formation by dependent tensor and use semantic substitution twice; the tensor beta equation gives the required composite. Force uses the counit of the linear exponential, parameter application uses ordinary dependent-function beta in B, and the remaining evaluation rules use functoriality followed by their induction hypotheses. Thus every LD1 evaluation derivation preserves its denotation. ◻

Dropping the state–parameter structure leaves the conclusion without a meaning: the application proof uses both the context-tensor equation and the dependent counit. Dropping the evaluation premise also fails; two terms of the same type need not denote the same morphism. Conversely, the theorem does not prove that evaluation terminates or that every closed value is canonical. The source states an unrestricted soundness result as Theorem 3.12, but its displayed application argument explicitly assumes k=1. The theorem above records the fragment established by that argument rather than silently generalizing it.

Exercise 98.4

★★☆ Redraw the application case of theorem 98.13 as a commuting square. Label its four objects, the tensor-environment map, the counit, and the map induced by V. Then write the equality of the two paths; the diagram alone is not the answer.

A resource-indexed protocol

Let VecCell(n) be the state type of a register containing exactly n cells and let Fin(n) be the parameter type of valid positions. Consider read:(n:Nat)(r:VecCell(n))(i:Fin(n))BitVecCell(n). The parameter n may be reused to check i, while the register r occurs once. For n=2, i=1, and r:VecCell(2), the typing calculation is read2:(r:VecCell(2))(i:Fin(2))BitVecCell(2),read2r:(i:Fin(2))BitVecCell(2),read2r@1:BitVecCell(2). The first application consumes r; parameter application reuses 2. An attempted second call with the same r has context usage 1+1=ω, which is forbidden for the state type VecCell(2). The returned register, rather than the consumed name, must be threaded into the next call.

This protocol resembles an ownership API and its parameter index resembles a session-state index. Those resemblances do not identify the calculi: the present soundness proof depends on a state–parameter fibration and does not establish progress for a session operational semantics or borrowing laws for an ownership language.

The pinned Proto-Quipper-D tutorial exercises the same boundary in three stages [FKRS20]. Its first circuit boxes a reusable generator at type Circ(1,QubitQubit), separating the parameter-level circuit description from the state-bearing qubit wires. Its dependent Fourier-transform family then has the inspectable interface qftBox:(n:Nat)Circ(VecQubitn,VecQubitn). The retained results bell00Box.pdf, teleBox.pdf, and qft5.pdf display the generated circuits; the vector length remains a parameter while each circuit consumes and returns its wire bundle.

The dynamic-lifting test measures a freshly initialized qubit, lifts the resulting bit into a host Boolean, and branches in a recursive binary-number calculation. A neighboring negative test attempts to use that dynamically lifted number as the length of a returned vector and is rejected: a run-time measurement cannot retroactively determine the static family in the result type. This implementation trace illustrates the state/parameter boundary; it is not a premise of theorem 98.13.

Exercise 98.5

★★☆ Type two successive reads by eliminating the tensor returned by the first call and passing its register component to the second. Give the usage of the original register and of the bound returned register. Show the exact context sum that rejects two reads of the original register.

Suggested first pass.

None of these problems is a prerequisite for a later chapter. Begin with exercise 98.6, then complete exercise 98.8.

Exercise 98.6

★★☆ Reconstruct all three clauses of theorem 98.6 for the term (M,N). Identify the clause used for the second component’s type and the clause used for each component term. Test the boundary obtained by replacing Sh(V) with V.

Exercise 98.7

★★★ For the application fragment, instantiate a state–parameter model whose parameter category is finite sets and whose state morphisms carry a finite state transition. Define the dependent counit and verify the semantic substitution square on a two-state example. State which additional structure would be required for pairs and !A.

Exercise 98.8

★★★ Practical project.ldtt-shape-usage-checker Implement in Agda or Kappa the finite syntax consisting of state and parameter variables, linear application, dependent pairs, and shape. Maintain the invariant that a state variable has total usage at most one and that every classifier contains only parameter syntax. On the named threaded-read, duplicate-read, and raw-state-index inputs, require these exact stdout fragments:

threaded-read term accepted
duplicate-read term rejected for state usage
raw state index rejected during kinding

Also print the shape-substituted result type of threaded-read. The checker is a finite executable instance of the substitution invariant; it does not prove theorem 98.13.

Sources. The syntax, shape operation, three-clause substitution theorem, and semantic soundness theorem are reconstructed from Fu, Kishida, and Selinger’s linear dependent type theory for quantum programming: Theorem 3.7 appears on p. 16 and Theorem 3.12 on p. 19 of the pinned version [FKS22]. Their Proto-Quipper-D tutorial supplies the circuit-programming route, but surface acceptance is not used as evidence for the semantic theorem. Benton’s linear/nonlinear separation is background for the parameter/state split [Ben94].

Search the book

Type to search the local edition.