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
+43-36Lines changed: 43 additions & 36 deletions
Original file line number
Diff line number
Diff line change
@@ -9,62 +9,69 @@ You should define the following methods for an expression tree type `T` with sym
9
9
with TermInterface.jl, and therefore with [SymbolicUtils.jl](https://github.com/JuliaSymbolics/SymbolicUtils.jl)
10
10
and [Metatheory.jl](https://github.com/0x0f0f0f/Metatheory.jl).
11
11
12
-
#### `istree(x::T)`or `istree(x::Type{T})`
12
+
#### `isexpr(x::T)`
13
13
14
-
Check if `x` represents an expression tree. If returns true,
15
-
it will be assumed that `operation(::T)` and `arguments(::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.
14
+
Returns `true` if `x` is an expression tree (an S-expression). If true, `head`
15
+
and `children` methods must be defined for `x`.
19
16
17
+
#### `iscall(x::T)`
20
18
21
-
#### `exprhead(x)`
19
+
Returns `true` if `x` is a function call expression. If true, `operation`, `arguments` must also be defined for `x::T`.
22
20
23
-
If `x` is a term as defined by `istree(x)`, `exprhead(x)` must return a symbol,
24
-
corresponding to the head of the `Expr` most similar to the term `x`.
25
-
If `x` represents a function call, for example, the `exprhead` is `:call`.
26
-
If `x` represents an indexing operation, such as `arr[i]`, then `exprhead` is `:ref`.
27
-
Note that `exprhead` is different from `operation` and both functions should
28
-
be defined correctly in order to let other packages provide code generation
29
-
and pattern matching features.
30
21
31
-
#### `operation(x::T)`
22
+
#### `head(x)`
32
23
33
-
Returns the head (a function object) performed by an expression
34
-
tree. Called only if `istree(::T)` is true. Part of the API required
35
-
for `simplify` to work. Other required methods are `arguments` and `istree`
24
+
Returns the head of the S-expression.
36
25
37
-
#### `arguments(x::T)`
26
+
#### `children(x)`
38
27
39
-
Returns the arguments (a `Vector`) for an expression tree.
40
-
Called only if `istree(x)` is `true`. Part of the API required
41
-
for `simplify` to work. Other required methods are `operation` and `istree`
28
+
Returns the children (aka tail) of the S-expression.
42
29
43
-
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.
Or `similarterm(t::Type{MyType}, f, args, symtype=T; metadata=nothing, exprhead=:call)`.
33
+
Returns the function a function call expression is calling. `iscall(x)` must be
34
+
true as a precondition.
48
35
49
-
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. The `exprhead` keyword argument is useful when creating `Expr`s.
36
+
#### `arguments(x)`
37
+
38
+
Returns the arguments to the function call in a function call expression.
0 commit comments