| Safe Haskell | None |
|---|---|
| Language | GHC2024 |
Circuit.Agent.Delivery
Description
Semiring delivery matrices for addressed posts.
deliversTo in Agent is the boolean predicate that gates delivery.
This module lifts the same logic to an arbitrary NumHask semiring,
producing delivery and topology matrices that can be interpreted under
different semirings:
- Boolean: exactly today's discrete delivery (the regression fence, G2).
- Real / probability: weighted delivery for gradient-based routing.
- Path-counting: number of delivery paths (useful for G3).
A post delivers to a recipient when the recipient appears in the post's to
list. The from field is treated as the sender when building agent-to-agent
topology matrices.
Synopsis
- deliversToSemiring :: (Additive r, Multiplicative r) => [Text] -> Text -> r
- type DelRel a = Set ((), a)
- copyRel :: Set a -> Set (a, (a, a))
- discardRel :: Set a -> Set (a, ())
- broadcastRel :: Set a -> DelRel a
- emptyRel :: DelRel a
- namedRel :: a -> DelRel a
- deliveryRel :: Set Text -> [Text] -> DelRel Text
- deliversRel :: DelRel Text -> Set Text -> Bool
- deliveryMatrix :: (Additive r, Multiplicative r) => [Text] -> [[Text]] -> Matrix r
- topologyMatrix :: (Additive r, Multiplicative r) => [Text] -> [(Text, [Text])] -> Matrix r
- isNilpotent :: (Additive r, Multiplicative r, Eq r) => Matrix r -> Bool
- matrixPowers :: (Additive r, Multiplicative r) => Int -> Matrix r -> [Matrix r]
Semiring predicate
Arguments
| :: (Additive r, Multiplicative r) | |
| => [Text] | Recipients on the post. |
| -> Text | Recipient name. |
| -> r |
Finite-relation delivery model
type DelRel a = Set ((), a) Source #
A relation from a single post (the unit type) to a finite set of agents.
This is the set-based reading of FinRel: objects are finite sets, morphisms
are relations, and the cartesian comonoid on the agent set gives canonical
copy/discard generators. The "all" broadcast sentinel is the dagger
(relational converse) of discardRel; the empty / [""] case is the zero
morphism emptyRel.
copyRel :: Set a -> Set (a, (a, a)) Source #
Canonical copy comonoid on a finite agent set.
Relates each agent a to the pair (a, a).
discardRel :: Set a -> Set (a, ()) Source #
Canonical discard counit on a finite agent set.
Relates every agent to the terminal value ().
broadcastRel :: Set a -> DelRel a Source #
Broadcast relation: the dagger of discardRel.
Maps the single post () to every agent in the roster. This is exactly
the semantics of to = ["all"].
Empty (zero) delivery relation.
This is the semantics of to = [] and to = [""]: the post reaches no
agent.
Arguments
| :: Set Text | Roster of agents (the codomain of the relation). |
| -> [Text] | Recipients on the post. |
| -> DelRel Text |
Delivery relation encoded by a post's to list.
"all"selects the broadcast relation (broadcastRel).[]and[""]select the zero relation (emptyRel).- Named recipients select the corresponding singleton injections.
deliversRel :: DelRel Text -> Set Text -> Bool Source #
Evaluate a delivery relation against a subscriber set.
Returns True when the relation's image intersects the subscribers.
Matrices
Arguments
| :: (Additive r, Multiplicative r) | |
| => [Text] | Agents (column labels). |
| -> [[Text]] | Recipient lists for each post (row labels are implicit). |
| -> Matrix r |
Delivery matrix for a fixed list of posts and a roster of agents.
Rows are posts (in the order given), columns are agents (in the order
given), and entry (p, a) is the delivery weight of post p to agent a.
Arguments
| :: (Additive r, Multiplicative r) | |
| => [Text] | Agents (row and column labels, in the same order). |
| -> [(Text, [Text])] | Posts as |
| -> Matrix r |
Agent-to-agent delivery topology matrix.
Rows and columns are agents. Entry (i, j) is the combined weight with
which agent i's authored posts are delivered to agent j. The
aggregation uses the semiring addition (+), so multiple posts from the
same sender to the same recipient accumulate.
Posts are given as (author, recipients) pairs.
Nilpotency / acyclicity check
isNilpotent :: (Additive r, Multiplicative r, Eq r) => Matrix r -> Bool Source #
A square matrix is nilpotent when some power is the zero matrix.
For a delivery topology, nilpotency means the communication graph is a DAG: no directed cycle can return a non-zero weight, so every sufficiently long path multiplies out to zero.
matrixPowers :: (Additive r, Multiplicative r) => Int -> Matrix r -> [Matrix r] Source #
Powers of a square matrix, starting from the first power.