Skip to content

Commit 130cf14

Browse files
Simplify conj and real for ::Real
1 parent 9d1a99b commit 130cf14

File tree

3 files changed

+5
-0
lines changed

3 files changed

+5
-0
lines changed

src/simplify_rules.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ let
5151
@rule(~x / ~y => ~x * pow(~y, -1))
5252
@rule(one(~x) => one(symtype(~x)))
5353
@rule(zero(~x) => zero(symtype(~x)))
54+
@rule(conj(~x::_isreal) => ~x)
55+
@rule(real(~x::_isreal) => ~x)
5456
@rule(ifelse(~x::is_literal_number, ~y, ~z) => ~x ? ~y : ~z)
5557
]
5658

src/utils.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ is_literal_number(x) = isliteral(Number)(x)
115115
_iszero(x) = x isa Number && iszero(x)
116116
_isone(x) = x isa Number && isone(x)
117117
_isinteger(x) = (x isa Number && isinteger(x)) || (x isa Symbolic && symtype(x) <: Integer)
118+
_isreal(x) = (x isa Number && isreal(x)) || (x isa Symbolic && symtype(x) <: Real)
118119

119120
issortedₑ(args) = issorted(args, lt=<ₑ)
120121
needs_sorting(f) = x -> is_operation(f)(x) && !issortedₑ(arguments(x))

test/rulesets.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ end
1818

1919
@testset "Numeric" begin
2020
@syms a::Integer b c d x::Real y::Number
21+
@eqtest simplify(conj(x)) == x
22+
@eqtest simplify(real(x)) == x
2123
@eqtest simplify(x - y) == x + -1*y
2224
@eqtest simplify(x - sin(y)) == x + -1*sin(y)
2325
@eqtest simplify(-sin(x)) == -1*sin(x)

0 commit comments

Comments
 (0)