This package contains definitions for common functions that are useful for symbolic expression manipulation. Its purpose is to provide a shared interface between various symbolic programming Julia packages, for example SymbolicUtils.jl, Symbolics.jl and Metatheory.jl.
You should define the following methods for an expression tree type T
with symbol types S
to work
with TermInterface.jl, and therefore with SymbolicUtils.jl
and Metatheory.jl.
Returns true
if x
is an expression tree (an S-expression). If true, head
and children
methods must be defined for x
.
Returns true
if x
is a function call expression. If true, operation
, arguments
must also be defined for x::T
.
Returns the head of the S-expression.
Returns the children (aka tail) of the S-expression.
Returns the function a function call expression is calling. iscall(x)
must be
true as a precondition.
Returns the arguments to the function call in a function call expression.
iscall(x)
must be true as a precondition.
Constructs an expression. T
is a constructor type, head
and children
are
the head and tail of the S-expression, type
is the type
of the S-expression.
metadata
is any metadata attached to this expression.
Note that maketerm
may not necessarily return an object of type T
. For example,
it may return a representation which is more efficient.
This function is used by term-manipulation routines to construct terms generically.
In these routines, T
is usually the type of the input expression which is being manipulated.
For example, when a subexpression is substituted, the outer expression is re-constructed with
the sub-expression. T
will be the type of the outer expression.
Packages providing expression types must implement this method for each expression type.
If your types do not support type information or metadata, you still need to accept these arguments and may choose to not use them.
When x
satisfies iscall
, returns the number of arguments of x
.
Implicitly defined if arguments(x)
is defined.
Returns the metadata attached to x
.
Returns the symbolic type of expr
. By default this is just typeof(expr)
.
Define this for your symbolic types if you want SymbolicUtils.simplify
to apply rules
specific to numbers (such as commutativity of multiplication). Or such
rules that may be implemented in the future.