Skip to content

Commit ba291c6

Browse files
adjoint(Symbolic{Number}) method
1 parent bbbf2d9 commit ba291c6

File tree

2 files changed

+4
-38
lines changed

2 files changed

+4
-38
lines changed

src/methods.jl

Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -160,37 +160,14 @@ for f in [identity, one, zero, *, +, -]
160160
end
161161

162162
promote_symtype(::typeof(Base.real), T::Type{<:Number}) = Real
163+
Base.real(s::Symbolic{<:Number}) = islike(s, Real) ? s : term(real, s)
163164
promote_symtype(::typeof(Base.conj), T::Type{<:Number}) = T
165+
Base.conj(s::Symbolic{<:Number}) = islike(s, Real) ? s : term(conj, s)
164166
promote_symtype(::typeof(Base.imag), T::Type{<:Number}) = Real
165-
function Base.real(s::Symbolic{<:Number})
166-
if iscall(s)
167-
f = operation(s)
168-
args = map(real, arguments(s))
169-
return f(args...)
170-
else
171-
islike(s, Real) ? s : term(real, s)
172-
end
173-
end
174-
function Base.conj(s::Symbolic{<:Number})
175-
if iscall(s)
176-
f = operation(s)
177-
args = map(conj, arguments(s))
178-
return f(args...)
179-
else
180-
islike(s, Real) ? s : term(conj, s)
181-
end
182-
end
183-
function Base.imag(s::Symbolic{<:Number})
184-
if iscall(s)
185-
f = operation(s)
186-
args = map(imag, arguments(s))
187-
return f(args...)
188-
else
189-
islike(s, Real) ? zero(symtype(s)) : term(imag, s)
190-
end
191-
end
167+
Base.imag(s::Symbolic{<:Number}) = islike(s, Real) ? zero(symtype(s)) : term(imag, s)
192168
Base.adjoint(s::Symbolic{<:Number}) = conj(s)
193169

170+
194171
## Booleans
195172

196173
# binary ops that return Bool

test/basics.jl

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -353,15 +353,4 @@ end
353353
@test typeof(sin(x)) <: BasicSymbolic{LiteralReal}
354354
end
355355
@test repr(sin(x) + sin(x)) == "sin(x) + sin(x)"
356-
end
357-
358-
@testset "real and complex" begin
359-
@syms x y z::Real
360-
@test isequal(conj(x*y*z), conj(x)*conj(y)*z)
361-
@test isequal(conj(x*y*z + y), conj(x)*conj(y)*z + conj(y))
362-
@test isequal(real(x*y*z + y), real(x)*real(y)*z + real(y))
363-
@test isequal(imag(x*y*z + y), imag(y))
364-
@test isequal(imag(x*y*z + y), imag(y))
365-
@test isequal(conj(exp(1im*x)*y), conj(exp(1im*x))*conj(y))
366-
@test isequal(adjoint(x*y*z), conj(x)*conj(y)*z)
367356
end

0 commit comments

Comments
 (0)