Skip to content

Evaluating polynomials with zero variables gives error #2180

@wegank

Description

@wegank
using Nemo
R, () = polynomial_ring(QQ, Symbol[])
x = one(R)
evaluate(x, [])

gives the following error:

ERROR: BoundsError: attempt to access 0-element Vector{QQMPolyRingElem} at index [1]
Stacktrace:
 [1] throw_boundserror(A::Vector{QQMPolyRingElem}, I::Tuple{Int64})
   @ Base ./essentials.jl:15
 [2] getindex
   @ ./essentials.jl:919 [inlined]
 [3] evaluate(a::QQMPolyRingElem, bs::Vector{QQMPolyRingElem})
   @ Nemo ~/.julia/packages/Nemo/kdloy/src/flint/fmpq_mpoly.jl:600
 [4] evaluate(a::QQMPolyRingElem, vals::Vector{Any})
   @ AbstractAlgebra ~/.julia/packages/AbstractAlgebra/T6WZD/src/MPoly.jl:862
 [5] top-level scope
   @ REPL[5]:1

while evaluate(x, QQFieldElem[]) gives the desired result.

Indeed, in the functions below, S = parent(bs[1]) fails when bs is empty...

function evaluate(a::QQMPolyRingElem, bs::Vector{QQMPolyRingElem})
allequal(map(parent, bs)) || error("parents do not match")
R = parent(a)
S = parent(bs[1])
length(bs) != nvars(R) &&
error("Number of variables does not match number of values")
c = S()
fl = @ccall libflint.fmpq_mpoly_compose_fmpq_mpoly(c::Ref{QQMPolyRingElem}, a::Ref{QQMPolyRingElem}, bs::Ptr{Ref{QQMPolyRingElem}}, R::Ref{QQMPolyRing}, S::Ref{QQMPolyRing})::Cint
fl == 0 && error("Something wrong in evaluation.")
return c
end
function evaluate(a::QQMPolyRingElem, bs::Vector{QQPolyRingElem})
allequal(map(parent, bs)) || error("parents do not match")
R = parent(a)
S = parent(bs[1])
length(bs) != nvars(R) &&
error("Number of variables does not match number of values")
c = S()
fl = @ccall libflint.fmpq_mpoly_compose_fmpq_poly(c::Ref{QQPolyRingElem}, a::Ref{QQMPolyRingElem}, bs::Ptr{Ref{QQPolyRingElem}}, R::Ref{QQMPolyRing})::Cint
fl == 0 && error("Something wrong in evaluation.")
return c
end

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions