ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Wed, 28 Jul 2021 16:30:25 +0200Polynomial ring conversion errorhttps://ask.sagemath.org/question/58137/polynomial-ring-conversion-error/I am trying to recursively solve a (zero-dimensional) system of polynomial equations in multiple variables by calculating elimination ideals, solving the resulting univariate polynomials algebraically and plugging the roots in to the original equations in order to remove a variable.
For this, it is necessary to observe within Sage that after plugging in a value for one variable, the result is then a polynomial in fewer variables. The following code shows an example where the coercion into a polynomial ring in fewer variables works in the first step but fails in the second (although in both steps the polynomial does not even contain the variable to be eliminated):
R.<x, y, s, t> = QQ[]
g = x * y
f1 = PolynomialRing(QQ, t)(t - 1)
L1.<a1> = QQ.extension(f1)
R1 = PolynomialRing(L1, [x, y, s])
g = g.change_ring(L1) # allow coefficients in L1
g = g(x, y, s, a1) # plug in t := a1
g = R1(g) # regard as polynomial in fewer variables
assert parent(g) == R1 # works
f2 = PolynomialRing(L1, s)(s - 1)
L2.<a2> = L1.extension(f2)
R2 = PolynomialRing(L2, [x, y])
g = g.change_ring(L2)
g = g(x, y, a2)
g = R2(g) # fails: "TypeError: not a constant polynomial"
(Note that this is a toy example, my code tries to achieve the same for arbitrary $R$, $f_i$'s and $g$.)FabianGWed, 28 Jul 2021 16:30:25 +0200https://ask.sagemath.org/question/58137/Multivariate Polynomial Ring +1 variablehttps://ask.sagemath.org/question/57422/multivariate-polynomial-ring-1-variable/So the idea is I was first working over
R.<w,x,y,z>=QQ[]
I have a function f and J is the Jacobian of f belonging to the ring above. I do some stuff and I end with a polynomial g in a symbolic ring in variables w,x,z. I want to lift g. So I want to do
q1, q2, q3, q4 = g.lift(J)
q1=1/3 * q1(w,x,y,z).derivative(w)
q2=1/3 *q2(w,x,y,z).derivative(x)
q3=1/3 *q3(w,x,y,z).derivative(y)
q4=1/3*q4(w,x,y,z).derivative(z)
h1=q1+q2+q3+q4
Now, the Symbolic ring has no attribute lift. This can be fixed by moving to Multivariate Polynomiial Ring by doing
g=g.polynomial(QQ)
The issue is, because g is only a function in w,x,z, this moves g to the Multivariate Polynomial Ring of w,x,z. This gives error as the Jacobian and function f is in Multivariate Polynomial Ring of w,x,y,z. I want g to be in the Multivariate Polynomial Ring of w,x,y,z even though there is no y in g. How can I do this? See my 2 attachment. In the attachment, h2 plays the role of g in my explanation above.
[C:\fakepath\Screenshot (126).png](/upfiles/1622665244126805.png)[C:\fakepath\Screenshot (123).png](/upfiles/1622665496418565.png)whatupmattWed, 02 Jun 2021 22:23:39 +0200https://ask.sagemath.org/question/57422/defining multivariate polynomial ring in scripthttps://ask.sagemath.org/question/49842/defining-multivariate-polynomial-ring-in-script/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
f.coefficients()
[10.6, 4.63, 5.332, 4.56, 3.25456, -43.54352]
but
A = QQ['theta1', 'theta2']; A
Multivariate Polynomial Ring in theta1, theta2 over Rational Field
f.coefficients()
[[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?mattbFri, 07 Feb 2020 14:16:21 +0100https://ask.sagemath.org/question/49842/How to express unknown coefficients in GF(2^8)?https://ask.sagemath.org/question/44675/how-to-express-unknown-coefficients-in-gf28/I want to make computations in GF(2^8) using the Rijndael modulus X^8+X^4+X^3+X+1 and with unknown elements of GF(2^8).
For example, I need a polynomial x which is defined as
x = x_7 * X^7 + x_6 * X^6 + x_5 * X^7 + ... + x_0
x.coefficients() should return
[x_0, x_1, x_2, x_3, x_4, ...]
If I for example add x to y, I would expect that the result would be a term like
(x_7+y_7) * X^7 + (x_6+y_6)*X^6 + ...
I tried the following:
sage: pgen = polygen(Integers(2))
sage: modulus = pgen()**8 + pgen()**4 + pgen()**3 + pgen() + 1
sage: F = FiniteField(2**8, 'X', modulus = modulus)
sage: X = F.gen()
X
sage: x_coeffs = list(var('x_%d' % i) for i in range(8))
sage: y_coeffs = list(var('y_%d' % i) for i in range(8))
sage: uF = PolynomialRing(F, 16, x_coeffs + y_coeffs); uF
Multivariate Polynomial Ring in x_0, x_1, x_2, x_3, x_4, x_5, x_6, x_7, y_0, y_1, y_2, y_3, y_4, y_5, y_6, y_7 over Finite Field in a of size 2^8
sage: poly_x = uF(x_0 * X^0 + x_1 * X^1 + x_2 * X^2 + x_3 * X^3 + x_4 * X^4 + x_5 * X^5 + x_6 * X^6 + x_7 * X^7)
sage: poly_y = uF(y_0 * X^0 + y_1 * X^1 + y_2 * X^2 + y_3 * X^3 + y_4 * X^4 + y_5 * X^5 + y_6 * X^6 + y_7 * X^7)
(which is very much like I found it in the sources of sage.crypto.mq.rijndael_gf.RijndaelGF)
But the coefficients of poly_x and poly_y are not the variables x_0, x_1 etc. but the X^0, X^1, etc...
I also tried:
sage: F = GF(2^8, 'X')
sage: X = F.gen()
X
sage: x_coeffs = list(var('x_%d' % i) for i in range(8))
sage: y_coeffs = list(var('y_%d' % i) for i in range(8))
sage: poly_x = 0*X
sage: type(poly_x)
<type 'sage.rings.finite_rings.element_givaro.FiniteField_givaroElement'>
sage: for i in xrange(8):
....: poly_x += x_coeffs[i] * X^i
....:
sage: poly_x
x_0 + X*x_1 + X^2*x_2 + X^3*x_3 + X^4*x_4 + X^5*x_5 + X^6*x_6 + X^7*x_7
sage: type(poly_x)
<type 'sage.symbolic.expression.Expression'>
sage: poly_x.coefficients()
[[X*x_1 + X^2*x_2 + X^3*x_3 + X^4*x_4 + X^5*x_5 + X^6*x_6 + X^7*x_7, 0],
[1, 1]]
which is also not what I want.
Also, expressions like the follow lead to an error:
sage: F(x_1*X)
TypeError: unable to coerce <type 'sage.symbolic.expression.Expression'>
How can I express unknown elements with unknown coefficients?rlswSat, 15 Dec 2018 17:32:46 +0100https://ask.sagemath.org/question/44675/Remove a variable from a polynomial ring k(a,b)[x1,x2,x0] where a,b are parametershttps://ask.sagemath.org/question/38710/remove-a-variable-from-a-polynomial-ring-kabx1x2x0-where-ab-are-parameters/ I am trying to homogenize polynomials using variable `x0` in a polynomial ring `k(a,b)[x1,x2]` defined as follows:
R.<a,b> = PolynomialRing( QQ, order='degrevlex' )
K = FractionField( R )
RK.<x1,x2> = PolynomialRing( K, order='degrevlex' )
After homogenization, I define the new polynomial ring with block order:
RKH.<x1,x2,x0>=PolynomialRing(K,order='degrevlex(2),degrevlex(1)')
Then in my program, I need to dehomogenize my polynomials by setting `x0=1`, and remove the variable `x0` from the polynomial ring. This works fine in a polynomial ring without the parameter fraction field. For example
P.<x,y,z>=PolynomialRing(QQ,order='degrevlex(2),degrevlex(1)')
fp=x^2+x*y+4*z^2
R=P.remove_var(z,order='degrevlex');R
R(fp(z=1)).parent()
Multivariate Polynomial Ring in x, y, z over Rational Field
Multivariate Polynomial Ring in x, y over Rational Field
Multivariate Polynomial Ring in x, y over Rational Field
However, with the fraction field `k(a,b)`, the same method does not work any more:
R.<a,b> = PolynomialRing( QQ, order='degrevlex' )
K = FractionField( R )
RK.<x1,x2> = PolynomialRing( K, order='degrevlex' )
RKH.<x1,x2,x0>=PolynomialRing(K,order='degrevlex(2),degrevlex(1)')
pf=a*x1^2-b*x1*x2+x0^2
RKHn=RKH.remove_var(x0,order='degrevlex')
pfn=pf(x0=1)
RKHn(pfn)
Multivariate Polynomial Ring in x1, x2, x0 over Fraction Field of Multivariate Polynomial Ring in a, b over Rational Field
Error in lines 11-11
TypeError: not a constant polynomial
I didn't copy down the whole error message so it doesn't look so long. Is there a way to fix this? Thank you for your help!KittyLFri, 01 Sep 2017 21:09:49 +0200https://ask.sagemath.org/question/38710/