Catlab.Algebra API
Catlab.Algebra
— Module.A module for traditional computer algebra from a categorical point of view.
Catlab.Algebra.Network
— Module.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.
Doctrine of algebraic networks
TODO: Explain
Catlab.Algebra.Network.Block
— Type.A block of Julia code with input and output variables.
Catlab.Algebra.Network.compile
— Method.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.Algebra.Network.compile_block
— Method.Compile an algebraic network into a block of Julia code.
Catlab.Algebra.Network.compile_expr
— Method.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.Algebra.Network.evaluate
— Method.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.
Internal state for compilation of algebraic network into Julia function.
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.Algebra.Network.genconst
— Method.Generate a constant (symbol or expression).
Catlab.Algebra.Network.genvar
— Method.Generate a fresh variable (symbol).
This is basically gensym
with local, not global, symbol counting.
Generate Julia expression for single or multiple assignment.
Catlab.Algebra.Network.sum_expr
— Method.Generate Julia expression for sum of zero, one, or more terms.
Catlab.Syntax.show_latex
— Method.Denote composition by a semicolon ala the computer scientists.
In this context, ⋅
is too easily confused for multiplication, (space) is too implicit, and
∘
has a right-to-left connotation.
Morphism in a category
Object in a category
Morphism in a category
Object in a category
Catlab.Algebra.Tree
— Module.Expression trees for computer algebra.
This module is not an implementation of a conventional, general-purpose CAS. There are already many outstanding CAS's. Its goals are to
- display formulas in conventional notation with free variables
- facilitate interop with existing CAS's
Catlab.Algebra.Tree.Formula
— Type.An expression tree for computer algebra.
We call these "formulas" to avoid confusion with Julia expressions (Base.Expr
) and GAT expressions (Catlab.Syntax.GATExpr
). 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
— Method.Show the formula as an S-expression.
Cf. the standard library function Meta.show_sexpr
.
Catlab.Algebra.Tree.to_formula
— Method.Convert algebraic network to formula.
Assumes that the network has a single output.
Catlab.Algebra.Tree.to_formula
— Method.Convert Julia expression to formula.
Only a subset of the Julia syntax is supported.
Catlab.Syntax.show_latex
— Method.Show the expression in infix notation using LaTeX math.
Does not include $
or \[begin|end]{equation}
delimiters.
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).
Algebraic networks realized by formulas with free variables.
These methods should only be used with gensym
-ed variables since they assume that any two formulas have disjoint variables.
Catlab.Algebra.Network.evaluate
— Method.Evaluate a formula, optionally with vectorization.
Catlab.Algebra.Tree.substitute
— Method.Simultaneous substitution of variables in formula.
Catlab.Algebra.Tree.substitute
— Method.Simultaneous substitution of symbols in Julia expression.
Catlab.Algebra.Tree.sum_formulas
— Method.Create formula for sum of zero, one, or more terms.