Programs

Catlab.Programs.JuliaProgramsModule

Morphisms as Julia programs.

This module allows morphisms in a symmetric monoidal category to be converted to and from programs in a subset of the Julia language.

Catlab.Programs.JuliaPrograms.@parse_wiring_diagramMacro

Parse a wiring diagram from Julia code.

For the most part, this is standard Julia 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.

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).

Catlab.Programs.AlgebraicNetsModule

Computer algebra via monoidal categories.

In a conventional computer algebra system, algebraic expressions are represented as trees whose leaves are variables or constants and whose internal nodes are arithmetic operations or elementary or special functions. The idea here is to represent expressions as morphisms in a monoidal category.

Catlab.Programs.AlgebraicNets.compile_expr_vectorMethod

Compile an algebraic network into a Julia function expression.

The function signature is:

  • first argument = input vector
  • second argument = constant (coefficients) vector

Unlike compile_expr, this method assumes the network has a single output.

Catlab.Programs.AlgebraicNets.evaluateMethod

Evaluate an algebraic network without first compiling it.

If the network will only be evaluated once (possibly with vectorized inputs), then direct evaluation will be much faster than compiling with Julia's JIT.

Catlab.Programs.JuliaPrograms.compileMethod

Compile an algebraic network into a Julia function.

This method of "functorial compilation" generates simple imperative code with no optimizations. Still, the code should be fast provided the original expression is properly factored, with no duplicate computations.

Catlab.Programs.JuliaPrograms.compile_exprMethod

Compile an algebraic network into a Julia function expression.

The function signature is:

  • arguments = inputs (domain) of network
  • keyword arguments = symbolic constants (coefficients) of network, if any
Catlab.Programs.ExpressionTreesModule

Expression trees (formulas) for computer algebra.

This module is not an implementation of a conventional, general-purpose CAS. There are already many outstanding computer algebra systems. Its goals are to

  • represent formulas as expression tree, when that is convenient
  • display formulas in conventional mathematical notation with free variables
  • allow interoperation with existing computer algebra systems
Catlab.Programs.ExpressionTrees.FormulaType

An expression tree for computer algebra.

We call the expression trees "formulas" to avoid confusion with Julia expressions (Base.Expr) or GAT expressions (Catlab.Syntax.GATExpr). Usually the operations (head symbols) are interpreted as Julia functions, e.g., :/ is right multiplication by the matrix pseudoinverse while :./ is the elementwise division.

source
Base.Meta.show_sexprMethod

Show the formula as an S-expression.

Cf. the standard library function Meta.show_sexpr.

Catlab.Syntax.show_latexMethod

Show the expression in infix notation using LaTeX math.

Does not include $ or \[begin|end]{equation} delimiters.

Catlab.WiringDiagrams.WiringLayers.to_wiring_diagramMethod

Convert a formula, or formulas, to a wiring diagram.

The wiring diagram has an input for each symbol in vars and an output for each given formula. All terminal symbols not appearing in vars are treated as symbolic constants.

The algorithm creates wiring diagrams in normal form for a cartesian category, meaning that subformulas are maximally shared (cf. normalize_copy! for wiring diagrams and the congruence closure algorithm).