Skip to content

Arrow Instances

These instances implement arrow operations (type class hierarchy) for ordinary functions (Function), finite weighted relations (VRel), and stochastic transitions (Stochastic) (Hughes, 2000). Composing functions passes one result to the next function. Composing stochastic transitions averages the next output distribution over the intermediate values, so each transition must be a normalized kernel.

instances

Standard arrow instances for the typeclass tower.

Implements the arrow interfaces of quivers.arrows.typeclasses against the V-enriched category of finite sets. Each instance carries no per-instance state — every operation is a stateless construction on the underlying Morphism algebra. The instances register themselves against the relevant ABCs (Arrow, ArrowChoice, ArrowApply, ArrowLoop) so isinstance works transparently for the chart-parser's arrow-side dispatch.

Realisations:

  • VRel: the canonical V-enriched-relation arrow. compose is the V-Rel >> operator; arr is the identity embedding; first is the parallel-product factory; left_arr is the coproduct functorial action; loop_arr is finite diagonal contraction over the feedback component.
  • Function: restricts to deterministic V-relations (functions with point-mass tensors). Pure-functional operations.
  • Stochastic: stochastic-matrix arrows. Neither total finite functions nor normalized stochastic kernels have general diagonal-contraction feedback, so Function and Stochastic do not implement ArrowLoop.

VRel didactic-model

VRel(*, name: str = 'VRel')

Bases: Model

The V-enriched-relation arrow on finite sets.

Hom-sets are V-Rel morphisms; composition is the standard >>; arr is the identity embedding (every V-Rel morphism is an arrow); first is the parallel pair; left_arr is the coproduct functorial action; loop_arr is finite diagonal contraction.

Function didactic-model

Function(*, name: str = 'Function')

Bases: Model

Deterministic V-relation arrow (point-mass tensors only).

Restricts VRel to morphisms whose tensors are 0/1-valued (function graphs). Composition, first, and left_arr preserve determinism on this carrier. Arbitrary feedback can have several fixed points or none, so this instance does not implement ArrowLoop.

app

app(A: SetObject, B: SetObject) -> Morphism

ArrowApply.app for Function — the standard evaluation.

Source code in src/quivers/arrows/instances.py
def app(self, A: SetObject, B: SetObject) -> Morphism:
    """ArrowApply.app for Function — the standard evaluation."""
    return _evaluation_morphism(A, B)

Stochastic didactic-model

Stochastic(*, name: str = 'Stochastic')

Bases: Model

Stochastic-matrix arrows.

Each arrow is a Morphism whose tensor rows are probability distributions. Operations preserve row-stochasticity: composition is matrix multiplication; first and left_arr are the tensor-product and coproduct lifts. Diagonal contraction need not preserve row sums, so this instance does not implement ArrowLoop.

Cited sources

John Hughes. Generalising Monads to Arrows. Science of Computer Programming, 37(1–3):67–111, 2000. URL: https://www.sciencedirect.com/science/article/pii/S0167642399000234, doi:10.1016/S0167-6423(99)00023-4.