Roll Bounds for the Free Monad of a Polynomial Functor #
We define PFunctor.FreeM.IsRollBound oa budget canRoll cost, a generalized
predicate that bounds the number of roll constructors a term oa : FreeM P α
unfolds, parameterized by:
B— the budget typebudget : B— the initial budgetcanRoll : P.A → B → Prop— whether arollat positionais allowed under budgetbcost : P.A → B → B— how the budget is updated after arollata
The definition is structural via FreeM.construct: pure satisfies any bound,
and roll a r satisfies the bound when canRoll a b holds and each
continuation r y satisfies the bound at cost a b.
OracleComp.IsQueryBound (in VCVio/OracleComp/QueryTracking/QueryBound.lean)
is the specialization of this predicate to FreeM (spec.toPFunctor) and is
equal to IsRollBound definitionally; the bridge lemma in QueryBound.lean
witnesses the equivalence by Iff.rfl.
Generalized roll bound on FreeM P parameterized by a budget type B,
a validity check canRoll, and a cost function cost. pure satisfies any
bound; roll a r satisfies the bound when canRoll a b holds and every
continuation satisfies the bound at cost a b.
Instances For
If f <$> oa = ob for any f, the roll-bound predicate transfers between
them. The standard shape arises when oa and ob are two views of the same
underlying computation that agree up to a projection.
Project an IsRollBound along a budget projection proj : B → B'.
If the source bound at budget b validates rolls at every step, the projected
bound at proj b is also validated, provided:
h_can— whenever a step is allowed in the source (canRoll a b'), it is allowed in the projection (canRoll' a (proj b'));h_cost— the projection commutes with the cost step on the allowed branch (proj (cost a b') = cost' a (proj b')).
Generic bind composition for IsRollBound parameterised by an arbitrary
budget type B and a binary combine operation on it.
The two side conditions are universally quantified so they survive recursion
under generalizing b₁:
h_can— extending any validated budget on either side viacombinekeeps the roll valid;h_cost—costdistributes left and right overcombineon validated budgets.
Forward-direction seq analogue of isRollBound_bind. Reduces to the
bind case via seq_eq_bind_map plus isRollBound_map_iff.