Traces of polynomial-functor events #
For a polynomial functor P, the universal "log of P-events" is the free
monoid on indices Idx P = Σ a : P.A, P.B a. This file packages that monoid
together with the abstract Control.Trace machinery from
ToMathlib/Control/Trace.lean.
Main definitions #
PFunctor.TraceList P— the carrierFreeMonoid (Idx P), definitionallyList (Σ a, P.B a).PFunctor.Trace P X— the type ofX-indexedP-event traces, i.e.X → TraceList P, with monoid structure inherited pointwise.PFunctor.Trace.mapPartial,mapChart,restrictLeft,restrictRight— the standard push / filter operations along chart morphisms and direct-sum projections.PFunctor.Trace.toMonoid— the universal property: every valuationIdx P → ωextends uniquely to a monoid homTraceList P →* ω, and so to a trace mapTrace P X → Control.Trace ω X.
Boundary-emitter intuition #
Reading Trace P X as "for each input x : X, the finite, ordered list of
P-events that get emitted on the boundary": this is precisely the boundary
shape of a stateless effectful Mealy machine in the List-Writer Kleisli
category. Stateful executors (e.g. running over an OracleComp) are handled
separately in VCVio/OracleComp/QueryTracking/.
The canonical user inside this repository is BoundaryAction.emit in
VCVio/Interaction/UC/OpenProcess.lean, where Trace Δ.Out X records the
list of output-port packets a node emits when the local state transitions
to x : X. Operations such as mapBoundary, wireLeft, wireRight, and
the tensor embeddings of open processes are implemented directly by
PFunctor.Trace.mapChart and PFunctor.Trace.mapPartial against
appropriate boundary morphisms.
References #
- Bonchi, Di Lavore, Romàn — Effectful Mealy machines and Kleisli categories.
- Hancock, Setzer — Interactive programs and weakly final coalgebras in dependent type theory.
- Spivak, Niu — Polynomial Functors: A Mathematical Theory of Interaction, arXiv:2202.00534.
The free monoid on P-events. Definitionally FreeMonoid (Idx P), which
in turn is reducibly List (Idx P). This is the universal carrier for
"finite ordered logs of P-events".
Instances For
An X-indexed trace of P-events: for each input x : X, a finite ordered
list of P-events. Specialisation of Control.Trace at
ω = TraceList P, inheriting a pointwise monoid structure.
Instances For
Relabel-and-filter a trace along a partial map of indices. This is the single primitive for moving traces between polynomial functors: total chart pushforward and summand restriction are both specialisations of it.
Instances For
Push a P-trace forward along a chart P → Q.
Instances For
Pre-compose a P-trace with f : Y → X (input variance).
Instances For
The universal map into any monoid-valued trace via the free-monoid universal
property. Every valuation φ : Idx P → ω extends uniquely to a monoid
homomorphism FreeMonoid (Idx P) →* ω; toMonoid φ post-composes a P-trace
with that hom.
Instances For
Pointwise behaviour #
Functoriality of mapPartial and mapChart #
Trivial-trace lemmas #
The unit trace 1 : Trace P X = fun _ => [] is annihilated by all relabel /
filter operations. These are needed downstream to reason about
boundary actions whose default emission is the empty trace.
Naturality of toMonoid #
Pushing a P-trace along a chart φ : P → Q and then evaluating against a
Q-valuation ψ is the same as evaluating against the precomposed
P-valuation ψ ∘ Chart.mapIdx φ. This is exactly the free-monoid
naturality square.
Restriction along direct-sum projections #
The summand restriction operations need P and Q to share the B universe
so that P + Q typechecks.
Restrict a trace on P + Q to its P-summand.
Instances For
Restrict a trace on P + Q to its Q-summand.