Skip to content

Commit 933b982

Browse files
move real,imag and conj out of monadic, fix test
1 parent 9a7aa19 commit 933b982

File tree

2 files changed

+9
-15
lines changed

2 files changed

+9
-15
lines changed

src/methods.jl

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ import SpecialFunctions: gamma, loggamma, erf, erfc, erfcinv, erfi, erfcx,
44
besselj1, bessely0, bessely1, besselj, bessely, besseli,
55
besselk, hankelh1, hankelh2, polygamma, beta, logbeta
66

7-
const monadic = [deg2rad, rad2deg, transpose, conj, asind, log1p, acsch,
7+
const monadic = [deg2rad, rad2deg, transpose, asind, log1p, acsch,
88
acos, asec, acosh, acsc, cscd, log, tand, log10, csch, asinh,
99
abs2, cosh, sin, cos, atan, cospi, cbrt, acosd, acoth, acotd,
1010
asecd, exp, acot, sqrt, sind, sinpi, asech, log2, tan, exp10,
1111
sech, coth, asin, cotd, cosd, sinh, abs, csc, tanh, secd,
12-
atand, sec, acscd, cot, exp2, expm1, atanh, real, imag, gamma,
12+
atand, sec, acscd, cot, exp2, expm1, atanh, gamma,
1313
loggamma, erf, erfc, erfcinv, erfi, erfcx, dawson, digamma,
1414
trigamma, invdigamma, polygamma, airyai, airyaiprime, airybi,
1515
airybiprime, besselj0, besselj1, bessely0, bessely1]
@@ -97,9 +97,6 @@ promote_symtype(::typeof(rem2pi), T::Type{<:Number}, mode) = T
9797
Base.rem2pi(x::Symbolic{<:Number}, mode::Base.RoundingMode) = term(rem2pi, x, mode)
9898

9999
for f in monadic
100-
if f in [real, imag, conj]
101-
continue
102-
end
103100
@eval promote_symtype(::$(typeof(f)), T::Type{<:Number}) = promote_type(T, Real)
104101
@eval (::$(typeof(f)))(a::Symbolic{<:Number}) = term($f, a)
105102
end
@@ -111,15 +108,12 @@ for f in [identity, one, zero, *, +, -]
111108
@eval promote_symtype(::$(typeof(f)), T::Type{<:Number}) = T
112109
end
113110

114-
# All of these need to be `Sym` to overwrite the function definitions of
115-
# the L78, that are made with the type `Sym <: Symbolic`
116-
# @number_methods(Sym, term(f, a), term(f, a, b), skipbasics)
117111
promote_symtype(::typeof(Base.real), T::Type{<:Number}) = Real
118-
Base.real(s::Sym{<:Real}) = s
112+
Base.real(s::Symbolic{<:Number}) = islike(s, Real) ? s : term(real, s)
119113
promote_symtype(::typeof(Base.conj), T::Type{<:Number}) = T
120-
Base.conj(s::Sym{<:Real}) = s
114+
Base.conj(s::Symbolic{<:Number}) = islike(s, Real) ? s : term(conj, s)
121115
promote_symtype(::typeof(Base.imag), T::Type{<:Number}) = Real
122-
Base.imag(s::Sym{<:Real}) = zero(symtype(s))
116+
Base.imag(s::Symbolic{<:Number}) = islike(s, Real) ? zero(symtype(s)) : term(conj, s)
123117

124118
## Booleans
125119

test/rulesets.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
using Random: shuffle, seed!
2-
using SymbolicUtils: getdepth, Rewriters
2+
using SymbolicUtils: getdepth, Rewriters, Term
33

44
@testset "Chain, Postwalk and Fixpoint" begin
55
@syms w z α::Real β::Real
@@ -18,9 +18,9 @@ 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
23-
@eqtest simplify(imag(x)) == 0
21+
@eqtest simplify(Term{Real}(conj, [x])) == x
22+
@eqtest simplify(Term{Real}(real, [x])) == x
23+
@eqtest simplify(Term{Real}(imag, [x])) == 0
2424
@eqtest simplify(x - y) == x + -1*y
2525
@eqtest simplify(x - sin(y)) == x + -1*sin(y)
2626
@eqtest simplify(-sin(x)) == -1*sin(x)

0 commit comments

Comments
 (0)