Programs

Catlab.Programs.GenerateJuliaPrograms.evaluateMethod

Evaluate a morphism as a function.

If the morphism will be evaluated only once (possibly with vectorized inputs), then direct evaluation will be much faster than compiling (via compile) and evaluating a standard Julia function.

Compare with functor.

Catlab.Programs.ParseJuliaPrograms.@programMacro

Parse a wiring diagram from a Julia program.

For the most part, this is standard Julia code but we take a few liberties with the syntax. Products are represented as tuples. So if x and y are variables of type $X$ and $Y$, then (x,y) has type $X \otimes Y$. Also, both () and nothing are interpreted as the monoidal unit $I$.

Unlike in standard Julia, the call expressions f(x,y) and f((x,y)) are equivalent. Consequently, given morphisms $f: W \to X \otimes Y$ and $g: X \otimes Y \to Z$, the code

x, y = f(w)
g(x,y)

is equivalent to g(f(w)). In standard Julia, at most one of these calls to g would be valid, unless g had multiple signatures.

The diagonals (copying and deleting) 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 merge of x1 and x2 is represented by the vector [x1,x2] and creation by the empty vector []. For example, f([x1,x2]) translates to compose(mmerge(X),f).

This macro is a wrapper around parse_wiring_diagram.

Catlab.Programs.RelationalPrograms.@eval_tensor_networkMacro

Evaluate a tensor network using another macro.

This macro takes two arguments: an undirected wiring diagram and a macro call supporting the tensor contraction notation that is de facto standard among Julia tensor packages. For example, to evaluate a tensor network using the @tullio macro, use:

A = @eval_tensor_network diagram @tullio

The following macros should work:

However,, the macros @cast and @reduce from TensorCast.jl will not work because they do not support implicit summation.

See also: @tensor_network, the "inverse" to this macro.

Catlab.Programs.RelationalPrograms.@relationMacro

Construct an undirected wiring diagram using relation notation.

Unlike the @program macro for directed wiring diagrams, this macro fundamentally alters the usual semantics of the Julia language. Function calls with n arguments are now interpreted as assertions that an n-ary relation holds at a particular point. For example, the operation of composing of binary relations R ⊆ X × Y and S ⊆ Y × Z 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 where clause defines the set of junctions in the diagram and variable sharing defines the wiring of ports to junctions.

Catlab.Programs.RelationalPrograms.@tensor_networkMacro

Construct an undirected wiring diagram using tensor notation.

The tensor syntax is compatible with that used by packages like TensorOperations.jl and TensorCast.jl. For example, the wiring diagram for composite of two matrices (or two binary relations) is constructed by

@tensor_network (i,j,k) C[i,k] := A[i,j] * B[j,k]

The leading context, or list of variables, may be omitted, in which case it is inferred from the variables used in the tensor expression. So, in this example, an equivalent macro call is

@tensor_network C[i,k] := A[i,j] * B[j,k]

See also: @eval_tensor_network, the "inverse" to this macro.