JuliaMath / Polynomials.jl

Polynomial manipulations in Julia
http://juliamath.github.io/Polynomials.jl/
Other
303 stars 75 forks source link

Minor issue with degree #204

Closed andreasvarga closed 4 years ago

andreasvarga commented 4 years ago

I am using the function degree in some polynomial matrix computations. To figure out the maximum degree of a polynomial matrix P, I am working with the broadcasting form degree. and compute maximum(degree.(P)), which works fine for a matrix or a vector of polynomials, and even for a scalar polynomial. However, looking to the scalar case, I obtained the following result, for which I have no explanation (sorry for my ignorance):

julia> s = Poly([0,1],:s)
Poly(s)
julia> degree.([s])
1-element Array{Int64,1}:
 1
# but
julia> degree.(s)
2-element Array{Int64,1}:
 -1
  1

I wonder if this is the intended behaviour for degree.(s) or the result should be simply 1?

jverzani commented 4 years ago

Dear Andreas,

This was recently addressed in v0.7 (https://github.com/JuliaMath/Polynomials.jl/blob/master/src/common.jl#L363) ( hope).

However there are many other changes there, including a plan to deprecate the Poly constructor for Polynomial. For older code, Poly will still work, but after v1.0 uses will need to opt-in by calling using Polynomials.PolyCompat. If you have a small code base, I'd suggest using the longer form (it is now the documented form).

Thanks for the feedback. If you find upgrading doesn't fix this, please reopen.

andreasvarga commented 4 years ago

Thanks. I am writing codes for some computations on polynomial matrices, like eigenvalues, Kronecker structure, etc. For computations I am using a 3-dimensional array to store the coefficients of a polynomial matrix. However, I started to also support abstract matrices with polynomial entries as input data. I wonder if using the last version of Polynomials.jl, the compatibility with Julia 1.0 can be still ensured. From your test runs, this is apparently achieved. In this case, I will switch to using the Polynomial type instead the Poly type.

john verzani notifications@github.com schrieb am Di., 21. Apr. 2020, 13:21:

Dear Andreas,

This was recently addressed in v0.7 ( https://github.com/JuliaMath/Polynomials.jl/blob/master/src/common.jl#L363) ( hope).

However there are many other changes there, including a plan to deprecate the Poly constructor for Polynomial. For older code, Poly will still work, but after v1.0 uses will need to opt-in by calling using Polynomials.PolyCompat. If you have a small code base, I'd suggest using the longer form (it is now the documented form).

Thanks for the feedback. If you find upgrading doesn't fix this, please reopen.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/JuliaMath/Polynomials.jl/issues/204#issuecomment-617117128, or unsubscribe https://github.com/notifications/unsubscribe-auth/ALJDHEBD7XJM7MUJ7SDMQ7LRNV6UNANCNFSM4MNE67SQ .

jverzani commented 4 years ago

It should be, as of v1.0 the two types (the legacy Polyand the newer Polynomial) share much of the same code and the test set is supported, but I'm not sure all bug fixes going forward will be applied to both (likely, but may get overlooked.) The newer type is a bit more flexible with type parameters and the improved backend allows the writing of different bases. In v1.0 there will be ImmutablePolynomial where the coefficients are a tuple which will speed up polynomial evaluation and there is work to create a SpecialPolynomials package to implement orthogonal polynomials and interpolating polynomials.