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: docs/index.md
+21-16Lines changed: 21 additions & 16 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -12,18 +12,20 @@ where appropriate -->
12
12
13
13
The main features are:
14
14
15
-
- Symbols (`Sym`s) carry type information. ([read more](#symbolic_expressions))
16
-
- Compound expressions composed of `Sym`s propagate type information. ([read more](#symbolic_expressions))
17
-
- A flexible [rule-based rewriting language](#rule-based_rewriting) allowing liberal use of user defined matchers and rewriters.
15
+
- Fast expressions
18
16
- A [combinator library](#composing-rewriters) for making rewriters.
17
+
- A [rule-based rewriting language](#rule-based_rewriting).
18
+
- Type promotion:
19
+
- Symbols (`Sym`s) carry type information. ([read more](#symbolic_expressions))
20
+
- Compound expressions composed of `Sym`s propagate type information. ([read more](#symbolic_expressions))
19
21
- Set of [simplification rules](#simplification). These can be remixed and extended for special purposes.
20
22
21
23
22
24
## Table of contents
23
25
24
26
\tableofcontents <!-- you can use \toc as well -->
25
27
26
-
## Symbolic expressions
28
+
## `Sym`s
27
29
28
30
First, let's use the `@syms` macro to create a few symbols.
29
31
@@ -66,17 +68,6 @@ expr1 + expr2
66
68
```
67
69
\out{expr}
68
70
69
-
### Simplified printing
70
-
71
-
Tip: you can set `SymbolicUtils.show_simplified[] = true` to enable simplification on printing, or call `SymbolicUtils.showraw(expr)` to display an expression without simplification.
72
-
In the REPL, if an expression was successfully simplified before printing, it will appear in yellow rather than white, as a visual cue that what you are looking at is not the exact datastructure.
73
-
74
-
```julia:showraw
75
-
using SymbolicUtils: showraw
76
-
77
-
showraw(expr1 + expr2)
78
-
```
79
-
\out{showraw}
80
71
81
72
**Function-like symbols**
82
73
@@ -106,6 +97,20 @@ g(2//5, g(1, β))
106
97
107
98
This works because `g` "returns" a `Real`.
108
99
100
+
101
+
## Expression interface
102
+
103
+
Symbolic expressions are of type `Term{T}`, `Add{T}`, `Mul{T}` or `Pow{T}` and denote some function call where one or more arguments are themselves such expressions or `Sym`s.
104
+
105
+
All the expression types support the following:
106
+
107
+
-`istree(x)` -- always returns `true` denoting, `x` is not a leaf node like Sym or a literal.
108
+
-`operation(x)` -- the function being called
109
+
-`arguments(x)` -- a vector of arguments
110
+
-`symtype(x)` -- the "inferred" type (`T`)
111
+
112
+
See more on the interface [here](/interface)
113
+
109
114
## Rule-based rewriting
110
115
111
116
Rewrite rules match and transform an expression. A rule is written using either the `@rule` macro or the `@acrule` macro.
@@ -151,7 +156,7 @@ Notice that there is a subexpression `(2 * w) + (2 * w)` that could be simplifie
151
156
152
157
### Predicates for matching
153
158
154
-
Matcher pattern may contain slot variables with attached predicates, written as `~x::f` where `f` is a function that takes a matched expression (a `Term` object a `Sym` or any Julia value that is in the expression tree) and returns a boolean value. Such a slot will be considered a match only if `f` returns true.
159
+
Matcher pattern may contain slot variables with attached predicates, written as `~x::f` where `f` is a function that takes a matched expression and returns a boolean value. Such a slot will be considered a match only if `f` returns true.
155
160
156
161
Similarly `~~x::g` is a way of attaching a predicate `g` to a segment variable. In the case of segment variables `g` gets a vector of 0 or more expressions and must return a boolean value. If the same slot or segment variable appears twice in the matcher pattern, then at most one of the occurance should have a predicate.
0 commit comments