We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent fa22164 commit b578eddCopy full SHA for b578edd
test/rewrite.jl
@@ -2,7 +2,7 @@ using SymbolicUtils
2
3
include("utils.jl")
4
5
-@syms a b c
+@syms a b c x
6
7
@testset "Equality" begin
8
@eqtest a == a
@@ -47,6 +47,20 @@ end
47
@eqtest @rule(+(~~x,~y,~~x) => (~~x, ~y, ~~x))(term(+,6,type=Any)) == ([], 6, [])
48
end
49
50
+@testset "Commutative + and *" begin
51
+ r1 = @rule sin(~x) + cos(~x) => ~x
52
+ @test r1(sin(a)+cos(a)) === a
53
+ @test r1(sin(x)+cos(x)) === x
54
+ r2 = @rule (~x+~y)*(~z+~w)^(~m) => (~x, ~y, ~z, ~w, ~m)
55
+ r3 = @rule (~z+~w)^(~m)*(~x+~y) => (~x, ~y, ~z, ~w, ~m)
56
+ @test r2((a+b)*(x+c)^b) === (a, b, x, c, b)
57
+ @test r3((a+b)*(x+c)^b) === (a, b, x, c, b)
58
+ rPredicate1 = @rule ~x::(x->isa(x,Number)) + ~y => (~x, ~y)
59
+ rPredicate2 = @rule ~y + ~x::(x->isa(x,Number)) => (~x, ~y)
60
+ @test rPredicate1(2+x) === (2, x)
61
+ @test rPredicate2(2+x) === (2, x)
62
+end
63
+
64
@testset "Slot matcher with default value" begin
65
r_sum = @rule (~x + ~!y)^2 => ~y
66
@test r_sum((a + b)^2) === b
0 commit comments