Handlers certified by count matrices #
A one-shape Diller–Nahm morphism is a lens bang (y^ι') ⇆ y^ι out of the exponential of a
polynomial with one position. Its backward map sends each i : ι to a finite multiset over ι',
and at finite ι' it is determined by its count matrix ι → ι' → ℕ (Lens.ofCountMat,
Lens.countMat_ofCountMat, Lens.ofCountMat_countMat). Read with ι the resources of an
interface P and ι' the resources of an interface Q, the entry at (i, j) is the number of
units of j that one unit of i demands: the demands d of Handler.Certified.ofDemand, at
natural-number values.
A handler P → FreeM Q certified by such a morphism (Handler.CountCertified) is a certified
handler whose exchange is the demand map of the cast count matrix (CountCertified.toCertified),
which is the vector–matrix product (CountCertified.toCertified_exchange_apply). The lens points
from the resources of Q to those of P: the assignment is contravariant. The identity handler
is certified by the counit (CountCertified.id), and handlers compose with the co-Kleisli
composite of their lenses in the opposite order (CountCertified.comp). The assignment
toCertified preserves identities and composition (CountCertified.toCertified_id,
CountCertified.toCertified_comp): the composition of exchanges of Handler.Certified.comp at
demand maps is the product of count matrices of Lens.countMat_bangComp
(Lens.demand_bangComp). A program with use vector u runs through a composite with use vector
u times the product of the two count matrices (CountCertified.isChargeBound_liftM_comp).
The correspondence covers demand maps with natural-number entries, which are the count matrices
of one-shape morphisms (CountCertified.ofNatDemand). A demand map with entries outside the image
of ℕ, such as an expected demand in ℝ≥0 or an unbounded demand ⊤ in ℕ∞, is not a count
matrix, and a certified handler whose exchange is not a demand map has no count matrix at all.
One-shape Diller–Nahm morphisms and their count matrices #
The one-shape Diller–Nahm morphism with count matrix d: the direction i demands each
direction j with multiplicity d i j.
Equations
- One or more equations did not get rendered due to their size.
Instances For
The count matrix of ofCountMat d is d.
A one-shape Diller–Nahm morphism is the morphism of its count matrix.
The demand matrix of a one-shape Diller–Nahm morphism: its count matrix, cast to ω.
Equations
- PFunctor.Lens.demand ω g i j = ↑(g.countMat PUnit.unit i j)
Instances For
Demand matrices are nonnegative.
The demand map of a demand matrix is the vector–matrix product.
The demand matrix of the counit is the identity matrix.
Composition agrees. The demand matrix of a co-Kleisli composite is the product of the demand matrices.
The demand matrix of a co-Kleisli composite is the composite demand of
Handler.isChargeBound_liftM_demand_comp: the demand map of f applied to each row of g.
Handlers certified by count matrices #
A handler implementing P by programs over Q, certified by a one-shape Diller–Nahm morphism
from the resources ι' of Q to the resources ι of P: each call at a is implemented with
use vector at most ∑ i, c a i • lens.demand ω i.
The implementation of each call.
The demand of one unit of each resource of
Pin resources ofQ.- certificate (a : P.A) : (self.handler a).IsChargeBound e (∑ i : ι, c a i • Lens.demand ω self.lens i)
Each call is implemented within its demand.
Instances For
The certified handler with the demand map of the count matrix as its exchange.
Equations
Instances For
The exchange of a handler certified by a count matrix is the vector–matrix product.
Use bounds through a handler certified by a count matrix. A program with use vector u
runs with use vector u times the demand matrix.
A handler certified by a demand map with natural-number entries, certified by the one-shape Diller–Nahm morphism of that matrix.
Equations
- PFunctor.Handler.CountCertified.ofNatDemand h d hh = { handler := h, lens := PFunctor.Lens.ofCountMat d, certificate := ⋯ }
Instances For
The count matrix of ofNatDemand h d hh is d.
The identity handler, certified by the counit.
Equations
- PFunctor.Handler.CountCertified.id P c = { handler := PFunctor.Handler.id P, lens := PFunctor.Lens.bangCounit (PFunctor.purePower ι), certificate := ⋯ }
Instances For
The identity handler's certificate is the identity certificate.
Handlers certified by count matrices compose, with the co-Kleisli composite of their lenses in the opposite order.
Equations
Instances For
Composition agrees. The certified handler of a composite is the composite of the certified handlers: composing exchanges of demand maps is the product of count matrices.
Use bounds through two handlers. A program with use vector u runs through the composite
with use vector u times the product of the two demand matrices.