You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+96-1Lines changed: 96 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -5,4 +5,99 @@ Its purpose is to provide a shared interface between various symbolic programmin
5
5
[SymbolicUtils.jl](https://github.com/JuliaSymbolics/SymbolicUtils.jl), [Symbolics.jl](https://github.com/JuliaSymbolics/Symbolics.jl) and [Metatheory.jl](https://github.com/0x0f0f0f/Metatheory.jl).
6
6
7
7
## Docs
8
-
TODO
8
+
You should define the following methods for an expression tree type `T` with symbol types `S` to work
9
+
with TermInterface.jl, and therefore with [SymbolicUtils.jl](https://github.com/JuliaSymbolics/SymbolicUtils.jl)
10
+
and [Metatheory.jl](https://github.com/0x0f0f0f/Metatheory.jl).
11
+
12
+
#### `isterm(x::T)` or `isterm(x::Type{T})`
13
+
14
+
Check if `x` represents an expression tree. If returns true,
15
+
it will be assumed that `gethead(::T)` and `getargs(::T)`
16
+
methods are defined. Definining these three should allow use
17
+
of `SymbolicUtils.simplify` on custom types. Optionally `symtype(x)` can be
18
+
defined to return the expected type of the symbolic expression.
19
+
20
+
#### `gethead(x::T)`
21
+
22
+
Returns the head (a function object) performed by an expression
23
+
tree. Called only if `isterm(::T)` is true. Part of the API required
24
+
for `simplify` to work. Other required methods are `getargs` and `isterm`
25
+
26
+
#### `getargs(x::T)`
27
+
28
+
Returns the arguments (a `Vector`) for an expression tree.
29
+
Called only if `isterm(x)` is `true`. Part of the API required
30
+
for `simplify` to work. Other required methods are `gethead` and `isterm`
31
+
32
+
In addition, the methods for `Base.hash` and `Base.isequal` should also be implemented by the types for the purposes of substitution and equality matching respectively.
Construct a new term with the operation `f` and arguments `args`, the term should be similar to `t` in type. if `t` is a `SymbolicUtils.Term` object a new Term is created with the same symtype as `t`. If not, the result is computed as `f(args...)`. Defining this method for your term type will reduce any performance loss in performing `f(args...)` (esp. the splatting, and redundant type computation). T is the symtype of the output term. You can use `SymbolicUtils.promote_symtype` to infer this type.
37
+
38
+
### Optional
39
+
40
+
#### `symtype(x)`
41
+
42
+
The supposed type of values in the domain of x. Tracing tools can use this type to
43
+
pick the right method to run or analyse code.
44
+
45
+
This defaults to `typeof(x)` if `x` is numeric, or `Any` otherwise.
46
+
For the types defined in this SymbolicUtils.jl, namely `T<:Symbolic{S}` it is `S`.
47
+
48
+
Define this for your symbolic types if you want `SymbolicUtils.simplify` to apply rules
49
+
specific to numbers (such as commutativity of multiplication). Or such
50
+
rules that may be implemented in the future.
51
+
52
+
## Example
53
+
54
+
Suppose you were feeling the temptations of type piracy and wanted to make a quick and dirty
55
+
symbolic library built on top of Julia's `Expr` type, e.g.
56
+
57
+
```julia:piracy1
58
+
for f ∈ [:+, :-, :*, :/, :^] #Note, this is type piracy!
0 commit comments