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

Complex-valued variables #213

Merged
merged 41 commits into from
Oct 6, 2023
Merged

Complex-valued variables #213

merged 41 commits into from
Oct 6, 2023

Conversation

projekter
Copy link
Contributor

This is a first draft for the ideas mentioned in #212

@projekter projekter mentioned this pull request Jun 11, 2022
src/complex.jl Outdated Show resolved Hide resolved
src/complex.jl Outdated Show resolved Hide resolved
@blegat
Copy link
Member

blegat commented Dec 26, 2022

Sorry for not following up on this, are you still interested ?

@projekter
Copy link
Contributor Author

I am still interested, and if you also are, I'll go back and have a look at what I changed in the meantime (since I'm actively using those ideas locally for a package of mine) and update this request.

@blegat
Copy link
Member

blegat commented Dec 26, 2022

Ok, thanks, I'll have a look at the update

@projekter
Copy link
Contributor Author

Now I updated this to my current state. And I also uploaded my current implementation of all this in DynamicPolynomials.
Note that I did not include an implementation of Base.abs2, as it is not clear whether this should be done as conj(z)*z or as real(z)^2+imag(z)^2, which will give entirely different representations.
Well... you could already debate this for real(z). If z = z_r + im*z_i, is this then z_r or rather (z+conj(z))/2? For polynomials/monomials, this will make a huge difference in how many terms there are.

@blegat blegat marked this pull request as ready for review April 20, 2023 14:22
src/show.jl Outdated Show resolved Hide resolved
src/show.jl Outdated Show resolved Hide resolved
src/operators.jl Outdated Show resolved Hide resolved
src/complex.jl Show resolved Hide resolved
src/complex.jl Outdated Show resolved Hide resolved
src/complex.jl Outdated Show resolved Hide resolved
src/complex.jl Outdated Show resolved Hide resolved
src/complex.jl Outdated Show resolved Hide resolved
src/complex.jl Outdated Show resolved Hide resolved
src/complex.jl Outdated
end
return false
end
Base.conj(x::M) where {M<:AbstractMonomial} =
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would add a shortcut here in case isreal(x) is true

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same for the three methods below

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added the shortcuts; my initial rationale for not doing so was that the checks themselves are not just a query of a flag, but instead an iteration over potentially all the involved variables, so this is not a super cheap operation.
There's also the question of the function contract: Now it may return either the same object (for a no-op) or a new operation. Since MP is abstract, we don't know whether the underlying implementations are immutable/have addresses.
I added an isreal/iscomplex check for monomial vectors as well to have this explicitly and updated this in DynamicPolynomials, where it can be done much more efficiently.

src/complex.jl Outdated Show resolved Hide resolved
@projekter
Copy link
Contributor Author

Whew, when trying to implement the tests, I needed to go on the current master. I hope I found all the necessary replacements to the new conventions. Locally, all the tests work apart from two broken ones. One is due to iszero not being implemented on MutableArithmetics.Zero (since I don't know much/anything about MA, I can't comment on this). The other one is due to a difficulty on parsing incomplete substitutions - which hopefully is not the standard case. This could be mitigated (though it's more a DynamicPolynomials issue), but at some conversion cost.

@projekter
Copy link
Contributor Author

@blegat , is there something that still prevents this from being merged? Everything should be adapted for the current version, the test are working by now with the DP implementation (though you can always argue that there could be more tests), the functions are documented...

@blegat
Copy link
Member

blegat commented Jul 22, 2023

Thanks, no let's try to push this through the finish line.

src/operators.jl Outdated Show resolved Hide resolved
.github/workflows/ci.yml Outdated Show resolved Hide resolved
src/complex.jl Outdated Show resolved Hide resolved
src/complex.jl Outdated Show resolved Hide resolved
src/complex.jl Outdated Show resolved Hide resolved
src/complex.jl Outdated Show resolved Hide resolved
src/complex.jl Outdated Show resolved Hide resolved
@projekter projekter requested a review from blegat September 13, 2023 08:20
Copy link
Member

@blegat blegat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for all the work, it's been a requested feature for a long time and the implementation looks neat. We can merge once ci passes

@blegat blegat merged commit d1f41c5 into JuliaAlgebra:master Oct 6, 2023
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants