Codata.conat

-- Conaturals, split out of Codata/stream.nova: the Ξ½-scheme at its
-- simplest sum polynomial (NovaFoundation.txt, "Coinductive
-- types"). conat = Ξ½ (K πŸ™ ⊎ 𝕏): zero observes as inj₁, a successor
-- as injβ‚‚ of its predecessor; ∞ is its own predecessor. Ξ²-shaped
-- lemmas close by computation; infSucc is the classic coinductive
-- theorem, by el-nu-coind.
-- Conaturals: Ξ½ (K πŸ™ ⊎ 𝕏) β€” zero observes as inj₁, a successor as
-- injβ‚‚ of its predecessor; ∞ is its own predecessor

conat : π•Œ
conat = Ξ½ (K πŸ™ ⊎ 𝕏)

czero : conat using (Codata.conat.unfold)
czero = corec (s : πŸ™. inj₁ s) ()

cinf : conat using (Codata.conat.unfold)
cinf = corec (s : πŸ™. injβ‚‚ s) ()

-- observation shapes, by computation (el-nu-beta + el-sum-beta)
outZero : out czero ≑ inj₁ () ∈ πŸ™ ⊎ conat
  using (Codata.conat.eq, czero.eq, hyp.rw, Codata.conat.unfold)
outZero = ⋆

outInf : out cinf ≑ injβ‚‚ cinf ∈ πŸ™ ⊎ conat
  using (cinf.eq, Codata.conat.eq, hyp.rw, Codata.conat.unfold)
outInf = ⋆

-- csucc: emit injβ‚‚ of the stored conat, continuing by observation
csucc : conat β†’ conat using (Codata.conat.unfold)
csucc = Ξ»n. corec (p : πŸ™ ⊎ conat. injβ‚‚ (⊎-elim (u. inj₁ u) (m. out m) p)) (out n)

-- a successor always observes as injβ‚‚ β€” one Ξ² step, the payload
-- irrelevant to the shape (⊎-elim at an equality motive would refute
-- inj₁; here the equation is between the injections themselves)
outSuccInf : out (csucc cinf) ≑ injβ‚‚ (csucc cinf) ∈ πŸ™ ⊎ conat
  using (cinf.eq, Codata.conat.eq, csucc.eq, hyp.rw, Codata.conat.unfold)
outSuccInf = ⋆

-- conat's classic coinductive theorem: ∞ is its own successor. The
-- closure exercises the relator's SUM clause: the ⊎-elim at motive Ω
-- is stuck at the generic observations, un-stuck by the invariant's
-- variable-definition equations, and collapses definitionally on the
-- injβ‚‚/injβ‚‚ diagonal.
infSucc : cinf ≑ csucc cinf using (cinf.eq, csucc.eq, hyp.rw, Codata.conat.unfold)
infSucc =
  coind
    x y. βˆ₯(x ≑ cinf ∈ conat) Γ— (y ≑ csucc cinf ∈ conat)βˆ₯
    ⋆ (⋆, ⋆)
    x y h. squash-elim h (w. ⋆ (⋆, ⋆))