Skip to content

Commit d893a5e

Browse files
committed
clarified documentation
1 parent 5fe8282 commit d893a5e

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

docs/src/manual/rewrite.md

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,24 @@ r1(sin(3z))
3535
nothing
3636
```
3737

38-
Slot variable (matcher) is not necessary a single variable
39-
38+
Slot variable (matcher) is not necessary a single variable:
4039
```jldoctest rewrite
4140
r1(sin(2*(w-z)))
4241
4342
# output
4443
2cos(w - z)*sin(w - z)
4544
```
4645

46+
And can also match a function:
47+
```julia
48+
r = @rule (~f)(z+1) => ~f
49+
50+
r(sin(z+1))
51+
52+
# output
53+
sin (generic function with 20 methods)
54+
55+
```
4756
Rules are of course not limited to single slot variable
4857

4958
```jldoctest rewrite
@@ -55,7 +64,7 @@ r2(sin(α+β))
5564
sin(β)*cos(α) + cos(β)*sin(α)
5665
```
5766

58-
Let's say you want to catch the coefficients of a second degree polynomial in z. You can do that with:
67+
Now let's say you want to catch the coefficients of a second degree polynomial in z. You can do that with:
5968
```jldoctest rewrite
6069
c2d = @rule ~a + ~b*z + ~c*z^2 => (~a, ~b, ~c)
6170
@@ -70,15 +79,15 @@ c2d(3 + 2z + z^2)
7079
#output
7180
nothing
7281
```
73-
the rule is not applied. This is because in the input polynomial there isnt a multiplication in front of the `z^2`. If you want to solve this you must use **defslot variables**, with syntax `~!a`:
82+
the rule is not applied. This is because in the input polynomial there isn't a multiplication in front of the `z^2`. For this you can use **defslot variables**, with syntax `~!a`:
7483
```jldoctest rewrite
7584
c2d = @rule ~!a + ~!b*z + ~!c*z^2 => (~a, ~b, ~c)
7685
7786
c2d(3 + 2z + z^2)
7887
# output
7988
(3, 2, 1)
8089
```
81-
They work like normal slot variables, but if not present take a default value depending on the operation they are in, in the above example `~b = 1`. Currently defslot variables can be defined in:
90+
They work like normal slot variables, but if they are not present they take a default value depending on the operation they are in, in the above example `~b = 1`. Currently defslot variables can be defined in:
8291

8392
Operation | Default value
8493
----------|--------------

0 commit comments

Comments
 (0)