definition theorem example

An algebra for an Operad is an operad functor : it assigns to each type a set of fillers for boxes of type , and to each operation (wiring diagram) a function that assembles fillers into one — e.g. “takes circuits with interfaces and returns a circuit with boundary “. Just as set-valued functors are database instances, set-valued operad functors are the applications obeying a compositional grammar.

Sources: 7 Sketches §6.5.3 (Definition 6.99, Example 6.100, Proposition 6.101), Remark 5.74 (algebraic theories), §6.6; Catlab oapply; CTfS Definition 5.4.1.8, Application 5.4.2.2, Example 5.4.2.6, Application 5.4.2.7

Example 6.100 (circuits). sends to the set of circuits with marked terminals; a wiring diagram gives , which applied to a battery, a switch and a lamp-with-resistor yields the closed light-switch circuit of §6.1. This is the decorated-cospan story in operadic form.

Subsets as an algebra (CTfS Example 5.4.2.6, Application 5.4.2.7). On the operad of relations, is an algebra: given a relation and subsets , take the image in of the tuples of whose inputs lie in the . Read as survival: the super-entity survives exactly the phenomena that translate into phenomena every sub-entity survives. Materials and their strengths are two algebras on one operad, and a morphism of algebras relates them (Operad).

Proposition 6.101. -algebras are equivalent to hypergraph props — so is “the theory of hypergraph categories” (cf. Theorem 6.58). Advantages of the operadic view: every hypergraph prop arises (decorated cospans give only some), and one may vary the operad ( → cobordisms → wiring diagrams without passing wires) to get different compositionality rules. Compare: monoid objects are algebras of the prop “theory of monoids” (Remark 5.74); Catlab’s oapply(diagram, fillers) evaluates an operad algebra — for finite relations, Petri nets, dynamical systems, or circuits — on an Undirected Wiring Diagram.

Docs: FinSets · Free diagrams · Relational programs / UWDs

using Catlab, Catlab.WiringDiagrams, Catlab.Programs
# the operad algebra of relations on UWDs: a filler is a relation R ⊆ A × B, stored as a span
# A ← R → B of finite sets, and oapply glues fillers along the diagram (a limit = a join of tables)
uwd = @relation (x, z) begin
  R(x, y); S(y, z)
end
relspan(pairs, A, B) = Span(FinFunction(first.(pairs), A), FinFunction(last.(pairs), B))
R = relspan([(1, 1), (1, 2), (2, 2)], 2, 2)        # ≤ on {1, 2}
S = relspan([(1, 2), (2, 1)], 2, 2)                # swap
RS = oapply(uwd, [R, S])                           # the composite relation R ; S, as a span
πx, πz = legs(RS)
sort([(πx(i), πz(i)) for i in apex(RS)])           # [(1, 1), (1, 2), (2, 1)]
# oapply works the same way for open Petri nets (AlgebraicPetri) and other hypergraph categories
-- an algebra assigns filler sets to types and an assembly function to each wiring diagram (schematic)
class Operad op => Algebra op a where
  assemble :: op -> [a] -> a       -- F(f)(fillers)