From dc73ca9648ab0c66f15b3f2daeaf88e46685e109 Mon Sep 17 00:00:00 2001 From: Benedikt Tissot Date: Thu, 12 Dec 2024 12:12:33 +0100 Subject: [PATCH] Add rules to distribute conj over sum and prod --- src/simplify_rules.jl | 2 ++ test/rulesets.jl | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/simplify_rules.jl b/src/simplify_rules.jl index a612036cb..6bca6b1a0 100644 --- a/src/simplify_rules.jl +++ b/src/simplify_rules.jl @@ -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))) diff --git a/test/rulesets.jl b/test/rulesets.jl index cfbc0143e..c7bca5ba3 100644 --- a/test/rulesets.jl +++ b/test/rulesets.jl @@ -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)