Skip to content

Commit 0a76487

Browse files
committed
now the pattern ~x^~m matches 1/x with m=-1
1 parent 4ee4ebb commit 0a76487

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

src/matchers.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,15 @@ function term_matcher_constructor(term, acSets)
150150
result = loop(frankestein, bindings, matchers)
151151
result !== nothing && return success(result, 1)
152152
end
153+
154+
# if data is of the alternative form 1/(...), it might match with exponent = -1
155+
if (operation(data) === /) && isequal(arguments(data)[1], 1)
156+
denominator = arguments(data)[2]
157+
T = symtype(denominator)
158+
frankestein = Term{T}(^, [denominator, -1])
159+
result = loop(frankestein, bindings, matchers)
160+
result !== nothing && return success(result, 1)
161+
end
153162

154163
# if data is a exp call, it might match with base e
155164
if operation(data)===exp

test/rewrite.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ end
121121
@test r1(1/a^b) === (a, -b) # uses frankestein
122122
@test r1(1/a^(b+2c)) === (a, -b-2c) # uses frankestein
123123
@test r1(1/a^2) === (a, -2) # uses opposite_sign_matcher
124+
@test r1(1/a) === (a, -1)
124125

125126
r2 = @rule (~x)^(~y + ~z) => (~x, ~y, ~z) # rule with term as exponent
126127
@test r2(1/a^(b+2c)) === (a, -b, -2c) # uses frankestein

0 commit comments

Comments
 (0)