Polynomials.jl icon indicating copy to clipboard operation
Polynomials.jl copied to clipboard

Coefficient type determination for an empty polynomial matrix

Open andreasvarga opened this issue 4 years ago • 5 comments

This is possibly a silly question, but is related to the previous issue #308 .

Admitedly we have an empty polynomial matrix, created for example with the command:

julia> a=Polynomial.(rand(0,0))
0×0 Array{Polynomial{Float64},2}

julia> eltype(a)
Polynomial{Float64}

how it is possible to determine the type of coefficients (in the above case Float64). For a nonempty matrix, this is easy

julia> a=Polynomial.(rand(1,1))
1×1 Array{Polynomial{Float64},2}:
 Polynomial(0.8736304322844237)

julia> eltype(a[1])
Float64

andreasvarga avatar Feb 06 '21 17:02 andreasvarga

I think I'd suggest eltype(eltype(a)). But I'm not getting the same thing as you (though I'm on a new branch where the symbol is part of the type):

julia> a = Polynomial.(rand(0,0))
0×0 Array{Any,2}

julia> eltype(a)
Any

Whereas:

julia> p = Polynomial([1,2,3])
Polynomial(1 + 2*x + 3*x^2)

julia> a = [p p^2; -p^2 1]
2×2 Array{Polynomial{Int64,:x},2}:
 Polynomial(1 + 2*x + 3*x^2)                     …  Polynomial(1 + 4*x + 10*x^2 + 12*x^3 + 9*x^4)
 Polynomial(-1 - 4*x - 10*x^2 - 12*x^3 - 9*x^4)     Polynomial(1)

julia> eltype(eltype(a))
Int64

jverzani avatar Feb 06 '21 18:02 jverzani

I am working with Julia 1.5. eltype(eltype(a)) does not work! Is this a new feature in Julia 1.6?

john verzani [email protected] schrieb am Sa., 6. Feb. 2021, 19:05:

I think I'd suggest eltype(eltype(a)). But I'm not getting the same thing as you (though I'm on a new branch where the symbol is part of the type):

julia> a = Polynomial.(rand(0,0))

0×0 Array{Any,2}

julia> eltype(a)

Any

Whereas:

julia> p = Polynomial([1,2,3])

Polynomial(1 + 2x + 3x^2)

julia> a = [p p^2; -p^2 1]

2×2 Array{Polynomial{Int64,:x},2}:

Polynomial(1 + 2x + 3x^2) … Polynomial(1 + 4x + 10x^2 + 12x^3 + 9x^4)

Polynomial(-1 - 4x - 10x^2 - 12x^3 - 9x^4) Polynomial(1)

julia> eltype(eltype(a))

Int64

— 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/309#issuecomment-774516824, or unsubscribe https://github.com/notifications/unsubscribe-auth/ALJDHEDMROUQEIRJ6EC7G5DS5WAGXANCNFSM4XGPEMCQ .

andreasvarga avatar Feb 06 '21 18:02 andreasvarga

I'm not certain I am answering the question you are getting at, but that construct is just applying the function eltype twice (once to get that eltype of the array and again to get that of the polynomial).

jverzani avatar Feb 07 '21 00:02 jverzani

I think this issue can be closed. However, I wonder if the following is in the current version correct:

a=Polynomial.(rand(0,0))
0×0 Matrix{Any}

In an earlier version (see my first entry) it was

a=Polynomial.(rand(0,0))
0×0 Array{Polynomial{Float64},2}

andreasvarga avatar May 16 '21 13:05 andreasvarga

Yeah, I'm not sure why this changed. I thought maybe a change to broadcasting, but the behaviour is there under v1.0 too. Must be a change to the constructor. I was about to type you just need to specify the type, as in Polynomial{Float64}.(rand(0,0)), but even that failed. You need to put in the symbol too: Polynomial{Float64,:x}.(rand(0,0)).

jverzani avatar May 16 '21 15:05 jverzani