Skip to content

Commit 5a8490a

Browse files
author
Alessandro
committed
doc readme fix
1 parent fbf8eb1 commit 5a8490a

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

README.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ for `simplify` to work. Other required methods are `gethead` and `isterm`
3131

3232
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.
3333

34-
#### `similarterm(t::MyType, f, args; type=T, metadata=nothing)` or `similarterm(t::Type{MyType}, f, args; type=T, metadata=nothing)`
34+
#### `similarterm(t::MyType, f, args; type=T, metadata=nothing)`
35+
36+
Or `similarterm(t::Type{MyType}, f, args; type=T, metadata=nothing)`.
3537

3638
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.
3739

@@ -54,7 +56,7 @@ rules that may be implemented in the future.
5456
Suppose you were feeling the temptations of type piracy and wanted to make a quick and dirty
5557
symbolic library built on top of Julia's `Expr` type, e.g.
5658

57-
```julia:piracy1
59+
```julia
5860
for f [:+, :-, :*, :/, :^] #Note, this is type piracy!
5961
@eval begin
6062
Base.$f(x::Union{Expr, Symbol}, y::Number) = Expr(:call, $f, x, y)
@@ -71,7 +73,7 @@ ex = 1 + (:x - 2)
7173

7274
How can we use SymbolicUtils.jl to convert `ex` to `(-)(:x, 1)`? We simply implement `isterm`,
7375
`head`, `arguments` and we'll be able to do rule-based rewriting on `Expr`s:
74-
```julia:piracy2
76+
```julia
7577
using TermInterface
7678
using SymbolicUtils
7779

@@ -85,15 +87,15 @@ TermInterface.similarterm(x::Type{Expr}, head, args; type=nothing, metadata=noth
8587
```
8688

8789
However, this is not enough to get SymbolicUtils to use its own algebraic simplification system on `Expr`s:
88-
```julia:piracy3
90+
```julia
8991
simplify(ex)
9092
```
9193

9294
The reason that the expression was not simplified is that the expression tree is untyped, so SymbolicUtils
9395
doesn't know what rules to apply to the expression. To mimic the behaviour of most computer algebra
9496
systems, the simplest thing to do would be to assume that all `Expr`s are of type `Number`:
9597

96-
```julia:piracy4
98+
```julia
9799
TermInterface.symtype(s::Expr) = Real
98100
TermInterface.symtype(s::Sym) = Real
99101

0 commit comments

Comments
 (0)