Ask Your Question
1

Multivariate polynomial cannot be evaluated at vector despite length being correct

asked 2025-06-11 21:38:24 +0200

N2B gravatar image

updated 2025-06-13 17:40:48 +0200

I am writing a function which involves a polynomial ring with a variable number of variables. I want to evaluate a polynomial at a vector with the appropriate number of entries. I'm sure that the length of the input vector is the same as the number of variables in the ring, but it raises a type error:

sage: p = 5 # any prime power
sage: l = 3 # number of variables
sage: F = GF(p) # coeff field
sage: R = PolynomialRing(F, 'x', l); R
Multivariate Polynomial Ring in x0, x1, x2 over Finite Field of size 5
sage: R.inject_variables()
Defining x0, x1, x2
sage: f = x0*x1 - x2 # polynomial in R
sage: inp = random_vector(F, l) # to be inputted into f
sage: len(R.gens()) == len(inp) # check if inp has the right number of entries to serve as the input of a polynomial over R
True
sage: f(inp)
-------------------------------------------------------------------------------------
TypeError                                        Traceback (most recent call last)
# error text
...
TypeError: x must be of correct length
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2025-06-12 20:14:15 +0200

rburing gravatar image

Sage is not smart enough to understand what you want.

In the source code we can see it does handle lists and tuples as single inputs, but not vectors.

As a workaround, you can do e.g.

sage: f(*inp)

or

sage: f(inp.list())

or

sage: f(tuple(inp))

It would be reasonable to report this as an issue (if it has not already been reported).

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2025-06-11 21:38:24 +0200

Seen: 63 times

Last updated: Jun 13