Ask Your Question

defining multivariate polynomial ring in script

asked 2020-02-07 14:16:21 +0200

mattb gravatar image

I'm trying to setup a multivariate polynomial ring within a generic python script so I can access the coefficients of an ellipse easily. One wrinkle in the problem is that I'm declaring variables that have an arbitrary display value. For instance,

theta1, theta2 = var('v1073, v1074')
f = 10.6*theta1**2 + 4.63*theta1*theta2 + 5.332*theta2**2 + 4.56*theta1 + 3.25456*theta2 - 43.54352

The reason I'm declaring a different value between the variable and the display value is because I'm using this same equation in a loop where I update the variable values to represent a current pair. This equation is being used to generate elliptical variable constraints in an optimization.

To the heart of the question. I can get the proper output for the coefficients if I declare a PolynomialRing lexographically. But this format is not compatible with a python script. How do you define the same PolynomialRing in another way? For example:

A.<theta1, theta2> = QQ[]; A
Multivariate Polynomial Ring in theta1, theta2 over Rational Field
[10.6, 4.63, 5.332, 4.56, 3.25456, -43.54352]


A = QQ['theta1', 'theta2']; A
Multivariate Polynomial Ring in theta1, theta2 over Rational Field
[[5.332*v1074^2 + 3.25456*v1074 - 43.54352, 0],
[4.63*v1074 + 4.56, 1],
[10.6, 2]]

I've tried a few other methods, but it doesn't seem to work. Even though when I look at the definition of A, I get the same answer as to what it represents. How can I define the ring, such that I get the correct answer?

edit retag flag offensive close merge delete



A = PolynomiaRing(QQ,['theta1', 'theta2'])
FrédéricC gravatar imageFrédéricC ( 2020-02-07 14:47:56 +0200 )edit

That gives me the same result as my second example.

mattb gravatar imagemattb ( 2020-02-08 00:59:48 +0200 )edit

1 Answer

Sort by » oldest newest most voted

answered 2020-02-08 12:09:24 +0200

tmonteil gravatar image

You could have a look at this answer:

TL;DR replace:

A = QQ['theta1', 'theta2']


A = QQ['theta1', 'theta2']
edit flag offensive delete link more


Perfect! So simple, but didn't know about the 'inject_variables' method. Thanks!

mattb gravatar imagemattb ( 2020-02-22 18:39:48 +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


Asked: 2020-02-07 14:16:21 +0200

Seen: 329 times

Last updated: Feb 08 '20