Programs
Catlab.Programs.JuliaPrograms
— ModuleMorphisms 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.Block
— TypeA block of Julia code with input and output variables.
Catlab.Programs.JuliaPrograms.CompileState
— TypeInternal state for compilation of morphism into Julia code.
Catlab.Programs.JuliaPrograms.compile
— MethodCompile a morphism expression into a Julia function.
Catlab.Programs.JuliaPrograms.compile_block
— MethodCompile a morphism expression into a block of Julia code.
Catlab.Programs.JuliaPrograms.compile_expr
— MethodCompile a morphism expression into a Julia function expression.
Catlab.Programs.JuliaPrograms.parse_wiring_diagram
— MethodParse a wiring diagram from a Julia function expression.
See also: @parse_wiring_diagram
Catlab.Programs.JuliaPrograms.@parse_wiring_diagram
— MacroParse 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.AlgebraicNets
— ModuleComputer 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.AlgebraicNetSignature
— ModuleDoctrine of algebraic networks
TODO: Explain
Catlab.Programs.AlgebraicNets.compile_expr_vector
— MethodCompile 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.evaluate
— MethodEvaluate 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.compile
— MethodCompile 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_block
— MethodCompile an algebraic network into a block of Julia code.
Catlab.Programs.JuliaPrograms.compile_expr
— MethodCompile 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.ExpressionTrees
— ModuleExpression 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.Formula
— TypeAn 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.
Base.Meta.show_sexpr
— MethodShow the formula as an S-expression.
Cf. the standard library function Meta.show_sexpr
.
Catlab.Programs.ExpressionTrees.to_formula
— MethodConvert algebraic network to formula.
Assumes that the network has a single output.
Catlab.Programs.ExpressionTrees.to_formula
— MethodConvert Julia expression to formula.
Only a subset of the Julia syntax is supported.
Catlab.Syntax.show_latex
— MethodShow the expression in infix notation using LaTeX math.
Does not include $
or \[begin|end]{equation}
delimiters.
Catlab.WiringDiagrams.WiringLayers.to_wiring_diagram
— MethodConvert 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).