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

Conversions to and from RationalFunction broken #566

Open
jishnub opened this issue Apr 24, 2024 · 3 comments
Open

Conversions to and from RationalFunction broken #566

jishnub opened this issue Apr 24, 2024 · 3 comments

Comments

@jishnub
Copy link
Contributor

jishnub commented Apr 24, 2024

Julia nightly demands that convert(T, x) produce a result of type T. This is currently not the case with RationalPolynomials, where promote_rule at various places hard-codes Polynomial instead of using a proper promotion. As a consequence, the following is broken (and tests fail on Julia nightly in general):

julia> r = SparsePolynomial([1,2], :x)
(SparsePolynomial(1 + 2*x)

julia> rr = r // (r-1)
(1 + 2*x) // (2*x)

julia> oftype(rr, r)
ERROR: TypeError: in typeassert, expected RationalFunction{Int64, :x, SparsePolynomial{Int64, :x}}, got a value of type RationalFunction{Int64, :x, Polynomial{Int64, :x}}
Stacktrace:
 [1] oftype(x::RationalFunction{Int64, :x, SparsePolynomial{Int64, :x}}, y::SparsePolynomial{Int64, :x})
   @ Base ./essentials.jl:641
 [2] top-level scope
   @ REPL[12]:1
@jverzani
Copy link
Member

Thanks for letting me know!

jverzani added a commit to jverzani/Polynomials.jl that referenced this issue Apr 26, 2024
jverzani added a commit that referenced this issue Apr 26, 2024
* close issue #566

* remove bad test

* typo
@jishnub
Copy link
Contributor Author

jishnub commented Apr 29, 2024

Note that there are other instances like

function Base.convert(::Type{PQ}, q::LaurentPolynomial) where {PQ <: AbstractRationalFunction}
m = firstindex(q)
if m >= 0
p = convert(Polynomial, q)
return convert(PQ, p)
else
z = variable(q)
zᵐ = z^(-m)
p = convert(Polynomial, zᵐ * q)
return rational_function(PQ, p, convert(Polynomial, zᵐ))
end
end
where the convert explicitly uses Polynomial, which may not be the correct type

@jverzani
Copy link
Member

Yes, that one was deliberate. Perhaps it should just be deprecated and the user should convert to a polynomial type without negative powers before using.

Thanks again! I really appreciate your time and effort to point these out.

@jverzani jverzani mentioned this issue May 10, 2024
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

No branches or pull requests

2 participants