From baaefe1bb126e3c9db59475312120c82a054e99c Mon Sep 17 00:00:00 2001 From: john verzani Date: Tue, 26 Oct 2021 17:26:54 -0400 Subject: [PATCH] modify real, imag to return Sym not N(...) (#443) * modify real, imag to return Sym not N(...) * version bump, minor change --- Project.toml | 2 +- src/generic.jl | 11 ++--------- test/test-math.jl | 5 +++++ 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/Project.toml b/Project.toml index c414b1b..65e014e 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "SymPy" uuid = "24249f21-da20-56a4-8eb1-6a02cf4ae2e6" -version = "1.0.53" +version = "1.1.0" [deps] CommonEq = "3709ef60-1bee-4518-9f2f-acd86f176c50" diff --git a/src/generic.jl b/src/generic.jl index d76ad0e..1a4825a 100644 --- a/src/generic.jl +++ b/src/generic.jl @@ -98,15 +98,8 @@ function Base.transpose(f::Sym)::Sym end Base.real(::Type{Sym}) = Sym -Base.real(x::Sym) = _real(N(x)) -_real(x::Sym) = sympy.:re(x) -_real(x) = real(x) - - - -Base.imag(x::Sym) = _imag(N(x)) -_imag(x::Sym) = sympy.im(x) -_imag(x) = imag(x) +Base.real(x::Sym) = sympy.re(x) +Base.imag(x::Sym) = sympy.im(x) Base.angle(z::SymPy.SymbolicObject) = atan(sympy.im(z), sympy.re(z)) diff --git a/test/test-math.jl b/test/test-math.jl index 72e8939..3aee29b 100644 --- a/test/test-math.jl +++ b/test/test-math.jl @@ -10,6 +10,11 @@ using SpecialFunctions @test simplify(hypot(ρ*cos(ϕ), ρ * sin(ϕ))) == ρ @test simplify(hypot(ρ*cos(ϕ), 3)) == sqrt(ρ^2*cos(ϕ)^2 + 9) + @test real(sqrt(Sym(5))+im) == sqrt(Sym(5)) + @test real(sqrt(Sym(5))+im) isa Sym + @test imag(sqrt(Sym(5))+im) == 1 + @test imag(sqrt(Sym(5))+im) isa Sym + @test atan(Sym(1), 1) == PI/4 @test atan(Sym(1), -1) == 3PI/4