definition example program

A signal flow graph (Shannon, 1940s) is a Wiring Diagram whose dangling left wires are inputs, right wires outputs, built from icons over a Rig of signals:

generatoriconmeaningmatrixarity
amplify by box multiply the signal by
copyblack dot, 1 in 2 outtwo copies of the input
discardblack dot, 1 in 0 outoutput nothing ()
addwhite dot, 2 in 1 outsum of the inputs
zerowhite dot, 0 in 1 outoutput ()

Formally (Definition 5.45), with and counting dangling wires, a simplified signal flow graph is a morphism of the Free Prop ; boxes are drawn as icons rather than labelled boxes.

Sources: 7 Sketches §5.1 (Eq. 5.1), §5.3.2–5.3.5 (Definition 5.45, Examples 5.44, 5.46, Exercises 5.43, 5.55), §5.4 (Graphical Linear Algebra, feedback, control theory), §5.5; [Sob] Graphical Linear Algebra blog, [BE15], [Zan15].

Example (Eq. 5.1). With inputs (top) and (bottom) and icons “copy ”, “amplify by 7”, “add”, “amplify by 5”, “amplify by 2”, “copy”, “amplify by 3”, “add”: the outputs are and . Outputs can be computed by tracing signals forward, or by summing over paths: the contribution of input to output is the sum over all paths from to of the product of amplifications along the path (no backwards traversal); there is one path top-to-top with amplification , and none bottom-to-top.

Example 5.44. Linear differential equations , become, via the Laplace transform with = “differentiate”, a signal flow graph over with amplifications .

Semantics

Every signal flow graph denotes a matrix: the prop functor (Functorial Semantics, Theorem 5.53) sends the generators to the matrices above, and is the matrix whose entry is the total amplification from input to output (Proposition 5.54, by induction on prop expressions: composition is matrix multiplication by distributivity, monoidal product reindexes). Two graphs have the same behaviour iff they denote the same matrix; e.g. copy-then-copy-left and copy-then-copy-right both give (Eq. 5.47, 7S Exercise 5.55). Theorem 5.60 gives the complete set of graphical rewrite rules (Graphical Linear Algebra); every matrix is represented by a four-layer normal form (copy/discard, scalars, permutation, add/zero).

Feedback and the behavioural approach (§5.4.3)

Reversing the icons ( for ) and interpreting graphs by their behaviour — a relation, with the transposed relation — gives (non-simplified) signal flow graphs with semantics in the prop (Category of Relations). Reversed add is , reversed copy is (7S Exercise 5.77); has behaviour — solution sets of linear equations (7S Exercise 5.82); kernels and images arise from zero-reverse and discard-reverse (7S Exercise 5.84). Cups and caps (copy-then-discard reversed) make compact closed with every self-dual (Theorem 5.87), allowing feedback loops: a cruise-control system over with asks how to choose so that the behaviour approximates (Willems’ behavioural approach [Wil07]).

Docs: Theories (Catlab)

Builds on: Rig (Nat) — run that note’s Julia code first.

# evaluate a simplified signal flow graph as a matrix via the semantics functor S (Theorem 5.53)
copyM(R)    = reshape([R.one, R.one], 1, 2)          # 1 → 2
discardM(R) = zeros(typeof(R.one), 1, 0)             # 1 → 0
addM(R)     = reshape([R.one, R.one], 2, 1)          # 2 → 1
zeroM(R)    = zeros(typeof(R.one), 0, 1)             # 0 → 1
scalarM(R, a) = reshape([a], 1, 1)
idM(R, n) = [i == j ? R.one : R.zero for i in 1:n, j in 1:n]
dsum(R, A, B) = [A fill(R.zero, size(A,1), size(B,2)); fill(R.zero, size(B,1), size(A,2)) B]   # f + g
# Eq. (5.1) over ℕ, as four action columns: (copy + 7) ; (id + add) ; (5 + 2) ; ... → S = [15 3; 0 21]
col1 = dsum(Nat, copyM(Nat), scalarM(Nat, 7))                 # 2 → 3
col2 = dsum(Nat, idM(Nat, 1), addM(Nat))                      # 3 → 2
col3 = dsum(Nat, scalarM(Nat, 5), scalarM(Nat, 2))            # 2 → 2
col4 = dsum(Nat, copyM(Nat), idM(Nat, 1))                     # 2 → 3
col5 = dsum(Nat, scalarM(Nat, 3), addM(Nat))                  # 3 → 2
S = foldl((A, B) -> matmul(Nat, A, B), [col1, col2, col3, col4, col5])   # [15 3; 0 21]
 
# Catlab: signal flow graphs live in Catlab.Programs / Catlab.Graphics (e.g. `@program`, `to_graphviz`)
-- semantics of the generators as matrices over a semiring R
def copyM (R : Type) [Semiring R] : Matrix (Fin 1) (Fin 2) R := fun _ _ => 1
def addM  (R : Type) [Semiring R] : Matrix (Fin 2) (Fin 1) R := fun _ _ => 1
def scalarM {R : Type} [Semiring R] (a : R) : Matrix (Fin 1) (Fin 1) R := fun _ _ => a
-- S(g) for a composite is the product of the layer matrices (Matrix.mul), monoidal product is `Matrix.fromBlocks`
-- a signal flow graph as a prop expression over the icon signature, evaluated to a matrix
data Icon r = Copy | Discard | Add | Zero | Scalar r
type M r = [[r]]
iconMatrix :: Rig r => Icon r -> M r
iconMatrix Copy       = [[one, one]]
iconMatrix Discard    = [[]]
iconMatrix Add        = [[one], [one]]
iconMatrix Zero       = []
iconMatrix (Scalar a) = [[a]]
-- eval :: Rig r => Expr (Icon r) -> M r   uses matrix multiplication for Seq and block sums for Par