Catlab.Algebra API

# Catlab.Algebra API

A module for traditional computer algebra from a categorical point of view.

source

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.

source

Doctrine of algebraic networks

TODO: Explain

source

A block of Julia code with input and output variables.

source

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.

source

Compile an algebraic network into a block of Julia code.

source

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
source

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.

source

Internal state for compilation of algebraic network into Julia function.

source

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.

source

Generate a constant (symbol or expression).

source

Generate a fresh variable (symbol).

This is basically `gensym` with local, not global, symbol counting.

source

Generate Julia expression for single or multiple assignment.

source

Generate Julia expression for sum of zero, one, or more terms.

source

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.

source

Morphism in a category

source

Object in a category

source

Morphism in a category

source

Object in a category

source

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
source

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.

source

Show the formula as an S-expression.

Cf. the standard library function `Meta.show_sexpr`.

source

Convert algebraic network to formula.

Assumes that the network has a single output.

source

Convert Julia expression to formula.

Only a subset of the Julia syntax is supported.

source

Show the expression in infix notation using LaTeX math.

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

source

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

source

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.

source

Evaluate a formula, optionally with vectorization.

source

Simultaneous substitution of variables in formula.

source

Simultaneous substitution of symbols in Julia expression.

source

Create formula for sum of zero, one, or more terms.

source