Prerequisites. Direct starred prerequisites: Chapter 20, Chapter 40. No later core chapter depends on this route.
The indices 0,1,𝜔 distinguish absence, exact use, and unrestricted use, but the previous chapter fixes those three quantities in advance. It cannot state that a variable is used twice, that a branch costs 𝑟, or that substitution multiplies one demand by another. Ordinary dependent typing has the opposite defect: an index may occur in a type without recording whether it survives at run time.
A quantitative judgment puts both facts in one place. Types see the whole context spine; annotations record computational demand. The annotation zero therefore means “available to type formation but absent from this computation.” It does not mean that every two inhabitants of the annotated type are propositionally equal.
A usage semiring is a structure whose operations (𝑅,+,0,⋅,1) satisfy the semiring laws. It must also satisfy 𝜌+𝜋=0⇒𝜌=0=𝜋,𝜌𝜋=0⇒𝜌=0or𝜋=0. A quantitative context has the form Γ=𝑥1:𝜌1𝑆1,…,𝑥𝑛:𝜌𝑛𝑆𝑛. Contexts with the same variable and type spine are added and scaled pointwise. Scaling is shallow: 𝜌Γ scales the annotations on the declarations, not annotations occurring inside the types 𝑆𝑖.
The natural numbers, the Boolean semiring, and the zero–one–many semiring are examples. Positivity is used when a conclusion has quantity zero: it lets the proof recover that every summand was zero. The zero-product property is used in substitution: if a scaled demand vanishes, either the outer demand or the substituted computation’s demand vanishes.
QTT separates context and type formation from terms: Γ⊢,Γ⊢𝑆,Γ⊢𝑆≡𝑇,Γ⊢𝑀:𝜎𝑆,Γ⊢𝑀≡𝑁:𝜎𝑆, where the output quantity is restricted to 𝜎∈{0,1}. Quantity zero is the type-level or erased fragment; quantity one is the present fragment. Types are formed in 0Γ, so every variable on which a type depends has zero computational demand.
Allowing an arbitrary output quantity looks more general, but it breaks substitution for the zero–one–many semiring. A term can coerce a function that uses its argument once to one announced at usage 𝜔. Substituting that function into a context split requiring 𝜔=1+𝜔 would require splitting an actual usage-one derivation into usage 1 and 𝜔, which is impossible. Restricting the output to zero or one prevents this hidden subusage step.
Proof. Induct on the typing derivation. A variable derivation at output zero has a zero context by its rule. In every rule that adds premise contexts, the conclusion annotations are sums; positivity forces each summand to be zero. In every rule that scales a premise context, the conclusion annotations are products; the zero-product property separates a zero output multiplier from a zero premise annotation. Constants contribute the zero context. These are all ways in which an annotation enters a conclusion. ◻
The converse is false. A closed Boolean constant can be classified at output quantity one while requiring the zero context. Thus the lemma detects absence of input demand; it does not reconstruct the output quantity.
★★☆ Give a two-element commutative semiring in which positivity fails, and point to the induction step of lemma 99.3 that can no longer recover zero premises. Separately explain why the natural-number semiring satisfies both additional properties.
Write (𝑥:𝜋𝑆)→𝑇 for a dependent function whose body uses its argument at quantity 𝜋. Its principal rules are
0Γ⊢𝑆0Γ,𝑥:0𝑆⊢𝑇
0Γ⊢(𝑥:𝜋𝑆)→𝑇
QTT-Π-F
Γ,𝑥:𝜎𝜋𝑆⊢𝑀:𝜎𝑇
Γ⊢𝜆𝑥.𝑀:𝜎(𝑥:𝜋𝑆)→𝑇
QTT-Lam
Γ1⊢𝑀:𝜎(𝑥:𝜋𝑆)→𝑇Γ2⊢𝑁:𝜎′𝑆𝜎′=0⟺(𝜋=0or𝜎=0)
Γ1+𝜋Γ2⊢𝑀𝑁:𝜎𝑇[𝑁/𝑥]
QTT-App
The side condition selects an erased argument when either the binder demand is zero or the whole application is in the erased fragment. Formation sees 𝑥 at zero demand because 𝑇 may depend on 𝑥 without consuming it at run time.
where 𝜎∈{0,1}. At output one it consumes one copy; its erased counterpart is available in a zero context. Function application then performs the semiring calculation visible in its conclusion. If a function uses its argument three times and the argument uses resources 2Δ, the application contributes 3(2Δ)=6Δ.
The equality of zeroed context spines ensures that dependency information is shared even when computational demands differ. The result family is formed over a fresh pair variable 𝑧; the premise and conclusion substitute the introduced pair and the actual scrutinee for that same variable. The beta root is Γ⊢𝗅𝖾𝗍(𝑥,𝑦)=(𝑀,𝑁)𝗂𝗇𝐿≡𝐿[𝑀/𝑥,𝑁/𝑦]:𝜎𝑈[(𝑀,𝑁)/𝑧], with the contexts determined by the rule above. If the scrutinee is a neutral variable, elimination is stuck. The selected core imports this beta equation; it makes no tensor eta claim.
★☆☆ In the natural-number usage semiring, suppose Γ1⊢𝑓:1(𝑥:3𝐴)→𝐵 and 2Δ⊢𝑢:1𝐴. Derive the application context. Now replace the function by one whose binder quantity is zero. State which argument premise must change, use the output-quantity side condition to justify that change, and derive the resulting application context.
If Γ1,𝑥:𝜌𝑆,Γ′⊢J is a context, type, or type-equality judgment, Γ2⊢𝑁:0𝑆, and 0Γ1=0Γ2, then Γ1,Γ′[𝑁/𝑥]⊢J[𝑁/𝑥].
If Γ1,𝑥:𝜌𝑆,Γ′⊢𝑀:𝜎𝑇,Γ2⊢𝑁:𝜎′𝑆, with 0Γ1=0Γ2 and 𝜎′=0⟺𝜌=0, then (Γ1+𝜌Γ2),Γ′[𝑁/𝑥]⊢𝑀[𝑁/𝑥]:𝜎𝑇[𝑁/𝑥]. The corresponding term-equality rule has the same hypotheses and context.
Proof. Prove context formation, type formation, terms, and equalities simultaneously. The variable case makes the context formula necessary. When the selected variable is 𝑥, its use is 𝜌, so replacing it by 𝑁 demands 𝜌Γ2. When another variable is selected, 𝑥 has zero demand in that branch and contributes 0Γ2.
For QTT-App, alpha-rename its binder to 𝑦 and write the application as 𝐿𝑀, with result type 𝑇[𝑀/𝑦]. Split the demand 𝜌 on the substituted variable 𝑥 between the function and argument derivations as 𝜌1+𝜋𝜌2. The induction hypotheses give the contexts Δ1+𝜌1Γ2 and Δ2+𝜌2Γ2. Rebuilding the rule yields (Δ1+𝜌1Γ2)+𝜋(Δ2+𝜌2Γ2)𝑑𝑖𝑠𝑡𝑟𝑖𝑏.=Δ1+𝜋Δ2+(𝜌1+𝜋𝜌2)Γ2𝑑𝑒𝑚𝑎𝑛𝑑=Δ1+𝜋Δ2+𝜌Γ2. The rebuilt type is 𝑇[𝑁/𝑥][𝑀[𝑁/𝑥]/𝑦], equal to 𝑇[𝑀/𝑦][𝑁/𝑥] by capture-avoiding substitution composition.
For QTT-Lam, alpha-rename the binder and use 𝜌(𝜎𝜋)=(𝜌𝜎)𝜋 to rebuild its body demand. The pair case uses distributivity in the same direction as application. In QTT-Let, split the substituted variable’s demand between the scrutinee and body premises as 𝜌1+𝜌2. The induction hypotheses yield Δ1+𝜌1Γ2 and Δ2+𝜌2Γ2; rebuilding the exact rule gives their sum, which is Δ1+Δ2+(𝜌1+𝜌2)Γ2 by associativity and commutativity. The zero-spine premise is preserved by clause (1), and capture-avoiding composition identifies 𝑈[𝑃/𝑧][𝑁/𝑥] with 𝑈[𝑁/𝑥][𝑃[𝑁/𝑥]/𝑧]. Formation and equality cases use clause (1); constants and unit constructors contribute zero. Positivity and the zero-product property discharge the side conditions in precisely the branches where an output quantity is zero. Every rule is therefore reconstructed with the displayed context. ◻
The multiplication 𝜌Γ2 is not optional bookkeeping. Replacing it by Γ2 undercounts an argument used twice; replacing it by 𝜌+Γ2 is ill sorted because 𝜌 is a scalar and Γ2 is a vector of demands.
If Γ⊢(𝜆𝑥.𝑀)𝑁:𝜎𝑇[𝑁/𝑥], then Γ⊢𝑀[𝑁/𝑥]:𝜎𝑇[𝑁/𝑥]. Consequently compatible beta reduction preserves QTT typing in the displayed function-and-tensor fragment.
Proof. Invert QTT-App and QTT-Lam. Their contexts expose exactly the two premises and the scalar 𝜌 required by theorem 99.6(2). Apply that theorem for the root beta step. For a compatible step, induct on the one-hole term context, use the induction hypothesis for its changed premise, and rebuild the enclosing rule. The dependent result classifier is unchanged by substitution composition. ◻
This corollary is preservation for the frozen beta fragment. It does not assert normalization or decidability for Idris 2, whose elaborator, effects, pattern compilation, and run-time system have a larger signature.
★★☆ Write the QTT-Lam case of theorem 99.6(2). Display the scalar equation aligning the substituted body context with the abstraction rule, and state where alpha-renaming is needed.
Let 𝑛:0𝖭𝖺𝗍 occur in the type 𝖵𝖾𝖼(𝐴,𝑛). The zero annotation says that evaluating the term does not inspect the run-time representation of 𝑛. The type checker may still distinguish 𝖵𝖾𝖼(𝐴,0) from 𝖵𝖾𝖼(𝐴,1), and a proof of 0=1 is not thereby created.
No operational erasure map has been defined, so the proposition makes no claim about compiled representations. It also gives neither proof irrelevance nor term equality: the closed terms 𝗍𝗋𝗎𝖾 and 𝖿𝖺𝗅𝗌𝖾 require no input resources but remain distinguishable by the Boolean eliminator.
Now consider an append operation 𝖺𝗉𝗉𝖾𝗇𝖽:(𝑛:0𝖭𝖺𝗍)→(𝑚:0𝖭𝖺𝗍)→𝖵𝖾𝖼(𝐴,𝑛)→𝖵𝖾𝖼(𝐴,𝑚)→𝖵𝖾𝖼(𝐴,𝑛+𝑚). The indices 𝑛,𝑚 are checked and may occur repeatedly in the result type, but the program traverses the two vector values. In the Idris 2 v0.8.0 tutorial, the corresponding hole context prints 0 beside 𝑛, 𝑚, and 𝐴, and no quantity beside the unrestricted vector arguments. That surface trace witnesses the implementation’s elaborated multiplicities; it is not the proof of theorem 99.6.
The pinned v0.8.0 transcript records the accepted elaboration state as
Main> :t append_rhs
0 m : Nat
0 a : Type
0 n : Nat
ys : Vect m a
xs : Vect n a
-------------------------------------
append_rhs : Vect (plus n m) a
and the nearby attempted linear duplicator is rejected with
While processing right hand side of Main.duplicate:
There are 2 uses of linear name x
These are implementation observations from the retained tutorial [Idr26], not premises of the QTT proofs.
A nearby rejected definition has type (𝑥:1𝐴)→(𝑦:1𝐴)⊗𝐴 and body (𝑥,𝑥). Pair formation adds the two uses, producing demand 1+1, not the binder’s promised 1. An accepted linear state transition instead consumes a door once and returns the new door state, threading the result into the next operation.
★★☆ Give quantitative contexts for both branches of vector append. Verify that the length indices have quantity zero while the vector spine used by the recursive call has positive demand. Explain why replacing the zero on 𝑛 by one changes run-time availability but not the proposition 𝑛+𝑚=𝑚+𝑛.
★★☆ Reconstruct the QTT-App and QTT-Let cases of quantitative substitution over the natural-number semiring. Annotate each distributivity or associativity step and check the zero-output side conditions separately.
★★★ Use the zero–one–many semiring to reconstruct the failed substitution from the source calculus with an arbitrary output quantity. Exhibit the equation 𝜔=1+𝜔, the premise derivation that would have to split, and the missing subusage rule. Then show why restricting output quantities to zero and one blocks the construction.
★★★Practical project.qtt-demand-calculator Implement in Agda or Kappa context vectors over the natural-number and zero–one–many semirings, together with addition, scaling, and the application instance of quantitative substitution. Maintain the invariant that every output vector has the same declaration spine as its inputs. On the named cases twice-of-two, erased-index, and the promise-versus-inferred duplicate-use case, require these exact stdout fragments:
Also require acceptance of a preserved 𝑉𝑋,𝑉𝑌 spine and rejection of a mismatched 𝑉𝑋,𝑉𝑍 spine. A mutation that makes spine comparison constantly true must fail the mismatch oracle. The calculator checks finite semiring equations; it does not prove admissibility for all QTT derivations or an Idris erasure theorem.
Sources. The judgment forms, positive zero-product usage semiring, zero-needs-nothing lemma, and substitution theorem follow Atkey’s QTT calculus [Atk18]. The exact substitution rules and the counterexample to arbitrary output quantities are on p. 5 of the pinned LICS paper. The Idris 2 v0.8.0 multiplicities tutorial supplies the vector-hole and linear resource traces [Idr26]; those implementation traces are kept separate from the paper calculus’s metatheory.