Skip to content

Commit

Permalink
Add rules to distribute conj over sum and prod
Browse files Browse the repository at this point in the history
  • Loading branch information
benneti committed Dec 12, 2024
1 parent 59e3aa6 commit dc73ca9
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/simplify_rules.jl
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ let
@rule(~x \ ~y => ~y / (~x))
@rule(one(~x) => one(symtype(~x)))
@rule(zero(~x) => zero(symtype(~x)))
@rule(conj(+(~~x)) => sum(conj.(~~x)))
@rule(conj(*(~~x)) => prod(conj.(~~x)))
@rule(conj(~x::_isreal) => ~x)
@rule(real(~x::_isreal) => ~x)
@rule(imag(~x::_isreal) => zero(symtype(~x)))
Expand Down
2 changes: 2 additions & 0 deletions test/rulesets.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ end
@eqtest simplify(Term{Real}(real, [x])) == x
@eqtest simplify(Term{Real}(imag, [x])) == 0
@eqtest simplify(Term{Real}(imag, [y])) == imag(y)
@eqtest simplify(conj(x*y^2)) == x*conj(y^2)
@eqtest simplify(conj(x+y)) == x+conj(y)
@eqtest simplify(x - y) == x + -1 * y
@eqtest simplify(x - sin(y)) == x + -1 * sin(y)
@eqtest simplify(-sin(x)) == -1 * sin(x)
Expand Down

0 comments on commit dc73ca9

Please sign in to comment.