No finite constructor value is the stream 0,1,2,…. The equations 𝗁𝖾𝖺𝖽(𝖿𝗋𝗈𝗆(𝑛))=𝑛,𝗍𝖺𝗂𝗅(𝖿𝗋𝗈𝗆(𝑛))=𝖿𝗋𝗈𝗆(𝗌𝗎𝖼𝑛) nevertheless answer every finite sequence of observations. A termination checker rejects the recursive call because 𝗌𝗎𝖼𝑛 is larger than 𝑛. The relevant invariant is instead that each demanded observation is produced after finitely many definition steps.
Streams are observed, not constructed
Timpl-co extends Timpl by the coinductive record 𝖲𝗍𝗋𝖾𝖺𝗆(𝐴):U𝑖,𝗁𝖾𝖺𝖽:𝖲𝗍𝗋𝖾𝖺𝗆(𝐴)→𝐴,𝗍𝖺𝗂𝗅:𝖲𝗍𝗋𝖾𝖺𝗆(𝐴)→𝖲𝗍𝗋𝖾𝖺𝗆(𝐴). and by declarations made of the two copattern equations 𝗁𝖾𝖺𝖽(𝑓 ⃗𝑥) =𝑒ℎ and 𝗍𝖺𝗂𝗅(𝑓 ⃗𝑥) =𝑒𝑡, whose right sides are generated by 𝑒ℎ::=𝑡∣𝗁𝖾𝖺𝖽(𝑔⃗𝑢),𝑒𝑡::=𝑔⃗𝑢. One finite group is type homogeneous: in a common ambient context it fixes one 𝐴 :U𝑖, and every declaration has type 𝑓𝑗 :(Δ𝑗) →𝖲𝗍𝗋𝖾𝖺𝗆(𝐴). Declarations returning streams with different element types belong to separate groups, even when their call graph is disconnected. If 𝛿𝖼𝗈(𝑓𝑗) =(Δ𝑗;𝑒ℎ,𝑗;𝑒𝑡,𝑗), acceptance checks Γ0,Δ𝑗⊢𝑒ℎ,𝑗:𝐴,Γ0,Δ𝑗⊢𝑒𝑡,𝑗:𝖲𝗍𝗋𝖾𝖺𝗆(𝐴), in addition to the guardedness conditions below. Here 𝑔 ranges over the declarations of the group, and 𝑡 and every ⃗𝑢 are Timpl terms over ⃗𝑥 containing no declaration of the group. Every argument binder retains the inherited Timpl relevance mark of definition 121.5; the displayed Δ𝑗 suppresses those superscripts. These marks control source evaluation and precede the erasure admissibility test: they do not by themselves select a target representation. Argument telescopes are Timpl telescopes, so no declared argument is itself a stream, and only calls among declarations in the same finite group are corecursive. Call a head right side of the first form a producer, one of the second form a head alias, and a tail right side a tail step. No deeper destructor above a group call is inside the card; remark 124.7 shows what the criterion below would cost if one were admitted.
Evaluation is weak-head and observation driven. It unfolds a definition only after a head or tail destructor reaches that definition. The guardedness checker records how many tail observations are discharged before each mutual call. The target is the primitive stream coiterator with the same two coprojection computation rules. No normalization theorem for streams, sized type, coinductive family, effect, clock, or arbitrary record corecursor is added. The elaboration may generate a finite nonrecursive state datatype accepted by Timpl-data; that signature declaration is program data and adds no rule to the target calculus.
Referenced from 6 locations
The operational delta has two explicit layers and hides no source evaluation judgment. Let Σ be the accepted group-free signature: Timpl together with the finite nonrecursive Timpl-data blocks used by the group and by its generated state. Extend the NbE normalizer of definition 49.37, theorem 111.76 with one semantic constructor and one readback clause for each constructor of those blocks, and with the generated Block-comp clause for each eliminator. Because no generated block is recursive, this extension is ordered by declaration order and introduces no semantic fixed point. Write the resulting typed normalizer as nf𝐴Σ,Γ.
The accepted group-free subevaluation is the normalizer interface itself. For a closed group-free ⋅ ⊢𝑡 :𝐴 and a typed normal form 𝑛 :𝐴, define 𝑡⇓𝖳𝑛⟺𝑛=nf𝐴Σ,⋅(𝑡). Thus every premise carrying ⇓𝖳 below asks for the unique typed 𝛽𝜂-long normal form. It does not ask for a separately chosen weak evaluation strategy.
An implementation may compute that normal form in two stages. The first stage is the least call-by-value relation 𝑡 ⇓𝖳,𝖼𝖻𝗏𝑣 displayed below; the second applies nf to 𝑣. This relation is an implementation layer and never defines preparation or a stream rule. Its values are lambdas under either relevance mark, pairs of values, reflexivity values, and primitive or declared constructors whose runtime fields are values and whose erased fields remain checked static syntax. If constructor field 𝑖 has inherited mark 𝜅𝑖, let ̂𝑎𝑖 =𝑣𝑖 when 𝜅𝑖 =𝗋𝗎𝗇𝗍𝗂𝗆𝖾 and 𝑎𝑖 ⇓𝖳,𝖼𝖻𝗏𝑣𝑖, and let ̂𝑎𝑖 =𝑎𝑖 when 𝜅𝑖 =𝖾𝗋𝖺𝗌𝖾𝖽. Values, applications, pairs, projections, declared constructors, and generated cases use 𝑋𝑣⇓𝖳,𝖼𝖻𝗏𝑣T−Val 𝑓⇓𝖳,𝖼𝖻𝗏𝜆𝜖,𝗋𝗎𝗇𝗍𝗂𝗆𝖾(𝑥:𝐴).𝑏𝑎⇓𝖳,𝖼𝖻𝗏𝑣𝑎𝑏[𝑣𝑎/𝑥]⇓𝖳,𝖼𝖻𝗏𝑣𝑓𝜖,𝗋𝗎𝗇𝗍𝗂𝗆𝖾𝑎⇓𝖳,𝖼𝖻𝗏𝑣T−App−R 𝑓⇓𝖳,𝖼𝖻𝗏𝜆𝜖,𝖾𝗋𝖺𝗌𝖾𝖽(𝑥:𝐴).𝑏𝑏[𝑎/𝑥]⇓𝖳,𝖼𝖻𝗏𝑣𝑓𝜖,𝖾𝗋𝖺𝗌𝖾𝖽𝑎⇓𝖳,𝖼𝖻𝗏𝑣T−App−E. 𝑎⇓𝖳,𝖼𝖻𝗏𝑣𝑎𝑏⇓𝖳,𝖼𝖻𝗏𝑣𝑏(𝑎,𝑏)⇓𝖳,𝖼𝖻𝗏(𝑣𝑎,𝑣𝑏)T−Pair 𝑠⇓𝖳,𝖼𝖻𝗏(𝑣𝑎,𝑣𝑏)𝗉𝗋1(𝑠)⇓𝖳,𝖼𝖻𝗏𝑣𝑎T−Fst𝑠⇓𝖳,𝖼𝖻𝗏(𝑣𝑎,𝑣𝑏)𝗉𝗋2(𝑠)⇓𝖳,𝖼𝖻𝗏𝑣𝑏T−Snd. (𝑎𝑖⇓𝖳,𝖼𝖻𝗏𝑣𝑖)𝜅𝑖=𝗋𝗎𝗇𝗍𝗂𝗆𝖾𝑐(𝑎1,…,𝑎𝑛)⇓𝖳,𝖼𝖻𝗏𝑐(̂𝑎1,…,̂𝑎𝑛)T−Con 𝑒⇓𝖳,𝖼𝖻𝗏𝑐𝑘(̂⃗𝑎)𝑒𝑘[̂⃗𝑎/⃗𝑥𝑘]⇓𝖳,𝖼𝖻𝗏𝑣𝖼𝖺𝗌𝖾 𝑒 𝗈𝖿 {𝑐𝑗(⃗𝑥𝑗)⇒𝑒𝑗}𝑗⇓𝖳,𝖼𝖻𝗏𝑣T−Case. The primitive eliminators have their own instances: 𝑏⇓𝖳,𝖼𝖻𝗏𝗍𝗍𝑒𝑡⇓𝖳,𝖼𝖻𝗏𝑣𝗂𝗇𝖽𝟐(𝑥.𝐶;𝑒𝑡,𝑒𝑓,𝑏)⇓𝖳,𝖼𝖻𝗏𝑣T−Bool−T 𝑏⇓𝖳,𝖼𝖻𝗏𝖿𝖿𝑒𝑓⇓𝖳,𝖼𝖻𝗏𝑣𝗂𝗇𝖽𝟐(𝑥.𝐶;𝑒𝑡,𝑒𝑓,𝑏)⇓𝖳,𝖼𝖻𝗏𝑣T−Bool−F. Abbreviate 𝑁𝐶(𝑒0,𝑒𝑠;𝑚):=𝐼𝐶(𝑒0;𝑛𝜚𝑛.𝑟𝜚𝑟.𝑒𝑠;𝑚). Then 𝑚⇓𝖳,𝖼𝖻𝗏𝟢𝑒0⇓𝖳,𝖼𝖻𝗏𝑣𝑁𝐶(𝑒0,𝑒𝑠;𝑚)⇓𝖳,𝖼𝖻𝗏𝑣T−Nat−Z 𝑚⇓𝖳,𝖼𝖻𝗏𝗌𝗎𝖼(𝑣𝑛)𝑁𝐶(𝑒0,𝑒𝑠;𝑣𝑛)⇓𝖳,𝖼𝖻𝗏𝑣𝑟𝑒𝑠[𝑣𝑛/𝑛,𝑣𝑟/𝑟]⇓𝖳,𝖼𝖻𝗏𝑣𝑁𝐶(𝑒0,𝑒𝑠;𝑚)⇓𝖳,𝖼𝖻𝗏𝑣T−Nat−S. Identity elimination and the two vector branches are 𝑒𝑞⇓𝖳,𝖼𝖻𝗏𝗋𝖾𝖿𝗅𝑣𝑞𝑒𝑟[𝑎/𝑧]⇓𝖳,𝖼𝖻𝗏𝑣𝖩𝐴;𝑎;𝑏(𝑥.𝑦.𝑝.𝐶;𝑧𝜚𝑧.𝑒𝑟;𝑒𝑞)⇓𝖳,𝖼𝖻𝗏𝑣T−J, 𝑚⇓𝖳,𝖼𝖻𝗏𝟢𝑦𝑠⇓𝖳,𝖼𝖻𝗏𝗏𝗇𝗂𝗅𝑒0⇓𝖳,𝖼𝖻𝗏𝑣𝗏𝗂𝗇𝖽(𝑃;𝑒0;𝑛𝜚𝑛.𝑎𝜚𝑎.𝑥𝑠.𝑟𝜚𝑟.𝑒𝑠;𝑚,𝑦𝑠)⇓𝖳,𝖼𝖻𝗏𝑣T−Vec−Nil 𝑚⇓𝖳,𝖼𝖻𝗏𝗌𝗎𝖼(𝑣𝑛)𝑦𝑠⇓𝖳,𝖼𝖻𝗏𝗏𝖼𝗈𝗇𝗌(𝑣𝑛,𝑣𝑎,𝑣𝑥𝑠)𝗏𝗂𝗇𝖽(𝑃;𝑒0;𝑛𝜚𝑛.𝑎𝜚𝑎.𝑥𝑠.𝑟𝜚𝑟.𝑒𝑠;𝑣𝑛,𝑣𝑥𝑠)⇓𝖳,𝖼𝖻𝗏𝑣𝑟𝑒𝑠[𝑣𝑛/𝑛,𝑣𝑎/𝑎,𝑣𝑥𝑠/𝑥𝑠,𝑣𝑟/𝑟]⇓𝖳,𝖼𝖻𝗏𝑣𝗏𝗂𝗇𝖽(𝑃;𝑒0;𝑛𝜚𝑛.𝑎𝜚𝑎.𝑥𝑠.𝑟𝜚𝑟.𝑒𝑠;𝑚,𝑦𝑠)⇓𝖳,𝖼𝖻𝗏𝑣T−Vec−Cons. There is no named-recursion rule in either interface: the group-free signature fixed above is Timpl plus nonrecursive Timpl-data blocks. A neutral or mismatched scrutinee has no CBV implementation rule. Define a preparation function from the inherited relevance marks by recursion on a dependent telescope: 𝗉𝗋𝖾𝗉⋅(⋅)=⋅,𝗉𝗋𝖾𝗉Δ,𝑥𝗋𝗎𝗇𝗍𝗂𝗆𝖾:𝐴(⃗𝑎,𝑏)=(⃗𝑣,𝑤)if 𝗉𝗋𝖾𝗉Δ(⃗𝑎)=⃗𝑣 and 𝑏[⃗𝑣/⃗𝑥]⇓𝖳𝑤,𝗉𝗋𝖾𝗉Δ,𝑥𝖾𝗋𝖺𝗌𝖾𝖽:𝐴(⃗𝑎,𝑏)=(⃗𝑣,𝑛)if 𝗉𝗋𝖾𝗉Δ(⃗𝑎)=⃗𝑣 and 𝑛=nf𝐴[⃗𝑣/⃗𝑥]Σ,⋅(𝑏[⃗𝑣/⃗𝑥]). A runtime component is normalized as demanded subevaluation. An erased component is canonicalized by the same typed normalizer at preparation time; it is never forced by an operational CBV frame. Thus every prepared component is a typed normal form, while the inherited mark still records which components survive runtime erasure. This preparation is not the erasure judgment that selects a target representation. The coinductive declarations add the following three rules and no eager unfolding rule for a bare stream call: 𝛿𝖼𝗈(𝑓𝑖)=(Δ𝑖;𝑡;𝑒𝑡)𝗉𝗋𝖾𝗉Δ𝑖(⃗𝑎)=⃗𝑎𝑣𝑡[⃗𝑎𝑣/⃗𝑥]⇓𝖳𝑣𝗁𝖾𝖺𝖽(𝑓𝑖⃗𝑎)⇓𝑣Co−Head−Producer, 𝛿𝖼𝗈(𝑓𝑖)=(Δ𝑖;𝗁𝖾𝖺𝖽(𝑔⃗𝑢);𝑒𝑡)𝗉𝗋𝖾𝗉Δ𝑖(⃗𝑎)=⃗𝑎𝑣𝗉𝗋𝖾𝗉Δ𝑔(⃗𝑢[⃗𝑎𝑣/⃗𝑥])=⃗𝑏𝗁𝖾𝖺𝖽(𝑔⃗𝑏)⇓𝑣𝗁𝖾𝖺𝖽(𝑓𝑖⃗𝑎)⇓𝑣Co−Head−Alias, 𝛿𝖼𝗈(𝑓𝑖)=(Δ𝑖;𝑒ℎ;𝑔⃗𝑢)𝗉𝗋𝖾𝗉Δ𝑖(⃗𝑎)=⃗𝑎𝑣𝗉𝗋𝖾𝗉Δ𝑔(⃗𝑢[⃗𝑎𝑣/⃗𝑥])=⃗𝑏𝗍𝖺𝗂𝗅(𝑓𝑖⃗𝑎)⇓𝑔⃗𝑏Co−Tail−Unfold. The first rule delegates only the group-free producer to the extended NbE subevaluation. The second follows one head-alias edge after preparing its group-free arguments. The third exposes one tail step with prepared arguments and stops, so a later observation controls whether the resulting stream call is unfolded again. Erased arguments are normalized statically, not forced by a runtime frame.
Referenced from 5 locations
For every accepted group-free signature Σ and Γ ⊢𝑒 :𝐴:
nf𝐴Σ,Γ(𝑒) is total, well typed, and unique;
𝑒 ≡nf𝐴Σ,Γ(𝑒) (soundness);
for any Γ ⊢𝑒′ :𝐴, 𝑒≡𝑒′⟺nf𝐴Σ,Γ(𝑒)=nf𝐴Σ,Γ(𝑒′) up to 𝛼-equality (completeness);
every typed normal form is fixed by nf𝐴Σ,Γ (stability);
if 𝜃,𝜃′ :Γ′ →Γ are well-typed substitutions with judgmentally equal corresponding components, write 𝐴𝜃 for 𝐴[𝜃] and convert 𝑒[𝜃′] along 𝐴[𝜃′] ≡𝐴𝜃. Then nf𝐴𝜃Σ,Γ′(𝑒[𝜃])=nf𝐴𝜃Σ,Γ′(𝑒[𝜃′]).
Consequently, for every closed well-typed 𝑒 :𝐴, there is exactly one typed normal form 𝑛 :𝐴 with 𝑒 ⇓𝖳𝑛, and 𝑒⇓𝖳𝑛⟺(𝑒≡𝑛 and 𝑛 is normal). The optional implementation layer is deterministic on closed typed terms. If 𝑒 ⇓𝖳,𝖼𝖻𝗏𝑣, then 𝑒≡𝑣,nf(𝑒)=nf(𝑣),𝑒⇓𝖳nf(𝑣).
Referenced from 13 locations
Proof of Lemma 124.3 — Group-free normalization and evaluation interface
Proof. Induct on the declaration order of Σ. The empty extension is theorem 111.76, lemma 111.77. For one nonrecursive Timpl-data block, extend the semantic domain by disjoint constructor tags carrying the semantic interpretations of their already interpreted fields. Evaluation of an introduction returns that tag. Evaluation of its eliminator inspects the tag and applies the corresponding generated method; this is exactly Block-comp. A neutral scrutinee is reflected as a stuck eliminator, and readback reconstructs it. Structural induction on the finite constructor telescope proves that evaluation and readback are functional. The proof of the fundamental lemma gains precisely the introduction, neutral-elimination, and Block-comp cases just described; none recurses through the new family. The escape argument therefore gives typing and soundness, the semantic equality argument gives completeness, and induction on normal forms gives stability, exactly as in theorem 111.76, lemma 111.77. The same declaration-order induction proves definedness of the new semantic operations: every Block-comp clause consumes a constructor tag from the block being interpreted and invokes methods over previously interpreted field types, so no semantic call returns to the new family.
For item 5, ordinary substitution gives 𝑒[𝜃] ≡𝑒[𝜃′] from the component equations, after the displayed classifier conversion. Completeness from item 3 makes their normal forms identical.
The definition of ⇓𝖳 makes existence and uniqueness immediate from item 1. Soundness gives the forward implication of the displayed characterization. Conversely, completeness and stability show that any normal 𝑛 judgmentally equal to 𝑒 is the normalizer output.
For the implementation claims, first prove determinism by induction on the first ⇓𝖳,𝖼𝖻𝗏 derivation and inversion of a second derivation. Disjoint value constructors select the same rule; the induction hypotheses identify each runtime premise and then the selected branch. In T-Nat-S and T-Vec-Cons, apply the hypotheses first to the scrutinee, then to the strictly smaller recursive-eliminator premise, and finally to the branch body. These are the only rules with a recursive evaluation premise.
Finally, induct on a ⇓𝖳,𝖼𝖻𝗏 derivation, retaining its typing derivation, to prove 𝑒 ≡𝑣. Rule T-Val uses reflexivity. For T-App-R, inversion gives 𝑓 :∏𝜖,𝗋𝗎𝗇𝗍𝗂𝗆𝖾𝑥:𝐴0𝐵 and 𝑎 :𝐴0. The induction hypotheses and the application computation rule give 𝑓𝑎𝑐𝑜𝑛𝑔𝑟𝑢𝑒𝑛𝑐𝑒≡(𝜆𝑥.𝑏)𝑣𝑎Π−𝛽≡𝑏[𝑣𝑎/𝑥]𝐼𝐻≡𝑣. Substitution congruence for 𝑎 ≡𝑣𝑎 converts the chain from 𝐵[𝑣𝑎/𝑥] to 𝐵[𝑎/𝑥]. Rule T-App-E uses the same chain with the unchanged checked argument 𝑎. Rule T-Pair uses dependent pair congruence, converting the second induction hypothesis along the first one. Rules T-Fst and T-Snd compose scrutinee congruence with the corresponding Σ-computation equation; the second projection result is converted along congruence of first projection.
Rule T-Con uses constructor congruence on each runtime field and reflexivity on each static field. For T-Case, scrutinee congruence reaches the selected constructor, Block-comp exposes the selected branch, and simultaneous substitution congruence followed by the branch induction hypothesis reaches 𝑣. Motive conversion follows the scrutinee equality. Rules T-Bool-T and T-Bool-F are the two primitive instances.
For T-Nat-Z, combine scrutinee congruence, Nat-comp1, and the base induction hypothesis. For T-Nat-S, scrutinee congruence and Nat-comp2 expose the step body. The predecessor and recursive-result induction hypotheses justify simultaneous substitution, and the branch induction hypothesis reaches 𝑣; conversion along 𝑚 ≡𝗌𝗎𝖼(𝑣𝑛) restores the original motive. In T-J, proof soundness gives 𝑒𝑞 ≡𝗋𝖾𝖿𝗅𝑣𝑞. Identity-value inversion gives 𝑣𝑞 ≡𝑎 ≡𝑏; after those conversions, Id-comp exposes 𝑒𝑟[𝑎/𝑧], and its induction hypothesis reaches 𝑣.
Rule T-Vec-Nil uses the index and vector induction hypotheses, Vec-comp1, and conversion along 𝑚 ≡0 and 𝑦𝑠 ≡𝗏𝗇𝗂𝗅. Rule T-Vec-Cons uses Vec-comp2; simultaneous congruence substitutes the equal predecessor, head, tail, and recursive result, while conversion along 𝑚 ≡𝗌𝗎𝖼(𝑣𝑛) and 𝑦𝑠 ≡𝗏𝖼𝗈𝗇𝗌(𝑣𝑛,𝑣𝑎,𝑣𝑥𝑠) restores the declared indexed motive. These cases exhaust the implementation rule card. Normalizer completeness gives nf(𝑒) =nf(𝑣), and the definition of ⇓𝖳 gives 𝑒 ⇓𝖳nf(𝑣). For example, 𝜆𝑥.((𝜆𝑦.𝑦) 𝑥) ⇓𝖳,𝖼𝖻𝗏𝜆𝑥.((𝜆𝑦.𝑦) 𝑥) by T-Val, after which the required second stage returns the NbE normal form 𝜆𝑥.𝑥. ◻
Let ⃗𝑎 be a closed, well-typed tuple of group-free Timpl terms for a telescope Δ. There is a unique prepared tuple ⃗𝑎𝑣 such that 𝗉𝗋𝖾𝗉Δ(⃗𝑎) =⃗𝑎𝑣.
Referenced from 4 locations
Proof of Lemma 124.4 — Preparation is total and unique
Proof. Induct on Δ. The empty tuple has the unique empty result. For a runtime extension, apply the induction hypothesis to the prefix, substitute its result into the last component, and use lemma 124.3 to obtain its unique typed normal form. For an erased extension, the induction hypothesis fixes the prefix and totality and uniqueness of the same typed normalizer fix the canonical static component. These are exactly the two recursive clauses of 𝗉𝗋𝖾𝗉. ◻
The rule delta permits the opening definition. It also permits 𝗓𝖾𝗋𝗈𝗌, given by 𝗁𝖾𝖺𝖽(𝗓𝖾𝗋𝗈𝗌)=0,𝗍𝖺𝗂𝗅(𝗓𝖾𝗋𝗈𝗌)=𝗓𝖾𝗋𝗈𝗌. It does not permit the equation 𝗁𝖾𝖺𝖽(𝖻𝖺𝖽) =𝗁𝖾𝖺𝖽(𝖻𝖺𝖽): evaluating the first observation repeats the same demand without producing a numeral.
An observation word is generated by 𝑜::=𝗁𝖾𝖺𝖽∣𝗍𝖺𝗂𝗅⋅𝑜. For a closed stream term 𝑠, the partial judgment 𝑠 ⇓𝑜𝑣 means that weak-head evaluation of the destructor path 𝑜 terminates at the closed value 𝑣 :𝐴. Its rules are 𝗁𝖾𝖺𝖽(𝑠)⇓𝑣𝑠⇓𝗁𝖾𝖺𝖽𝑣𝗍𝖺𝗂𝗅(𝑠)⇓𝑠′𝑠′⇓𝑜𝑣𝑠⇓𝗍𝖺𝗂𝗅⋅𝑜𝑣. A closed stream is productive when for every observation word 𝑜 there exists a closed value 𝑣 with 𝑠 ⇓𝑜𝑣.
Referenced from 3 locations
★☆☆ Using 𝗉𝗋𝖾𝗉𝑛:ℕ(0) =(0), give the complete derivation of 𝖿𝗋𝗈𝗆(0) ⇓𝗍𝖺𝗂𝗅⋅𝗁𝖾𝖺𝖽1. Name the source declaration rule used at each destructor and the finite-observation rule that assembles them.
Referenced from 3 locations
For 𝖿𝗋𝗈𝗆(0), the first three words compute to 𝖿𝗋𝗈𝗆(0)⇓𝗁𝖾𝖺𝖽0,𝖿𝗋𝗈𝗆(0)⇓𝗍𝖺𝗂𝗅⋅𝗁𝖾𝖺𝖽1,𝖿𝗋𝗈𝗆(0)⇓𝗍𝖺𝗂𝗅⋅𝗍𝖺𝗂𝗅⋅𝗁𝖾𝖺𝖽2. The definition never returns a complete stream value. Productivity asks only for the value at each finite word.
Mutual calls need a guard cycle condition
One guarded edge per definition is too strong. A finite chain of aliases may precede the equation that produces an observation. What must be excluded is an entire cycle of aliases.
The guard-weighted call graph of a finite Timpl-co group has one vertex per defined stream function. Every group call occurs in exactly one of the two right-side forms of definition 124.1, so the weight of an edge is total and takes only two values: a head alias 𝗁𝖾𝖺𝖽(𝑓 ⃗𝑥) =𝗁𝖾𝖺𝖽(𝑔 ⃗𝑢) emits 𝑓0→𝑔, and a tail step 𝗍𝖺𝗂𝗅(𝑓 ⃗𝑥) =𝑔 ⃗𝑢 emits 𝑓1→𝑔. A producer emits no edge. The weight is the number of observations discharged between the demand at 𝑓 and the demand it passes to 𝑔: a head alias passes the same demand, a tail step passes a demand one symbol shorter.
The judgment ⊢G 𝗀𝗎𝖺𝗋𝖽𝖾𝖽 holds when the subgraph of zero-weight edges is acyclic. Since every weight is 0 or 1, this says equivalently that every directed cycle carries a positive-weight edge, and also that every directed cycle has positive total weight. A topological rank 𝑟(𝑓) of the zero-edge subgraph is stored in the certificate, decreasing along every zero edge.
Referenced from 4 locations
For the mutually defined streams 𝗁𝖾𝖺𝖽(𝑒)=0,𝗍𝖺𝗂𝗅(𝑒)=𝑜,𝗁𝖾𝖺𝖽(𝑜)=1,𝗍𝖺𝗂𝗅(𝑜)=𝑒, both call edges have weight one. For 𝗁𝖾𝖺𝖽(𝑓) =𝗁𝖾𝖺𝖽(𝑔) and 𝗁𝖾𝖺𝖽(𝑔) =𝗁𝖾𝖺𝖽(𝑓), both edges have weight zero, so the checker reports that cycle.
The Timpl-co guardedness checker terminates on every finite declaration group. If it accepts, every zero-weight call strictly decreases the stored rank.
Referenced from 4 locations
Proof of Lemma 124.8 — Guard checking terminates
Proof. The checker traverses each finite right side once, emitting a finite graph. It deletes positive edges and performs depth-first cycle detection on the remaining finite graph. If no back edge is found, reverse finishing order is a topological ranking. Every zero edge points to a vertex with smaller rank by construction. All traversals therefore terminate and the returned rank has the stated property. ◻
★☆☆ Give the weighted call graph for the complete group 𝗁𝖾𝖺𝖽(𝑓)=𝗁𝖾𝖺𝖽(𝑔),𝗁𝖾𝖺𝖽(𝑔)=𝗁𝖾𝖺𝖽(ℎ),𝗁𝖾𝖺𝖽(ℎ)=0,𝗍𝖺𝗂𝗅(𝑓)=𝑔,𝗍𝖺𝗂𝗅(𝑔)=ℎ,𝗍𝖺𝗂𝗅(ℎ)=𝑓. Delete the positive edges and give one valid rank assignment.
Referenced from 5 locations
Every finite demand is met
The proof uses a lexicographic measure. The observation length decreases when a positive edge is crossed. Between positive edges, the stored topological rank decreases.
Let G be guarded. For a declared 𝑓 and any tuple ⃗𝑎 of closed group-free Timpl terms in its input telescope, consider the closed call 𝑓 ⃗𝑎. For a demanded head observation, evaluation either returns a closed Timpl value or follows a zero-weight mutual call to 𝑔 ⃗𝑏, again with closed group-free arguments, and 𝑟(𝑔) <𝑟(𝑓). For a demanded tail observation, evaluation returns such a closed declared call 𝑔 ⃗𝑏 in one Co-Tail-Unfold step.
Referenced from 3 locations
Proof of Lemma 124.9 — One demanded destructor makes progress
Proof. Inspect the selected copattern equation. A head right side is in the nonrecursive terminating Timpl fragment except for recorded zero-weight calls. By lemma 124.4, the preparation function first produces 𝗉𝗋𝖾𝗉Δ𝑓(⃗𝑎) =⃗𝑎𝑣. Substitution of ⃗𝑎𝑣 leaves every alias argument closed and group-free, and its componentwise evaluation produces the closed tuple required by Co-Head-Alias. Each alias call decreases rank by lemma 124.8; finite induction on 𝑟(𝑓) reaches a right side with no zero call and returns its normal form by the extended NbE subevaluation. A tail equation discharges the demanded tail and Co-Tail-Unfold returns its root mutual call after componentwise evaluation; the system-card side condition makes its arguments closed and group-free. These are the two coprojection forms of the system card. ◻
If Timpl-co accepts a group G, then every closed call to a declared stream function is productive in the sense of definition 124.5.
Referenced from 6 locations
Proof of Theorem 124.10 — Productivity of accepted stream groups
Proof. Generalize over the declared function 𝑓 and every closed group-free input tuple ⃗𝑎, then fix an observation word 𝑜. Induct lexicographically on the number of tail symbols in 𝑜 and the stored rank of 𝑓. For a head word, lemma 124.9 either returns a value or follows a zero edge and decreases the second component. For 𝗍𝖺𝗂𝗅 ⋅𝑜′, the same lemma computes the tail to a closed call 𝑔 ⃗𝑏. The recursive demand 𝑜′ has one fewer tail symbol, so the generalized outer induction hypothesis applies to the arbitrary closed tuple ⃗𝑏 and gives its value. The two clauses construct a finite derivation 𝑠 ⇓𝑜𝑣 for every 𝑜. ◻
Let G be guarded and type homogeneous. Fix its element type 𝐴, and generate the nonrecursive Timpl-data block 𝖲𝗍𝖺𝗍𝖾G:Uℓ,𝗂𝗇𝑖:(⃗𝑎:Δ𝑖)→𝖲𝗍𝖺𝗍𝖾G. No constructor argument mentions the generated family, so definition 122.4 accepts the block. Its universe level is the maximum accepted level of the input telescopes.
Head aliases are resolved statically first, because a head equation whose right side is 𝗁𝖾𝖺𝖽(𝑔 ⃗𝑢) would otherwise make the head map of the coiterator call itself, and the coiterator takes a Timpl function, not a second recursive definition. Repeatedly replace such a right side by the head right side of 𝑔 under the substitution ⃗𝑢. Each replacement follows one zero-weight edge, so by lemma 124.8 it strictly decreases the stored rank; after at most 𝑟(𝑓𝑖) replacements the right side is a producer. Write ˆ𝑒𝑖 for the resulting group-free head right side of 𝑓𝑖, and let 𝗍𝖺𝗂𝗅(𝑓𝑖 ⃗𝑥) =𝑓𝜏(𝑖) ⃗𝑢𝑖 be its tail step. Now define ℎ:𝖲𝗍𝖺𝗍𝖾G→𝐴,ℎ(𝗂𝗇𝑖(⃗𝑎)):=ˆ𝑒𝑖[⃗𝑎/⃗𝑥],𝑡:𝖲𝗍𝖺𝗍𝖾G→𝖲𝗍𝖺𝗍𝖾G,𝑡(𝗂𝗇𝑖(⃗𝑎)):=𝗂𝗇𝜏(𝑖)(⃗𝑢𝑖[⃗𝑎/⃗𝑥]), both by the eliminator of the generated state datatype. For later equations, abbreviate the normal state 𝗌𝗍𝑖(⃗𝑎):=nf𝖲𝗍𝖺𝗍𝖾GΣ,⋅(𝗂𝗇𝑖(⃗𝑎)). For a prepared tuple ⃗𝑎𝑣, constructor normality and stability give 𝗌𝗍𝑖(⃗𝑎𝑣) =𝗂𝗇𝑖(⃗𝑎𝑣). The abbreviation keeps the state-normalization premise visible when the input tuple has not yet been prepared. Elaboration sends a source call 𝑓𝑖 ⃗𝑎 to 𝖼𝗈𝗂𝗍𝖾𝗋(ℎ,𝑡,𝗂𝗇𝑖(⃗𝑎)). Its primitive equations are 𝗁𝖾𝖺𝖽(𝖼𝗈𝗂𝗍𝖾𝗋(ℎ,𝑡,𝑠))⇝0ℎ(𝑠),𝗍𝖺𝗂𝗅(𝖼𝗈𝗂𝗍𝖾𝗋(ℎ,𝑡,𝑠))⇝0𝖼𝗈𝗂𝗍𝖾𝗋(ℎ,𝑡,𝑡(𝑠)). The coiterator is strict in its state. More exactly, if 𝑠𝑣 and 𝑠′𝑣 are closed typed normal forms of 𝖲𝗍𝖺𝗍𝖾G, the two contractions induce the evaluation rules 𝑠⇓𝖳𝑠𝑣ℎ(𝑠𝑣)⇓𝖳𝑣𝗁𝖾𝖺𝖽(𝖼𝗈𝗂𝗍𝖾𝗋(ℎ,𝑡,𝑠))⇓𝑣Coiter−Head and 𝑠⇓𝖳𝑠𝑣𝑡(𝑠𝑣)⇓𝖳𝑠′𝑣𝗍𝖺𝗂𝗅(𝖼𝗈𝗂𝗍𝖾𝗋(ℎ,𝑡,𝑠))⇓𝖼𝗈𝗂𝗍𝖾𝗋(ℎ,𝑡,𝑠′𝑣)Coiter−Tail. Thus a tail observation evaluates the next state before returning the next stream. This convention is unobservable in the total, group-free state language, but it fixes the state normal form that the erasure translation stores in both target closures.
Referenced from 7 locations
★☆☆ For the two-vertex alternating group with 𝗁𝖾𝖺𝖽(𝑒) =0, 𝗁𝖾𝖺𝖽(𝑜) =1, 𝗍𝖺𝗂𝗅(𝑒) =𝑜, and 𝗍𝖺𝗂𝗅(𝑜) =𝑒, take 𝖲𝗍𝖺𝗍𝖾G with nullary constructors 𝗂𝗇𝑒,𝗂𝗇𝑜. Write the complete definitions of ℎ and 𝑡, then derive 𝗍𝖺𝗂𝗅(𝖼𝗈𝗂𝗍𝖾𝗋(ℎ,𝑡,𝗂𝗇𝑒)) by Coiter-Tail, including both ⇓𝖳 premises.
Referenced from 3 locations
Let Γ and Δ be dependent Timpl telescopes. Let 𝜂 be a closed group-free tuple for Γ, and let 𝜃 be a group-free tuple for Δ in context Γ. If 𝗉𝗋𝖾𝗉Γ(𝜂)=𝜂𝑣,𝗉𝗋𝖾𝗉Δ[𝜂𝑣](𝜃[𝜂𝑣])=𝜃𝑣, then preparation of the concatenated tuple is 𝗉𝗋𝖾𝗉Γ,Δ(𝜂,𝜃[𝜂])=(𝜂𝑣,𝜃𝑣). Moreover, for every group-free runtime term 𝑒 typed under Δ and closed typed normal form 𝑤, 𝑒[𝜃[𝜂𝑣]/Δ]⇓𝖳𝑤⟺𝑒[𝜃𝑣/Δ]⇓𝖳𝑤.
Referenced from 5 locations
Proof of Lemma 124.12 — Preparation composes with group-free substitution
Proof. Induct on Δ. The empty suffix gives the first equation immediately. At a runtime binder, substitution composition identifies the term prepared by the recursive clause with the corresponding component of 𝜃[𝜂𝑣]; totality and determinism in lemma 124.3 supply the component of 𝜃𝑣. At an erased binder, substitution composition identifies the same typed input to the normalizer, whose uniqueness supplies the component of 𝜃𝑣. This proves the concatenation equation.
For the second claim, compare the two simultaneous substitutions component by component. At a runtime position, the defining premise of preparation and soundness in lemma 124.3 give judgmental equality between the unprepared component and its normal form. At an erased position, normalizer soundness gives the same judgmental equality. Dependent substitution congruence, in telescope order, therefore gives 𝑒[𝜃[𝜂𝑣]/Δ]≡𝑒[𝜃𝑣/Δ] at the common converted result type. Completeness in lemma 124.3 identifies their normal forms. By the definition of ⇓𝖳, either displayed subevaluation judgment holds exactly when that common normal form is 𝑤, which proves both implications. ◻
If every component of a closed group-free tuple ⃗𝑏 :Δ is a typed normal form after substitution of its prefix, then 𝗉𝗋𝖾𝗉Δ(⃗𝑏) =⃗𝑏.
Referenced from 5 locations
Proof of Lemma 124.13 — Prepared tuples are fixed points
Proof. Induct on Δ. Both extensions use stability of closed typed normal forms; the relevance mark determines only which preparation clause records the normalizer call. In both cases the induction hypothesis fixes the prefix, so the dependent substitution into the final component is unchanged. ◻
Fix a declaration 𝑓𝑖 :(Δ𝑖) →𝖲𝗍𝗋𝖾𝖺𝗆(𝐴) in an accepted group. Let ⃗𝑎 be a closed group-free tuple and suppose 𝗉𝗋𝖾𝗉Δ𝑖(⃗𝑎) =⃗𝑎𝑣. For every closed typed normal form 𝑤 :𝐴, 𝗁𝖾𝖺𝖽(𝑓𝑖⃗𝑎)⇓𝑤⟺ℎ(𝗌𝗍𝑖(⃗𝑎𝑣))⇓𝖳𝑤. For every group declaration 𝑓𝑗 and closed prepared tuple ⃗𝑏, 𝗍𝖺𝗂𝗅(𝑓𝑖⃗𝑎)⇓𝑓𝑗⃗𝑏⟺𝑡(𝗌𝗍𝑖(⃗𝑎𝑣))⇓𝖳𝗌𝗍𝑗(⃗𝑏).
Referenced from 5 locations
Proof of Lemma 124.14 — Source/map evaluation agreement
Proof. First, soundness of normalization and congruence give ℎ(𝗌𝗍𝑖(⃗𝑎𝑣))≡ℎ(𝗂𝗇𝑖(⃗𝑎𝑣)),𝑡(𝗌𝗍𝑖(⃗𝑎𝑣))≡𝑡(𝗂𝗇𝑖(⃗𝑎𝑣)). Completeness therefore lets either map be calculated at the constructor and then normalized.
For the head equivalence, induct on the stored rank of 𝑓𝑖. A producer rule normalizes ˆ𝑒𝑖[⃗𝑎𝑣/⃗𝑥], which is the branch selected by ℎ(𝗂𝗇𝑖(⃗𝑎𝑣)). For an alias to 𝑓𝑗 ⃗𝑢, Co-Head-Alias first derives 𝗉𝗋𝖾𝗉Δ𝑗(⃗𝑢[⃗𝑎𝑣/⃗𝑥])=⃗𝑏 and then evaluates 𝗁𝖾𝖺𝖽(𝑓𝑗 ⃗𝑏). Static alias resolution defines ˆ𝑒𝑖 as ˆ𝑒𝑗 under the same simultaneous substitution. By lemma 124.12, the resolved expression receives the same prepared tuple ⃗𝑏; the induction hypothesis for 𝑓𝑗, whose rank is smaller, gives both implications. This treats the producer and alias rule families.
For the tail equivalence, invert Co-Tail-Unfold. It fixes 𝑗 =𝜏(𝑖) and derives 𝗉𝗋𝖾𝗉Δ𝑗(⃗𝑢𝑖[⃗𝑎𝑣/⃗𝑥]) =⃗𝑏. The generated branch for 𝑡 first contracts to 𝗂𝗇𝜏(𝑖)(⃗𝑢𝑖[⃗𝑎𝑣/⃗𝑥]). For every runtime component, preparation soundness identifies that component judgmentally with the corresponding component of ⃗𝑏. For every erased component, preparation replaces the checked substitution term by its typed NbE normal form; normalizer soundness makes those two terms judgmentally equal. Constructor congruence and completeness therefore identify the branch normal form with 𝗌𝗍𝜏(𝑖)(⃗𝑏). Conversely, injectivity of the generated constructor tag identifies the prepared components, and normalizer uniqueness identifies each erased canonical component with the one fixed by preparation. Hence the same prepared tuple is recovered and Co-Tail-Unfold applies. The declaration index fixes 𝑗 =𝜏(𝑖). ◻
Let 𝑠 be a closed call accepted by Timpl-co and let 𝑠† be its coiterator elaboration. For every observation word 𝑜 and closed value 𝑣, 𝑠⇓𝑜𝑣⟺𝑠†⇓𝑜𝑣.
Referenced from 4 locations
Proof of Theorem 124.15 — Finite-observation simulation
Proof. Write 𝑠 =𝑓𝑖 ⃗𝑎. Generalize over 𝑓𝑖 and every closed group-free tuple ⃗𝑎 :Δ𝑖, then induct on 𝑜. Normalizer-defined preparation gives a unique tuple ⃗𝑎𝑣 with 𝗉𝗋𝖾𝗉Δ𝑖(⃗𝑎) =⃗𝑎𝑣. Preparation soundness and constructor congruence identify the normal forms, so 𝗂𝗇𝑖(⃗𝑎)⇓𝖳𝗌𝗍𝑖(⃗𝑎𝑣).
For 𝗁𝖾𝖺𝖽, invert the source observation rule and apply the head equivalence of lemma 124.14. Its right side together with the displayed constructor evaluation is precisely Coiter-Head, so the elaborated call has the same head observation. Inverting Coiter-Head and using the converse implication of the lemma proves the reverse direction.
For 𝗍𝖺𝗂𝗅 ⋅𝑜′, source inversion gives a uniquely determined closed call 𝑓𝑗 ⃗𝑏, together with 𝗍𝖺𝗂𝗅(𝑓𝑖⃗𝑎)⇓𝑓𝑗⃗𝑏,𝑓𝑗⃗𝑏⇓𝑜′𝑣. The tail equivalence of lemma 124.14 and Coiter-Tail derive 𝗍𝖺𝗂𝗅(𝖼𝗈𝗂𝗍𝖾𝗋(ℎ,𝑡,𝗂𝗇𝑖(⃗𝑎)))⇓𝖼𝗈𝗂𝗍𝖾𝗋(ℎ,𝑡,𝗌𝗍𝑗(⃗𝑏)). By lemma 124.13, the tuple ⃗𝑏 is fixed by preparation. The raw elaborated state 𝗂𝗇𝑗(⃗𝑏) and the state 𝗌𝗍𝑗(⃗𝑏) both subevaluate to the latter by definition and stability. Hence every first Coiter-Head or Coiter-Tail premise is identical for the two target streams. Apply the generalized induction hypothesis to the closed call 𝑓𝑗 ⃗𝑏 and the shorter word 𝑜′. Conversely, inversion of Coiter-Tail, the converse tail equivalence, and the same induction hypothesis reconstruct the two source premises. These are the two forms of observation word. ◻
The observation-first presentation and copattern typing follow Abel, Pientka, Thibodeau, and Setzer, Sections 3–5 [APTS13]. Their paper intentionally separates typing from productivity. The cycle criterion and productivity theorem above belong only to the stream fragment fixed in definition 124.1; Giménez’s guarded schemes provide the historical boundary [Gim95].
Suggested first pass.
None of these problems is a prerequisite for a later chapter. Begin with exercise 124.4, then complete exercise 124.6.
★★☆ Elaborate 𝖿𝗋𝗈𝗆 to a coiterator with state ℕ. Calculate the observation word with three tails followed by head on both source and target, annotating every coprojection contraction.
Referenced from 4 locations
★★☆ Take the complete group of exercise 124.2, whose zero-weight subgraph is the path 𝑓 →𝑔 →ℎ. Give its topological rank, say which edge every directed cycle must use and why that edge is positive, and prove productivity directly by the lexicographic measure used in theorem 124.10.
Referenced from 3 locations
★★★ Practical project.corecursive-group-observer Represent a declaration by its two copattern equations and derive the weighted call graph from them, so that a zero edge exists exactly when a head alias does. Compute a topological rank by one relaxation round per vertex and verify the stored certificate of definition 124.6: every zero edge strictly decreases the rank. Apply that test at every vertex, not at one chosen start. Also perform the static head-alias resolution of definition 124.11, bounded by the vertex count. Print the first four observations of from-0 as 0,1,2,3; accept alternating and the three-vertex alias-chain with their ranks; print the resolved head of every declaration in the alias chain; reject head-loop with the zero cycle you computed. Two mutations must fail the oracle: relaxing once instead of once per vertex, and dropping the strict rank decrease. The observer witnesses finite demands; it does not prove normalization of Timpl-co.
Referenced from 5 locations