ASKSAGE: Sage Q&A Forum - Latest question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Tue, 26 Feb 2019 05:15:45 -0600Multivariate Laurent serieshttp://ask.sagemath.org/question/29669/multivariate-laurent-series/I'm trying to perform calculations with two variables $z, u$, one of which, $z$, should be invertible. Apparently Laurent series rings are not yet implemented for multivariate rings. I tried the following
R = QQ[['zed, you, zedi']]
R
Multivariate Power Series Ring in zed, you, zedi over Rational Field
x = R.gens()
x
(zed, you, zedi)
i = x[0]*x[2] - 1
i
-1 + zed*zedi
I = i*R
I
S = QuotientRing(R, I, names="z, u, xi")
S
Principal ideal (-1 + zed*zedi) of Multivariate Power Series Ring in zed, you, zedi over Rational Field
Quotient of Multivariate Power Series Ring in zed, you, zedi over Rational Field by the ideal (-1 + zed*zedi)
g = S.gens()
g
(zed, you, zedi)
g[0]*g[2]
zed*zedi
Apparently, in the quotient ring I still get that $z z^{-1}$ doesn't simplify to 1. Also, my assigned names aren't recognized. What am I doing wrong? Is this even the best way of dealing with multivariate Laurent polynomials?
Thank you. (This is my first day using sage and my first question here on ask.sagemath.org. Please let me know if I've done something wrong.)EarthlingThu, 01 Oct 2015 18:55:04 -0500http://ask.sagemath.org/question/29669/coercion between polynomial rings with block term ordershttp://ask.sagemath.org/question/45553/coercion-between-polynomial-rings-with-block-term-orders/ Hello,
I have the following problem:
I define a polynomial ring
R.<x,y> = PolynomialRing(QQ,2,order='deglex')
then I define a new polynomial ring, with an addition auxiliary variable and a polynomial in this ring
S = PolynomialRing(R.base(),['w1']+[str(v) for v in R.gens() ],order=TermOrder('lex',1)+R.term_order())
S.inject_variables(verbose=False)
f = w1*x^3 + w1*y + x^2 + y^2
then I define another polynomial ring, with another addition auxiliary variable. Coercing to this new ring works fine
T = PolynomialRing(S.base(),['w2']+[str(v) for v in S.gens() ],order=TermOrder('lex',1)+S.term_order())
f2 = T(f)
However the way backwards fails
S(f2)
> (...)
> /home/phil/Applications/SageMath/local/lib/python2.7/site-packages/sage/rings/polynomial/polynomial_ring.pyc in _coerce_map_from_(self, P)
791 from sage.rings.polynomial.multi_polynomial_ring import is_MPolynomialRing
792 if is_MPolynomialRing(P) and self.variable_name() in P.variable_names():
--> 793 P_ = P.remove_var(self.variable_name())
794 return self.base_ring()!=P_ and self.base_ring().has_coerce_map_from(P_)
795
> /home/phil/Applications/SageMath/local/lib/python2.7/site-packages/sage/rings/polynomial/multi_polynomial_ring_base.pyx in sage.rings.polynomial.multi_polynomial_ring_base.MPolynomialRing_base.remove_var (build/cythonized/sage/rings/polynomial/multi_polynomial_ring_base.c:5831)()
299 return PolynomialRing(self.base_ring(), vars, order=self.term_order())
300 except ValueError:
--> 301 raise ValueError("impossible to use the original term order (most likely because it was a block order). Please specify the term order for the subring")
302 else:
303 return PolynomialRing(self.base_ring(), vars, order=order)
> ValueError: impossible to use the original term order (most likely because it was a block order). Please specify the term order for the subring
Any ideas what I could do to prevent this problem? How would I specify the term order (as it was suggested)?
Kind regards,
PhilippPhilipp SchneiderTue, 26 Feb 2019 05:15:45 -0600http://ask.sagemath.org/question/45553/Groebner basis computationhttp://ask.sagemath.org/question/45340/groebner-basis-computation/ How we can use SageMath for computing Groebner basis? e.g. we have 35 multivariate polynomial equations, is it possible to compute groebner basis at a time?MMumtazWed, 06 Feb 2019 00:49:28 -0600http://ask.sagemath.org/question/45340/How to express unknown coefficients in GF(2^8)?http://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 10:32:46 -0600http://ask.sagemath.org/question/44675/Does anyone know how to implement a simple XL Algorithm in sage?http://ask.sagemath.org/question/41818/does-anyone-know-how-to-implement-a-simple-xl-algorithm-in-sage/I need to implement the XL algorithm in sage, which i can use to solve over-determined systems of polynomial equations (more equations than variables). Any help on how to do this?
DalvirThu, 29 Mar 2018 07:45:45 -0500http://ask.sagemath.org/question/41818/get the coefficients of polynomial of several variables?http://ask.sagemath.org/question/41526/get-the-coefficients-of-polynomial-of-several-variables/ Consider that I have a polynomial with n variables x1,x2,...,xn and want to get the coefficient of that polynomial. For example I can have:
x1+2*x1*x5^2+3*x1^2*x4-5*x2*x5^2+1/2*x2*x3+x6^2*x7*x8+9*x3*x9^3
I would like to ask Sage to give coefficient for the polynomial with variables x1..x9 and the result should be something like this:
coefficient,(exponent of x1..x9);
1,(1,0,0,0,0,0,0,0,0);
2,(1,0,0,0,2,0,0,0,0);
3,(2,0,0,1,0,0,0,0,0);
-5,(0,1,0,0,2,0,0,0,0);
1/2,(0,1,1,0,0,0,0,0,0);
1,(0,0,0,0,0,2,1,1);
9,(0,0,1,0,0,0,0,0,3)
How can I achieve this?
DanialBaghTue, 13 Mar 2018 21:12:52 -0500http://ask.sagemath.org/question/41526/Is there a way to get the homogeneous part of certain degree of a (multivariate) polynomial?http://ask.sagemath.org/question/39177/is-there-a-way-to-get-the-homogeneous-part-of-certain-degree-of-a-multivariate-polynomial/Every multivariate polynomial $f\in\Bbb F[x_1,\ldots,x_n]$ of degree $d$ can be written as $f = f_0+f_1+\cdots+f_d$, where $f_i$ is a **homogeneous** polynomial of degree $i$. Is there a *direct* way to get each $f_i$ given $f$ in SageMath? For a specific application I have where I only need $f_d$ I am homogenizing and then setting $h=0$, and based on this I wrote an ugly script that recursively finds $f_i$.
Is there a cleaner (and more efficient) way to do this?
Thanks for the help!
**EDIT:**
This is the code I'm using to obtain $f_d$ from $f$
fd = R( f.homogenize()(h=0) )
where R is the multivariate polynomial ring (parent of $f$). If I want $f_{d-1}$ for example, I can define $g$ as $f - f_d$ and apply the line to $g$. This recursive definition is not satisfactory since to get $f_i$ I need to have all $f_{i+1},\ldots,f_d$ first, which is inefficient. Also, that trick of homogenizing, evaluating $h=0$ and coercing the result back to the original polynomial ring is not very neat.descuderoSun, 15 Oct 2017 12:37:26 -0500http://ask.sagemath.org/question/39177/Remove a variable from a polynomial ring k(a,b)[x1,x2,x0] where a,b are parametershttp://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 14:09:49 -0500http://ask.sagemath.org/question/38710/Finding Small Roots of Multivariate Polynomial Modulo an Integerhttp://ask.sagemath.org/question/38135/finding-small-roots-of-multivariate-polynomial-modulo-an-integer/I am trying to apply Coppersmith's attack to find small roots of an example polynomial
$f(x,y) = (8x+7)(8y+7) - N \pmod{8}$
For univariate polynomials, Coppersmith's attack is implemented via the `.small_roots()` function. However, it is to my understanding that finding small roots of a multivariate polynomial modulo an integer is not implemented in Sage. Is there any workaround code / method that will allow for small root finding of the above polynomial, and others of the same form?
In this example, the results should be $x = 2$ and $y = 8$.
Relevant papers:
http://honors.cs.umd.edu/reports/lowexprsa.pdf
http://www.jscoron.fr/publications/bivariate.pdf
Thanks, and your time and effort are greatly appreciated.SanguiniusThu, 29 Jun 2017 22:30:13 -0500http://ask.sagemath.org/question/38135/Finding Small Roots of Multivariate Polynomials Modulo an Integerhttp://ask.sagemath.org/question/38134/finding-small-roots-of-multivariate-polynomials-modulo-an-integer/I am trying to apply Coppersmith's attack to find small roots of an example polynomial
$f(x,y) = (8x+7)(8y+7) \pmod{8}$
It is to my understanding that finding small roots of a multivariate polynomial modulo an integer is not implemented in Sage. However, is there a workaround code / method that will allow for small root finding of the above polynomial, and others of the same form?
Thanks, and your time and effort are greatly appreciated.
SanguiniusThu, 29 Jun 2017 22:28:46 -0500http://ask.sagemath.org/question/38134/Recasting Laurent polynomialshttp://ask.sagemath.org/question/37914/recasting-laurent-polynomials/Hi,
I have 2 Laurent polynomials, f and g, and I'm trying to recast them into multivariable polynomials over ZZ (I'm eventually going to take their gcd).
However, I'm not able to do so on the Sage Cloud.
So far, I've tried the following:
1. Extracting the monomials of f and g, and their coefficients, and reconstructed f by:
`sum(map(mul,zip(f.coefficients(),f.monomials())))`
However, this didn't help, because SAGE thinks the type is:
<type 'sage.rings.polynomial.multi_polynomial_libsingular.MPolynomial_libsingular'>
so I still can't take the gcd.
2. I also tried to recast into R.<x,y> = ZZ[], but this didn't work either: when I do `sage: f.change_ring(R)`, I get the following error:
`AttributeError: 'sage.rings.polynomial.laurent_polynomial.LaurentPolynomial_mpair' object has no attribute 'change_ring'`
Any suggestions would be greatly appreciated!! Thanks so much. krishnaSun, 11 Jun 2017 18:52:04 -0500http://ask.sagemath.org/question/37914/Multivariate symbolicshttp://ask.sagemath.org/question/37292/multivariate-symbolics/Consider this piece of code:
sage: n=4 # dimension of state-space
sage: x = polygens(QQ, ['x'+str(i) for i in [1..n]]); x # vector of state variables
(x1, x2, x3, x4)
There is a handy keyword with formal power series, the number of generators (`num_gens`), and it works like:
sage: PowerSeriesRing(QQ, 'x', num_gens=5)
Multivariate Power Series Ring in x0, x1, x2, x3, x4 over Rational Field
There is a kind of analogue with polynomials, but not keyworded:
sage: PolynomialRing(QQ, 'x', 5)
Multivariate Polynomial Ring in x0, x1, x2, x3, x4 over Rational Field
Is it possible to use any of these to define a vector of polynomial variables in the object `x` as the beginning (but without list comprehension)?
---
As a side note, i think the `var` constructor also lacks a vector form?
sage: var(['x'+str(i) for i in [1..n]])
(x1, x2, x3, x4)
This could be useful to simplify constructions as:
sage: A = matrix(SR, [['a'+str(i)+str(j) for j in [1..n]] for i in [1..n]]); A
[a11 a12 a13 a14]
[a21 a22 a23 a24]
[a31 a32 a33 a34]
[a41 a42 a43 a44]
In Matlab this is `A = sym('a', n)`, but i didn't find a similar shortcut in Sage.mforetsFri, 14 Apr 2017 01:59:58 -0500http://ask.sagemath.org/question/37292/Division algorithm in a polynomial ring with variable coefficientshttp://ask.sagemath.org/question/37098/division-algorithm-in-a-polynomial-ring-with-variable-coefficients/ I am working on an algorithm to divide a polynomial `f` by a list of polynomials `[g1, g2, ..., gm]`. The following is my algorithm:
def div(f,g): # Division algorithm on Page 11 of Using AG by Cox;
# f is the dividend;
# g is a list of ordered divisors;
# The output consists of a list of coefficients for g and the remainder;
# p is the intermediate dividend;
n = len(g)
p, r, q = f, 0, [0 for x in range(0,n)]
while p != 0:
i, divisionoccured = 0, False
print(p,r,q);
while i < n and divisionoccured == False:
if g[i].lt().divides(p.lt()):
q[i] = q[i] + p.lt()//g[i].lt()
p = p - (p.lt()//g[i].lt())*g[i]
divisionoccured = True
else:
i = i + 1
if divisionoccured == False:
r = r + p.lt()
p = p - p.lt()
return q, r
Here is an example of implementing the algorithm:
K.<a,b> = FractionField(PolynomialRing(QQ,'a, b'))
P.<x,y,z> = PolynomialRing(K,order='lex')
f=a*x^2*y^3+x*y+2*b
g1=a^2*x+2
g2=x*y-b
div(f,[g1,g2])
Here is the result:
(a*x^2*y^3 + x*y + 2*b, 0, [0, 0])
(((-2)/a)*x*y^3 + x*y + 2*b, 0, [1/a*x*y^3, 0])
(x*y + 4/a^3*y^3 + 2*b, 0, [1/a*x*y^3 + ((-2)/a^3)*y^3, 0])
(4/a^3*y^3 + ((-2)/a^2)*y + 2*b, 0, [1/a*x*y^3 + ((-2)/a^3)*y^3 + 1/a^2*y, 0])
(((-2)/a^2)*y + 2*b, 4/a^3*y^3, [1/a*x*y^3 + ((-2)/a^3)*y^3 + 1/a^2*y, 0])
(2*b, 4/a^3*y^3 + ((-2)/a^2)*y, [1/a*x*y^3 + ((-2)/a^3)*y^3 + 1/a^2*y, 0])
Error in lines 6-6
Traceback (most recent call last):
and some other error messages.
We can see that it worked well until the leading term is `2b`. it does not recognize the `2b` as a term. I tried:
(x).lt().divides(1)
It gives the answer `False`. But I tried
(x).lt().divides(a)
It gives error message. Is there a way to solve this? Thank you for your help!
KittyLMon, 27 Mar 2017 14:26:48 -0500http://ask.sagemath.org/question/37098/Computing square free part of a multivariate polynomialhttp://ask.sagemath.org/question/36768/computing-square-free-part-of-a-multivariate-polynomial/In one of the algorithms I am working on, there is a part asking for the square-free part of a multivariate polynomial. I can find it using a complicated way, namely,
I = ideal(f)
IRad = I.radical().groebner_basis()
But I think this must be a very inefficient way to do it. Is there a better way? Thank you!KittyLTue, 28 Feb 2017 14:49:14 -0600http://ask.sagemath.org/question/36768/Polynomials with multiple variables and abstract coefficientshttp://ask.sagemath.org/question/34824/polynomials-with-multiple-variables-and-abstract-coefficients/ Hey there,
I need to create a polynomials (say P1, P2) that will have a number of variables (ca. 5) and abstract coefficients (ca. 9) (but I can assume that coefficients are variables carrying integer values). Then I would like to multiply P1, P2 and collect variables and extract coefficients standing next to them, e.g
from
` XA * XB + XA^2 + 2 * A * XA + 4*XB / XC + 5`
I should be able to get
`2*A*XA + XA^2 + XA*XB + 4*XB/XC + 5`
and from this a list of coefficients like
`[2A, 1, 1, 4, 5]` (with zeros in proper places eg. coefficient for XA*XB*XC)
Browsing the net I have found sth like:
`B.<x,y,z> = QQ[];
A.<x,y,z>=B[];
ex = (1-a^2)*x*y^2+(a-b^2+c)*x*y*z+(b^2-c^2-a)*x^2*z;
ex.coefficients();
ex.monomials()`
And my questions are:
(1.) how can I pass a list of variables to define a ring, I am interested in sth like
`B.list = QQ[];
A.list2 = B[]`
(2.) As you run the code above you can easily note that the output is:
`[-x*y^2, x^2*z - x*y*z, -x^2*z, -x^2*z + x*y*z, x*y*z, x*y^2];
[a^2, b^2, c^2, a, c, 1]`
As you can see the list from ex.coefficients() contains multiply entries for x*y^2 and -x*y^2 separately. And this is no go. Any ideas how can I fix it?
Thanks for any suggestions!
Bests
MichalmpzajacThu, 15 Sep 2016 06:22:11 -0500http://ask.sagemath.org/question/34824/numerical computation of roots (maple equivalent of fsolve) of a system of nonlinear equations with multiple variables parametershttp://ask.sagemath.org/question/34002/numerical-computation-of-roots-maple-equivalent-of-fsolve-of-a-system-of-nonlinear-equations-with-multiple-variables-parameters/ Hi All, the following is my code:
### Begin Code#####
#Parameters:
k0 = 0.1
kd = 0.05
k1 = 20
j1 = 0.1
km1 = 0.2
jm1 = 0.1
k2 = 0.055
j2 = 0.1
pPTEN = 0.001
dPTEN = 0.0054
k3 = 0.006
j3 = 2
k4 = 0.15
j4 = 0.1
km4 = 73
jm4 = 0.5
pMdm2 = 0.018
dMdm2 = 0.015
dMdm2s = 0.015
k5 = 0.024
j5 = 1
k6 = 10
j6 = 0.3
km6 = 0.2
jm6 = 0.1
n1 = 3
n2 = 3
PIPtot = 1
AKTtot = 1
#Variables to solve
p53 = var('p53')
AKTs = var('AKTs')
Mdm2 = var('Mdm2')
Mdm2s = var('Mdm2s')
PIP3 = var('PIP3')
PTEN = var('PTEN')
AKT = AKTtot - AKTs
PIP2 = PIPtot - PIP3
#Rate Equations
v0 = k0
v1 = (k1 * PIP3 * AKT) / (j1 + AKT)
vm1 = (km1 * AKTs) / (jm1 + AKTs)
v2 = (k2 * Mdm2s * p53) / (j2 + p53)
v3 = (k3 * ((p53)^n1))/(((j3)^n1) + ((p53)^n1))
v4 = (k4 * PIP2)/(j4 + PIP2)
vm4 = (km4 * PTEN * PIP3)/(jm4 + PIP3)
v5 = (k5 * ((p53)^n2))/(((j5)^n2) + ((p53)^n2))
v6 = (k6 * Mdm2 * AKTs)/(j6 + Mdm2)
vm6 = (km6 * Mdm2s)/(jm6 + Mdm2s)
ss_p53 = v0 - v2 - kd*p53
ss_AKTs = v1 - vm1
ss_PIP3 = v4 - vm4
ss_PTEN = pPTEN + v3 - dPTEN * PTEN
ss_Mdm2s = v6 - vm6 - dMdm2s*Mdm2s
ss_Mdm2 = pMdm2 + v5 - v6 + vm6 - dMdm2*Mdm2
#Equation to Solve
z = solve([ss_p53==0, ss_AKTs==0, ss_PIP3==0, ss_PTEN==0, ss_Mdm2s==0, ss_Mdm2==0],\ [p53, AKTs, PIP3,PTEN, Mdm2s, Mdm2])
End Code
I tried using Sage "solve" to analytically solve the system of equations. I got a "FloatingPointError: Floating point exception"
I thought of ways to get round this exception by
1) using log and exp in my math equations -- I can't work round this
2) I have no idea how to create exceptions for this since I can't access the sub-solutions while the solutions are still underway
3)Then I tried maxima.solve --> no roots could be found
Maybe, this problem can't be solved analytically, so I thought maybe I could do so numerically.
Hence my following question,
I can only find functions that tackle univariate equations. Is there a sage equivalent of maple's f-solve which numerically computes all roots of multivariate system of nonlinear equations without the need of initial conditions?
Thanks a lot! I would really appreciate this
Rgds
Samantha
sam_kjmSun, 03 Jul 2016 12:02:15 -0500http://ask.sagemath.org/question/34002/Find the kernel of a matrix $A$ and make it a matrix.http://ask.sagemath.org/question/33533/find-the-kernel-of-a-matrix-a-and-make-it-a-matrix/ I am trying to write a function that computes the monic genrator of an ideal $I\in k[x_1,\dots,x_n]$, i.e., the generator of $I\cap k[x_i]$ for each $i$. For this I need to use linear algebra for the set
$$\{1, x_i, x_i^2,\dots\}$$
I write each one of them in terms of the basis for the quotient ring $k[x_1,\dots,x_n]/I$, and see if they are linearly dependent.
Since I add in one more power a time, when I find a linearly dependent set, it should have nullity $1$. So if I can get the one element in basis of the kernel, I am done. But the $A.kernel()$ command in Sage gives me this:
N=M.kernel();N
Vector space of degree 2 and dimension 1 over Rational Field
Basis matrix:
[0 1]
Is there a way to assign it as a vector using the kernel command? Or do I have to write my own function to implement it? Thank you for your help!KittyLTue, 24 May 2016 06:47:57 -0500http://ask.sagemath.org/question/33533/Pass a list of variable names as parameter to a polynomial ringhttp://ask.sagemath.org/question/33526/pass-a-list-of-variable-names-as-parameter-to-a-polynomial-ring/ I am trying to write a function that compute a vector space basis $B$ for the quotient ring $k[x_1,\dots,x_n]/I$. I want to make the list of variables as the input parameter.
I tried this:
var("x,y")
Vlist=[x,y]
P.<Vlist>=PolynomialRing(QQ,order='degrevlex')
f=x^2+y^3
f.lm()
It gave me error message. I also tried
Vlist=['x,y']
or
Vlist=["x,y"]
None of them works.
I know that
P.<x,y>=PolynomialRing(QQ,order='degrevlex')
f=x^2+y^3
f.lm()
works. So I can just type this before I run my function. But is there a way that I can make this as input of the function?KittyLMon, 23 May 2016 12:17:44 -0500http://ask.sagemath.org/question/33526/Extracting coefficients of multivariate polynomials?http://ask.sagemath.org/question/10195/extracting-coefficients-of-multivariate-polynomials/If I enter, say:
P.<x,y,z> = QQ[]
ex = 6*x*y^2-4*x*y*z+2*x^2*z
ex.coefficients()
then Sage returns
[6, -4, 2]
as it should. My problem is that I'm trying to obtain a list of coefficients when the coefficients are themselves expressions:
ex = (1-a^2)*x*y^2+(a-b^2+c)*x*y*z+(b^2-c^2-a)*x^2*z
What I want returned is
[1-a^2, a-b^2+c, b^2-c^2-a]
(the order doesn't matter). If I enter `a, b, c` as elements of the same polynomial ring as `x, y, z` then I have the problem of distinguishing the different variables: `x, y, z`, from `a, b, c`.
What's the best way to do this?
Thanks,
Alasdair
AlasdairWed, 05 Jun 2013 14:46:50 -0500http://ask.sagemath.org/question/10195/How to flatten polynomial rings?http://ask.sagemath.org/question/26969/how-to-flatten-polynomial-rings/ It is possible in Sage to create a polynomial ring over a polynomial ring. But Sage stores this as a two-tiered structure that is sometimes inconvenient. I would like to flatten it.
For example,
sage: P = PolynomialRing(QQ, 'c', 6)
sage: S = PolynomialRing(P, 't', 6)
creates a polynomial ring in t0, t1, t2, ...., t5 over a polynomial ring in c0, c1, ..., c5. But then
sage: clist = list( P.gens()[i] for i in range(6)) # get names for variables
sage: tlist = list( S.gens()[i] for i in range(6))
sage: poly = clist[0]*tlist[0] # produces polynomial c0*t0 in S
sage: poly.polynomial(clist[0]) # asks for poly as a polynomial in c0
fails with "var must be one of the generators of the parent polynomial
ring."
I would like to `flatten' S so it is simply a single polynomial ring over QQ in 12 variables.
You may ask, why don't I just construct a single ring in the first place? In this instance, because I want to create a polynomial ring in c0, ...., cn and t0, ...., tn where n is a variable, and I don't know how to do this (I'd prefer to avoid just making c0, ..., c2n and trying to keep track of which are actually t's). I can imagine other situations where one would like to be able to flatten also.Kate StangeThu, 28 May 2015 10:44:37 -0500http://ask.sagemath.org/question/26969/multivariate polynomial root-findinghttp://ask.sagemath.org/question/10331/multivariate-polynomial-root-finding/I have a series of large, high-degree, bivariate polynomials in two variables, p and q. For example, one of these polynomials is:
$p^7 (25/4 q^6 - 75 q^5 + 525/2 q^4 - 400 q^3 + 300 q^2 - 120 q + 20) + p^6 (-175/8 q^6 + 525/2 q^5 - 3675/4 q^4 + 1400 q^3 - 1050 q^2 + 420 q - 70) + p^5 (255/8 q^6 - 765/2 q^5 + 2655/2 q^4 - 1980 q^3 + 1425 q^2 - 540 q + 84) + p^4 (-25 q^6 + 300 q^5 - 8175/8 q^4 + 1450 q^3 - 1875/2 q^2 + 300 q - 35) + p^3 (45/4 q^6 - 135 q^5 + 1785/4 q^4 - 580 q^3 + 300 q^2 - 60 q) + p^2 (-45/16 q^6 + 135/4 q^5 - 855/8 q^4 + 120 q^3 - 75/2 q^2) + p (5/16 q^6 - 15/4 q^5 + 45/4 q^4 - 10 q^3) + 1$
I would like to find all values of $q$ for which this polynomial is equal to $1-p$. The following code block illustrates my problem:
sage: fid7tof
5/4*(5*q^6 - 60*q^5 + 210*q^4 - 320*q^3 + 240*q^2 - 96*q + 16)*p^7 - 35/8*(5*q^6 - 60*q^5 + 210*q^4 - 320*q^3 + 240*q^2 - 96*q + 16)*p^6 + 3/8*(85*q^6 - 1020*q^5 + 3540*q^4 - 5280*q^3 + 3800*q^2 - 1440*q + 224)*p^5 - 5/8*(40*q^6 - 480*q^5 + 1635*q^4 - 2320*q^3 + 1500*q^2 - 480*q + 56)*p^4 + 5/4*(9*q^6 - 108*q^5 + 357*q^4 - 464*q^3 + 240*q^2 - 48*q)*p^3 - 15/16*(3*q^6 - 36*q^5 + 114*q^4 - 128*q^3 + 40*q^2)*p^2 + 5/16*(q^6 - 12*q^5 + 36*q^4 - 32*q^3)*p + 1
sage: solve([fid7tof == 1-p], q)
[0 == 5*(10*p^4 - 20*p^3 + 16*p^2 - 6*p + 1)*q^6 - 60*(10*p^4 - 20*p^3 + 16*p^2 - 6*p + 1)*q^5 + 30*(70*p^4 - 140*p^3 + 109*p^2 - 39*p + 6)*q^4 - 160*(20*p^4 - 40*p^3 + 29*p^2 - 9*p + 1)*q^3 + 160*p^4 + 600*(4*p^4 - 8*p^3 + 5*p^2 - p)*q^2 - 320*p^3 - 960*(p^4 - 2*p^3 + p^2)*q + 112*p^2 + 48*p + 16]
All Sage returns is another multivariate polynomial, which doubtless has many solutions $\bar{q}(p)$. Is there something I can do to get these solutions?bcrigerMon, 08 Jul 2013 07:10:36 -0500http://ask.sagemath.org/question/10331/Turning an expression into a multivariate polynomial?http://ask.sagemath.org/question/10198/turning-an-expression-into-a-multivariate-polynomial/Suppose I have the expression
-a^3x^2 - a^2xy^2 + axy + bx^2 + 2bxy + xy^2
I want to turn this into a polynomial in x and y:
(1-a^2)xy^2+(a+2*b)xy+(b-a^3)x^2
so that I can then extract the coefficients (by setting x=1, y=1 in the list of operands of the new expression). How do I tell Sage which of the four variables will be the polynomial variables?AlasdairWed, 05 Jun 2013 17:57:36 -0500http://ask.sagemath.org/question/10198/multivariate power series computation with recognitionhttp://ask.sagemath.org/question/10080/multivariate-power-series-computation-with-recognition/I would like to do a computation in Sage involving formal power series but I believe some (all?) steps may be impossible:
1. define a couple of formal power series in two variables (x,y) by defining the coefficient function a(m,n) (the coefficients involve gamma functions and such, and are rational). As far as I can see there is no way to do even this step in Sage.
2. do a change of variables, something like (x,y) = (g(x,y),y), obtaining new power series. The function g(x,y) may be a polynomial or possibly itself an infinite power series.
3. multiply the resulting power series
4. Simplify the expression for the coefficients of the resulting power series c(m,n) in terms of classical quantities like gamma functions.
Which of these steps do you believe is possible in Sage? I could write my own software to deal with formal power series properly, but then I would not be able to recognize or simplify the resulting coefficients.
As an example:
1. h(x,y) is a sum of (m!)(4^n)x^m y^n with indices running from 0 to infinity,
and k(x,y) is a sum of (m+n)x^m y^n,
2. do a substitution H(x,y) = h(x,exp(xy)y)
3. multiply H*k
4. simplify the coefficients of H*k. marcoWed, 01 May 2013 19:25:32 -0500http://ask.sagemath.org/question/10080/Polynomial as a sum of simply factored expressions?http://ask.sagemath.org/question/9761/polynomial-as-a-sum-of-simply-factored-expressions/The polynomial
p^9 + p^8 + 7*p^6 + 6*p^4 + 3*p^3 + 4*p^2 + 2
can't be factored (over the rationals). However, it can be expressed in simpler form as
(p^3+1)^3 + (p^2+1)^4
Is there any way (other than trial and error) of finding such a sum, for a given (multivariate) polynomial?AlasdairMon, 18 Feb 2013 21:56:58 -0600http://ask.sagemath.org/question/9761/Solving two-variate polynomial identities http://ask.sagemath.org/question/9674/solving-two-variate-polynomial-identities/Hi, some help is appreciated concerning the following search.
Suppose **P1**,**P2**,**P3** are two-variate polynomials with integer coefficients in A,B. I'm searching for all sets (**P1**,**P2**,**P3**) such that:
i) **P1**(A,B)+**P2**(A,B)=**P3**(A,B)
ii) Greatest common denominator **P1** and **P2** equals 1 (Thus gcd( **P1**,**P2** )=1)
iii) The product **P1** * **P2** * **P3** can be divided by AB(A+B) (Thus gcd( **P1**.**P2**.**P3**, AB(A+B) )=AB(A+B))
Some well-known identities are A^2 + B(2A+B) = (A+B)^2, (B-A)^2 + 4AB = (A+B)^2 and
(A+2B)A^3 + B(2A+3B)^3 = (A+B)(A+3B)^3. Most interesting are polynomials with *only* linear factors such as: 16(A+B)B^3 + A(3A+4B)^3+(A+2B)(3A+2B)^3 and 27(B-A)(A+B)^5 + (3A+2B)A^3(3A+5B)^2 = (2A+3B)B^3(5A+3B)^2.
I'm curious if via Sage one could develop a generating algorithm (maybe there is a connection to Graphs and/or Combinatorics ...). N.B.: A [related question](http://ask.sagemath.org/question/1452/polynomial-identity) was raised earlier.
Thanks in advance for any support!
RolandRolandbTue, 01 Jan 2013 07:49:28 -0600http://ask.sagemath.org/question/9674/SAGBI-Grobner basis of an invariant polynomial systemhttp://ask.sagemath.org/question/8774/sagbi-grobner-basis-of-an-invariant-polynomial-system/Hi all!
I've been looking into the SAGBI-Grobner basis and I gave it a test drive. My very simple multivariate system is invariant and I want to find its SAGBI basis via the Singular library. I'm pretty sure the code below produces *wrong* result for some reason (I'm by no means saying there is a bug in the Singular lib).
The last polynomial is in fact *invariant* to the same G as the original system, the rest of the polynomials are identical to the original ones. A paper on the topic by Nicolas M. Thiery: [Computing Minimal Generating Sets of Invariant Rings of Permutation Groups with SAGBI-Grobner Basis](http://www.dmtcs.org/pdfpapers/dmAA0123.pdf) states that the remainder of dividing any polynomial with any other in the SAGBI basis should be 0, but I'm sure this is not the case here, or am I missing something? Sorry in advance for vagueness - I don't understand the topic 100%. It should be simple however to compute SAGBI basis of this system by hand or see just by looking at the result, that something might be wrong here. I suspect there is something wrong with the original set of polynomials... A link to the [worksheet](http://www.sagenb.org/home/pub/4457/), if it helps!
Thank you in advance,
Sash
R1.<S0,S1,S2,S3> = QQ[]
P1.<X0,X1, Y0,Y1> = Frac(R1)[]
I1 = P * [
X0 + Y0 - S0,
X0 * X1 + Y0 * Y1 - S1,
X0* ( X1^2 )+ Y0 *( Y1^2 ) - 2* S2]
PI = singular(I1)
singular.LIB("sagbi.lib")
PI.sagbi()
------------------------------------------------
X0+Y0+(-S0),
X0*X1+Y0*Y1+(-S1),
X0*X1^2+Y0*Y1^2+(-2*S2),
X0*X1^2*Y0-2*X0*X1*Y0*Y1+X0*Y0*Y1^2+(-S0)*X0*X1^2+(-S0)*Y0*Y1^2+(2*S1)*X0*X1+(2*S1)*Y0*Y1+(-2*S2)*X0+(-2*S2)*Y0+(2*S0*S2-S1^2)musevicTue, 06 Mar 2012 05:34:42 -0600http://ask.sagemath.org/question/8774/Explicit representation of element of idealhttp://ask.sagemath.org/question/8636/explicit-representation-of-element-of-ideal/ P.<x,y,z,t>=PolynomialRing(QQ,4)
C1= 17*x^2 + 7*y^2 - 26*y*z + 7*z^2
C2= 13*y^2 - 7*y*z + 13*z^2 - 51*t^2
x^4+y^4+z^4-18*t^4 in ideal(C1,C2)
So there exist \alpha, \beta in P with <latex>\alpha C1 + \beta C2 = x^4+y^4+z^4-18*t^4</latex>
What's the command to find \alpha and \beta explicitly ?fivemackTue, 17 Jan 2012 12:40:59 -0600http://ask.sagemath.org/question/8636/Basis of invariant polynomial systemhttp://ask.sagemath.org/question/8509/basis-of-invariant-polynomial-system/I've been trying to compute a Grobner basis for a specific invariant polynomial system. It has 6 variables, 6 constants and 6 equations and is invariant to a group of cardinality 2. Various algorithms have been ran on it, including FGb/Gb through Maple and Singular through SAGE system. In both cases, the invariance was ignored and the computation of the Grobner basis failed to finish after hours (sometime days) of computation, while occupying all the memory available. Please note, I do not know what exactly the underlying algorithm was (Buchberger/F4/F5...).
It is an engineering application and in practice, I would only need the first few polynomials of the Grobner basis, that is the ones with as low degree as possible. I'm an engineer not a mathematician, so my knowledge of the topic is very limited. I did however understood, that in case of invariant systems, a SAGBI basis (or invariant Grobner basis) can be computed much more efficiently. More important, the invariant Grobner basis can be computed "up to a given degree", which is exactly what I probably need.
I got a hint that such algorithm might exist in SAGE. I've been searching through the SAGE documentation, but it seems I don't know what to search for and the system is huge.
If anyone can point me to right direction it would be great!
The problem:
X0 + Y0 - S0 = 0
X0 X1 + Y0 Y1 - S1 = 0
X0 ( X1^2 + 2 X2 )+ Y0 ( Y1^2 + 2 Y2 )- 2 S2 = 0
X0 ( X1^3 + 6 X2 X1 )+ Y0 ( Y1^3 + 6 Y2 Y1 ) - 6 S3 = 0
X0 ( X1^4 + 12 X2 X1^2 + 12 X2^2 )+ Y0 ( Y1^4 + 12 Y2 Y1^2 + 12 Y2^2 )- 24 S4 = 0
X0 ( X1^5 + 20 X2 X1^3 + 60 X2^2 X1 ) + Y0 ( Y1^5 + 20 Y2 Y1^3 + 60 Y2^2 Y1 ) - 120 S5 = 0
Where X0,X1,X2,Y0,Y1,Y2 are variables S0...S5 are constants, all are complex numbers.musevicThu, 24 Nov 2011 06:20:32 -0600http://ask.sagemath.org/question/8509/partial fraction decomposition function for multivariate rational expressionshttp://ask.sagemath.org/question/8429/partial-fraction-decomposition-function-for-multivariate-rational-expressions/Hi all:
I'd like to extend Sage's partial fraction decomposition function in the QuotientField class to a function that works on quotients of *multivariate* polynomials. To this end, i've found it convenient to store a rational expression $F = P/(Q_1^{e_1} \cdots Q_m^{e_m})$ as a Python list of the form [P,[Q_1,e_1],...,[Q_m,e_m]], where $Q_1,\ldots,Q_m$ are the irreducible factors of $F$'s denominator. Let's call these special kinds of lists 'widgets'. I have several auxiliary functions that manipulate widgets.
Code design questions for you. Should i make a new class for widgets, and if so, where in the Sage tree of modules should i put this class? If not, where do i put the auxiliary functions that manipulate widgets?
Thanks for your attention.
Alex araichevWed, 02 Nov 2011 13:11:23 -0500http://ask.sagemath.org/question/8429/