Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjust complex-valued functionality for DP changes #300

Merged
merged 2 commits into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/complex.jl
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,9 @@ for fun in [:real, :imag]
iszero(x) &&
return zero(polynomial_type(x, real(coefficient_type(x))))
# We replace every complex variable by its decomposition into real and imaginary part
subst_vars = filter(Base.:! ∘ isreal, variables(x))
subst_vars = unique(
ordinary_variable(v) for v in variables(x) if !isreal(v)
)
# To avoid a stack overflow on promote_type, we'll handle the empty case separately
full_version =
isempty(subst_vars) ? polynomial(x) :
Expand Down
2 changes: 1 addition & 1 deletion test/commutativetests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ include("polynomial.jl")
include("det.jl")

include("rational.jl")
isdefined(Mod, Symbol("@polycvar")) && include("complex.jl")
isdefined(Mod, Symbol("@complex_polyvar")) && include("complex.jl")

include("promote.jl")
include("hash.jl")
Expand Down
14 changes: 9 additions & 5 deletions test/complex.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
@test isreal(a^3 + 5a^2 + 4a)
@test !isreal(a^3 + 5im * a^2 + 4a)

Mod.@polycvar x y
Mod.@complex_polyvar x y
@test !isreal(x)
@test !isrealpart(x) &&
!isrealpart(conj(x)) &&
Expand Down Expand Up @@ -73,9 +73,13 @@

@test subs(4x + 8y^2 - 6x^3, [x, y] => [2 + 4im, 9 - im]) ==
(1176 - 32im) * x^0
@test subs(4x + 8y^2 - 6x^3, [x, conj(y)] => [2 + 4im, 9 - im]) ==
(1176 + 256im) * x^0
# the following are currently not supported by DP (substitution variables may
# only be the ordinary_variable, not a conjugate or real/imaginary part)
@test_broken subs(4x + 8y^2 - 6x^3, [x, conj(y)] => [2 + 4im, 9 - im]) ==
projekter marked this conversation as resolved.
Show resolved Hide resolved
(1176 + 256im) * x^0
@test_broken subs(4x + 8y^2 - 6x^3, [x, real(y)] => [2 + 4im, 9])
@test subs(4x + 8y^2 - 6x^3, [x, real(y)] => [2 + 4im, 9 + 0 * x^0]) ==
1184 + 112im + 144im * imag(y) - 8imag(y)^2
@test_broken subs(
4x + 8y^2 - 6x^3,
[x, real(y)] => [2 + 4im, 9 + 0 * x^0],
) == 1184 + 112im + 144im * imag(y) - 8imag(y)^2
end
Loading