Skip to content

feat(PFunctor): measure semantics for free monads and resumptions - #1089

Open
dtumad wants to merge 6 commits into
leanprover:mainfrom
dtumad:dtumad/pfunctor-measure
Open

dtumad wants to merge 6 commits into
leanprover:mainfrom
dtumad:dtumad/pfunctor-measure

Conversation

@dtumad

@dtumad dtumad commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Adds PFunctor.FreeM.toMeasure μ, the output measure of a program whose operations are answered according to μ, defined as the fold into Mathlib's Giry bind, and PFunctor.Resumption.toMeasure μ, the supremum of the measures of its finite approximations, so that runs that never return contribute no mass. With discrete response spaces both send bind to the Giry bind, they agree along FreeM.toResumption, and resumptions that never return have zero output measure. Also adds the facts about increasing sequences of measures this needs (Measure.iSup_apply_of_monotone, Measure.bind_iSup_of_monotone, Measure.iSup_bind_of_monotone). Adapted from VCVio.

Depends on:

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

dtumad and others added 6 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>
Add `PFunctor.FreeM.toMeasure μ`, the output measure of a program whose
operations answer according to `μ`, as the fold into the Giry bind, and
`PFunctor.Resumption.toMeasure μ`, the supremum of its finite
approximations, so divergence is lost mass. The two agree along
`FreeM.toResumption`, and resumptions that never return have zero output.

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