Exercise 85.1.
Take state 𝟐, output the state itself, transition Boolean negation, and initial state 𝗍𝗍: 𝖺𝗅𝗍𝖾𝗋𝗇𝖺𝗍𝖾:=𝖼𝗈𝗋𝖾𝖼𝟐(𝟐,𝜆𝑥.𝑥,𝗇𝗈𝗍,𝗍𝗍). The state iterates at depths 0 through 4 are 𝗍𝗍,𝖿𝖿,𝗍𝗍,𝖿𝖿,𝗍𝗍, respectively. Applying the output function, which is the identity, gives the same five observations.
Exercise 85.2.
The complete clauses are 𝗁𝖾𝖺𝖽(𝗓𝗂𝗉𝖶𝗂𝗍𝗁(𝑓,𝑠,𝑡))=𝑓(𝗁𝖾𝖺𝖽(𝑠))(𝗁𝖾𝖺𝖽(𝑡)),𝗍𝖺𝗂𝗅(𝗓𝗂𝗉𝖶𝗂𝗍𝗁(𝑓,𝑠,𝑡))=𝗓𝗂𝗉𝖶𝗂𝗍𝗁(𝑓,𝗍𝖺𝗂𝗅(𝑠),𝗍𝖺𝗂𝗅(𝑡)). Compile them with state 𝖲𝗍𝗋𝖾𝖺𝗆(𝐴) ×𝖲𝗍𝗋𝖾𝖺𝗆(𝐵) and maps 𝑜(𝑢,𝑣):=𝑓(𝗁𝖾𝖺𝖽(𝑢))(𝗁𝖾𝖺𝖽(𝑣)),𝑑(𝑢,𝑣):=(𝗍𝖺𝗂𝗅(𝑢),𝗍𝖺𝗂𝗅(𝑣)). The corecursor’s head and tail equations reduce judgmentally to the two clauses. Deleting the tail clause leaves 𝗍𝖺𝗂𝗅(𝗓𝗂𝗉𝖶𝗂𝗍𝗁(𝑓,𝑠,𝑡)) uncovered, so the copattern definition is incomplete.
Exercise 85.4.
Use the proof-relevant relation 𝐿(𝑟,𝑡):=𝗓𝗂𝗉𝖶𝗂𝗍𝗁(𝑓,𝑟,𝑡),𝑅(𝑟,𝑡):=𝗓𝗂𝗉𝖶𝗂𝗍𝗁(𝑓,𝑡,𝑟),𝐵(𝑢,𝑣):=∑𝑟:𝖲𝗍𝗋𝖾𝖺𝗆(𝐴)∑𝑡:𝖲𝗍𝗋𝖾𝖺𝗆(𝐴)(𝖨𝖽𝖲𝗍𝗋𝖾𝖺𝗆(𝐴)(𝑢,𝐿(𝑟,𝑡))×𝖨𝖽𝖲𝗍𝗋𝖾𝖺𝗆(𝐴)(𝑣,𝑅(𝑟,𝑡))). Eliminate the two identities carried by a witness (𝑟,𝑡, −, −). The head obligation is exactly 𝑐(𝗁𝖾𝖺𝖽(𝑟))(𝗁𝖾𝖺𝖽(𝑡)). The tails reduce to 𝗓𝗂𝗉𝖶𝗂𝗍𝗁(𝑓,𝗍𝖺𝗂𝗅(𝑟),𝗍𝖺𝗂𝗅(𝑡)),𝗓𝗂𝗉𝖶𝗂𝗍𝗁(𝑓,𝗍𝖺𝗂𝗅(𝑡),𝗍𝖺𝗂𝗅(𝑟)), which belong to 𝐵 with witnesses 𝗍𝖺𝗂𝗅(𝑟),𝗍𝖺𝗂𝗅(𝑡). Thus 𝐵 is a bisimulation, and stream coinduction gives the required observational equality.
Exercise 85.3.
Let 𝑠 be the constant-zero stream. Let 𝑡 be generated from Boolean state with output 0 at 𝖿𝖿, output 1 at 𝗍𝗍, negating transition, and initial state 𝖿𝖿. Then both heads are 0, so 𝐵(𝑠,𝑡) holds, but their depth-one observations are 0 and 1. The proposed relation has no closure witness 𝐵(𝗍𝖺𝗂𝗅(𝑠),𝗍𝖺𝗂𝗅(𝑡)); this is precisely the second premise of definition 85.12.
Exercise 85.5.
Use the proof-relevant relation 𝐵(𝑢,𝑣):=∑𝑟:𝖲𝗍𝗋𝖾𝖺𝗆(𝐴)(𝖨𝖽𝖲𝗍𝗋𝖾𝖺𝗆(𝐴)(𝑢,𝗆𝖺𝗉(𝜆𝑥.𝑥,𝑟))×𝖨𝖽𝖲𝗍𝗋𝖾𝖺𝗆(𝐴)(𝑣,𝑟)). After eliminating the two identities carried by a witness (𝑟, −, −), the heads calculate as 𝗁𝖾𝖺𝖽(𝗆𝖺𝗉(𝜆𝑥.𝑥,𝑟))≡(𝜆𝑥.𝑥)(𝗁𝖾𝖺𝖽(𝑟))≡𝗁𝖾𝖺𝖽(𝑟). The tails are related with witness 𝗍𝖺𝗂𝗅(𝑟) because 𝗍𝖺𝗂𝗅(𝗆𝖺𝗉(𝜆𝑥. 𝑥,𝑟)) ≡𝗆𝖺𝗉(𝜆𝑥. 𝑥,𝗍𝖺𝗂𝗅(𝑟)). Coinduction yields 𝗆𝖺𝗉(𝜆𝑥. 𝑥,𝑠) ≈𝐴𝑠.
Exercise 85.6.
Use state (𝑛,𝑎) :ℕ ×ℕ, output 𝑎, transition (𝑛,𝑎) ↦(𝗌𝗎𝖼(𝑛),𝑎 +𝗌𝗎𝖼(𝑛)), and initial state (0,0). The equivalent copattern clauses are 𝗁𝖾𝖺𝖽(𝑇(𝑛,𝑎))=𝑎,𝗍𝖺𝗂𝗅(𝑇(𝑛,𝑎))=𝑇(𝗌𝗎𝖼(𝑛),𝑎+𝗌𝗎𝖼(𝑛)). Their compilation is exactly that pair-state corecursor. Starting from (0,0), the states have second components 0,1,3,6,10,15, so these are the first six observations. To compare a separately named copattern definition with the compiled corecursor, relate the two results at every state (𝑛,𝑎). Their heads are both 𝑎 and their tails are related at (𝗌𝗎𝖼(𝑛),𝑎 +𝗌𝗎𝖼(𝑛)); coinduction proves observational equality.
Exercise 85.7.
The zero clauses compile with state 𝟏, constant output 0, and the identity transition, so both are accepted instances of definition 85.9. Put 𝑠:=𝗇𝖺𝗍𝗌:=𝗂𝗍𝖾𝗋𝖺𝗍𝖾(𝗌𝗎𝖼,0). Its head equation is judgmental, while its tail relation is observational: 𝗁𝖾𝖺𝖽(𝑠)≡0,𝗍𝖺𝗂𝗅(𝑠)≈ℕ𝗆𝖺𝗉(𝗌𝗎𝖼,𝑠). For the second equation, relate, for every 𝑛, 𝗂𝗍𝖾𝗋𝖺𝗍𝖾(𝗌𝗎𝖼,𝗌𝗎𝖼(𝑛))and𝗆𝖺𝗉(𝗌𝗎𝖼,𝗂𝗍𝖾𝗋𝖺𝗍𝖾(𝗌𝗎𝖼,𝑛)). Their heads both compute to 𝗌𝗎𝖼(𝑛); their tails have the same relation at 𝗌𝗎𝖼(𝑛) by the iterate-tail and map-tail rules. Coinduction proves the displayed observational equality at 𝑛 =0. Written as a recursive clause, its recursive occurrence is nested under 𝗆𝖺𝗉 rather than being the complete result of the matched tail clause, so the selected syntactic guard rejects it.
For the finite observations, first prove by induction on 𝑛 that 𝗇𝗍𝗁(𝑛,𝗆𝖺𝗉(𝑓,𝑟))=𝑓(𝗇𝗍𝗁(𝑛,𝑟)). The zero case is Map-head. The successor case uses Map-tail and the induction hypothesis at 𝗍𝖺𝗂𝗅(𝑟). More directly, induction on 𝑛 with the iterate computation rules gives 𝗇𝗍𝗁(𝟢,𝑠)≡0,𝗇𝗍𝗁(𝗌𝗎𝖼(𝑛),𝑠)≡𝗇𝗍𝗁(𝑛,𝗂𝗍𝖾𝗋𝖺𝗍𝖾(𝗌𝗎𝖼,1))𝑡ℎ𝑒𝑜𝑟𝑒𝑚85.3=𝗌𝗎𝖼𝑛(1)induction on 𝑛=𝗌𝗎𝖼(𝑛). Thus 𝑠 has observations 0,1,2,…. The observational tail equation and these calculations prove productivity of the example without turning stream observational equality into identity or claiming completeness of the guard checker.