Ask Your Question
1

How to make a list of polynomials callable?

asked 2022-04-13 15:26:17 +0200

updated 2022-04-13 15:29:48 +0200

A polynomial is callable:

sage: R=PolynomialRing(QQ,5,"x")
sage: R.gens()
(x0, x1, x2, x3, x4)
sage: f=x0*x1-x3
sage: f
x0*x1 - x3
sage: f(1,1,1)
0

but a list of polynomial is not:

sage: L=[x0*x1, x2, x3*x4]
sage: L(1,1,1,1,1)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-38-7ed7fddd166b> in <module>
----> 1 L(Integer(1),Integer(1),Integer(1),Integer(1),Integer(1))

TypeError: 'list' object is not callable

Question: How to make a list of polynomials callable?

I would like a function MakeCallable as follows:

sage: def MakeCallable(L):
....:     ....
....:     return fL

where fL would be as follows (here L=[x0*x1, x2, x3*x4]):

sage: def fL(x0, x1, x2, x3, x4):
....:     return [x0*x1, x2, x3*x4]
edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
2

answered 2022-04-13 15:50:38 +0200

rburing gravatar image

You can use MakeCallable = vector:

sage: R=PolynomialRing(QQ,5,"x")
sage: R.inject_variables()
Defining x0, x1, x2, x3, x4
sage: L=vector([x0*x1, x2, x3*x4])
sage: L(1,1,1,1,1)
(1, 1, 1)
edit flag offensive delete link more

Comments

I need to use it in a situation as follows

sage: var('y0,y1')
(y0, y1)
sage: E=[y0,y1]
sage: R=PolynomialRing(QQ,2,"y")
sage: EE=[e.polynomial(R) for e in E]
sage: EE
[y0, y1]
sage: VE=vector(EE)

but I get the following error:

TypeError: unable to find a common ring for all elements
Sébastien Palcoux gravatar imageSébastien Palcoux ( 2022-04-13 18:38:08 +0200 )edit

Are you sure you want e.polynomial(R)? (Check the parent/ring of the element you get; it is probably not what you want.) I suppose you want e.polynomial(ring=R), a.k.a. R(e).

rburing gravatar imagerburing ( 2022-04-13 18:45:16 +0200 )edit

Yes, thanks!

Sébastien Palcoux gravatar imageSébastien Palcoux ( 2022-04-13 18:55:11 +0200 )edit

Your Answer

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

Add Answer

Question Tools

1 follower

Stats

Asked: 2022-04-13 15:26:17 +0200

Seen: 163 times

Last updated: Apr 13 '22