Skip to content

feat(PFunctor): add resumptions and relate W-types, M-types and free monads - #1088

Open
dtumad wants to merge 5 commits into
leanprover:mainfrom
dtumad:dtumad/pfunctor-resumption
Open

dtumad wants to merge 5 commits into
leanprover:mainfrom
dtumad:dtumad/pfunctor-resumption

Conversation

@dtumad

@dtumad dtumad commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

Completes the polynomial tree types with coinductive resumptions and relates the four representations. PFunctor.W and PFunctor.M are the initial algebra and final coalgebra of P; PFunctor.FreeM P α and the new PFunctor.Resumption P α are those of X ↦ α ⊕ P X, the W- and M-types of C α + P (FreeM.equivW). The canonical maps W.toM and FreeM.toResumption are injective with image the well-founded trees, the latter a monad morphism, and they commute with the embeddings of trees that never return (W.toFreeM, M.toResumption), which are equivalences when nothing can be returned.

Resumptions have a corecursor, a bisimulation principle and a lawful monad structure whose API mirrors PFunctor.FreeM. Over y they are Capretta's delay monad; they give semantics to loops whose termination is not structural, such as rejection sampling or machine execution. Adapted from PolyFun.

AI agents were used to adapt VCVio definitions/proofs to Cslib definitions and conventions.

dtumad and others added 5 commits October 5, 2026 18:32
Add the canonical map `PFunctor.W.toM` and identify `P.W` with the
well-founded trees of `P.M`, together with Lambek's lemma `M.destEquiv` and
an induction principle for `PFunctor.W` through `W.mk`. Identify
`P.FreeM α` with the W-type of `C α + P`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Add `PFunctor.Resumption P α`, the M-type of `C α + P`: possibly
non-terminating programs that return an `α` or perform an operation of `P`.
It has a corecursor, a bisimulation principle and a lawful monad structure,
and `FreeM.toResumption` is an injective monad morphism whose image is exactly
the well-founded resumptions.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Use `liftBind` as the implementation-detail constructor with simp-normal
form `(lift a).bind k`, as for `PFunctor.FreeM`, and name the cases and
lemmas accordingly (`lift_bind`, `liftBind_bind`, `dest_lift_bind`,
`map_bind`, `bind_pure_comp`).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Add `M.toResumption`, `Resumption.toMOfIsEmpty` and `equivMOfIsEmpty`,
mirroring the W-type embedding of free programs, and show that embedding
W-trees commutes with these maps. Describe the four tree types and the maps
between them in the module documentation.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant