Catlab.Programs.ParseJuliaPrograms.@program
Parse a wiring diagram from a Julia program.
For the most part, this is standard Julia code but a few liberties are taken with the syntax. Products are represented as tuples. So if
xandyare variables of type and , then(x,y)has type . Also, both()andnothingare interpreted as the monoidal unit II.Unlike standard Julia, the function call expressions
f(x,y)andf((x,y))are equivalent.- Consequently, given morphisms and ,
- the code
x, y = f(w) g(x,y) - is equivalent to
g(f(w)). In standard Julia, at most one of these calls togwould be valid, unlessghad multiple signatures.
- the code
- Consequently, given morphisms and ,
The diagonals (copying and deleting) of a cartesian category are implicit in the Julia syntax:
- copying is variable reuse and deleting is variable non-use.
For the codiagonals (merging and creating), a special syntax is provided, reinterpreting Julia’s vector literals.
- The merging of
x1andx2is represented by the vector[x1,x2]and creation by the empty vector[]. - For example,
f([x1,x2])translates tocompose(mmerge(X),f).
- The merging of
This macro is a wrapper around
parse_wiring_diagram.
Catlab.Programs.RelationalPrograms.@relation
- Construct an undirected wiring diagram using relation notation.
- Unlike the
@programmacro for directed wiring diagrams, this macro departs significantly from the usual semantics of the Julia programming language.- Function calls with arguments are now interpreted as assertions that an -ary relation holds at a particular point. For example, the composite of binary relations and can be represented as an undirected wiring diagram by the macro call
@relation (x,z) where (x::X, y::Y, z::Z) begin R(x,y) S(y,z) end - In general, the context in the
whereclause defines the set of junctions in the diagram and variable sharing defines the wiring of ports to junctions. If thewhereclause is omitted, the set of junctions is inferred from the variables used in the macro call.
- Function calls with arguments are now interpreted as assertions that an -ary relation holds at a particular point. For example, the composite of binary relations and can be represented as an undirected wiring diagram by the macro call
reference: https://algebraicjulia.github.io/Catlab.jl/dev/apis/programs/