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.Sun, 23 Dec 2018 15:28:33 -0600LaurentPolynomial can't factor constantshttp://ask.sagemath.org/question/44764/laurentpolynomial-cant-factor-constants/Hi all,
Many `LaurentPolynomials` throw errors when I try to factor them. For example:
sage: R.<x,y> = LaurentPolynomialRing(QQ)
sage: R.one().factor()
AttributeError: ...
sage: (x^-1).factor()
AttributeError: ...
This seems to come from the unit part of `Polynomial.factor()` sometimes (incorrectly) living in `Integer Ring`, and sometimes (correctly) living in whatever `self.parent()` is.
Is this intentional or a bug?
Thanks,
Henryliu.henry.hlSun, 23 Dec 2018 15:28:33 -0600http://ask.sagemath.org/question/44764/kernel of a matrix defined over polynomial ringshttp://ask.sagemath.org/question/42453/kernel-of-a-matrix-defined-over-polynomial-rings/ I have a matrix defined as a function of variables in a polynomial ring defined over finite field as follows-
Gr.<xp,yp>=LaurentPolynomialRing(GF(2));
M=Matrix(Gr,[[xp-1,0],
[yp-1,0],
[0,(yp^(-1))-1],
[0,-(xp^(-1))+1]]);
I want to calculate the kernel of this matrix but the kernel function
M.kernel()
gives an error. What am I doing wrong?arpitSun, 27 May 2018 17:40:42 -0500http://ask.sagemath.org/question/42453/polynomials with roots of unity as coefficientshttp://ask.sagemath.org/question/42307/polynomials-with-roots-of-unity-as-coefficients/I have three polynomials $(1+x)^L+1$, $(1+\omega x)^L+$ and $(1+\omega^2 x)^L+1$ where $\omega$ is cube root of unity and L is some constant, for example, 2 or 3. I want to find the GCD of these polynomials. How do I define these polynomials in sagemath with coefficients as roots of unity?arpitThu, 10 May 2018 15:48:58 -0500http://ask.sagemath.org/question/42307/Laurent Expansion at Infinity / Root findinghttp://ask.sagemath.org/question/42317/laurent-expansion-at-infinity-root-finding/I'm new to sage, and I was trying to implement the following, to partial success:
I want to take the $p^{th}$ root of a polynomial (for a specified $p$), expand it as a Laurent series at infinity, and take the polynomial part of the expansion. I've written some code which seems to work with partial success, but it also fails in some very straightforward cases.
def poly_truncate(f):
g=f(1/x)
h = g.series(x==0,1).truncate()
return h(1/x)
It works, for instance, with $(x^2-3x+5)^{1/2}$ and $(x^3-5x^2+45x-713)^{1/3}$, but not (for example) with $(x^8-x^7+9x^6-7x^5+4x^4-x^3)^{1/2}$. I feel as though my method is kind of ad-hoc, and was hoping somebody could point me to a better way to do this. This is the error message it throws, for what it's worth:
poly_truncate((x^8-x^7+9*x^6-7*x^5+4*x^4-x^3)^(1/2))
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-6-d95c1391d7b5> in <module>()
----> 1 poly_truncate((x**Integer(8)-x**Integer(7)+Integer(9)*x**Integer(6)-Integer(7)*x**Integer(5)+Integer(4)*x**Integer(4)-x**Integer(3))**(Integer(1)/Integer(2)))
<string> in poly_truncate(f)
/Applications/SageMath-8.1.app/Contents/Resources/sage/src/sage/symbolic/expression.pyx in sage.symbolic.expression.Expression.__call__ (build/cythonized/sage/symbolic/expression.cpp:32775)()
5273 z^2 + x^y
5274 """
-> 5275 return self._parent._call_element_(self, *args, **kwds)
5276
5277 def variables(self):
/Applications/SageMath-8.1.app/Contents/Resources/sage/src/sage/symbolic/ring.pyx in sage.symbolic.ring.SymbolicRing._call_element_ (build/cythonized/sage/symbolic/ring.cpp:11496)()
973 d[ vars[i] ] = arg
974 except IndexError:
--> 975 raise ValueError("the number of arguments must be less than or equal to %s"%len(vars))
976
977 return _the_element.subs(d, **kwds)
ValueError: the number of arguments must be less than or equal to 0
Additionally, is there a faster/more trustworthy built-in function or package which computes the rational/integer roots of polynomials in $\mathbb{Q}[x]$ (i.e. better than just f.roots())?canuckleheadFri, 11 May 2018 23:00:02 -0500http://ask.sagemath.org/question/42317/How do I code a Laurent Series with variable coefficients?http://ask.sagemath.org/question/39662/how-do-i-code-a-laurent-series-with-variable-coefficients/Edit: Adding more context.
I am attempting the following procedure:
1. Begin with a polynomial $Z(u)$ with variable coefficients, of the form $1 + a*u + b*u^2 + c*u^3 + p*b*u^4 + p^2*a*u^5 + p^3*u^6$.
2. Examine the coefficients of $Z'(u)/Z(u)$ as a power series in $u$.
It is this quest which leads me to attempt to construct a LaurentSeriesRing with variable coefficients. However, I keep encountering TypeErrors, I am wondering if a kind soul could help me in my quest. I will use here a very simple polynomial f to get the point across.
I am attempting to construct a LaurentSeriesRing with variable coefficients. However, I keep encountering TypeErrors, I am wondering if a kind soul could help me in my quest. I will use here a very simple polynomial f to get the point across.
sage: R.<t> = LaurentSeriesRing(QQ, 't')
sage: var('a')
a
sage: f = 1 + a*t
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-31-06d3f2f41e45> in <module>()
----> 1 f = Integer(1) + a*t
sage/structure/element.pyx in sage.structure.element.Element.__mul__ (/usr/lib/sagemath//src/build/cythonized/sage/structure/element.c:12443)()
sage/structure/coerce.pyx in sage.structure.coerce.CoercionModel_cache_maps.bin_op (/usr/lib/sagemath//src/build/cythonized/sage/structure/coerce.c:10496)()
TypeError: unsupported operand parent(s) for '*': 'Symbolic Ring' and 'Laurent Series Ring in t over Rational Field'
I also tried:
sage: R.<u> = QQ[]
sage: var('a')
a
sage: f = 1 + a*u
sage: ff = derivative(f, u)
sage: R.<u> = LaurentSeriesRing(QQ); R
sage: f/ff + O(u^5)
----------------------
TypeError Traceback (most recent call last)
<ipython-input-28-c4846de7ced8> in <module>()
----> 1 f/ff + O(u**Integer(5))
sage/structure/element.pyx in sage.structure.element.Element.__add__ (/usr/lib/sagemath//src/build/cythonized/sage/structure/element.c:11198)()
sage/structure/coerce.pyx in sage.structure.coerce.CoercionModel_cache_maps.bin_op (/usr/lib/sagemath//src/build/cythonized/sage/structure/coerce.c:10496)()
TypeError: unsupported operand parent(s) for '+': 'Symbolic Ring' and 'Laurent Series Ring in u over Rational Field'masseygirlSun, 19 Nov 2017 13:35:21 -0600http://ask.sagemath.org/question/39662/How can I take a fractional power and a power series inverse?http://ask.sagemath.org/question/39734/how-can-i-take-a-fractional-power-and-a-power-series-inverse/I am attempting to take the power series inverse of the Taylor series expansion of $(x^4-x)^{1/3}$ around the point 0.
When I attempt to define g=(x^4-x)^{1/3} :
sage: R.<x> = LaurentPolynomialRing(QQ);
sage: g = (x^4-x)^{1/3}
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-21-675538f6f472> in <module>()
----> 1 g = (x**Integer(4)-x)**{Integer(1)/Integer(3)}
sage/rings/polynomial/laurent_polynomial.pyx in sage.rings.polynomial.laurent_polynomial.LaurentPolynomial_univariate.__pow__ (/usr/lib/sagemath//src/build/cythonized/sage/rings/polynomial/laurent_polynomial.c:10802)()
TypeError: int() argument must be a string or a number, not 'set'
Now, when I define $g$ as follows, I am unable to take the power series inverse:
sage: var('x')
x
sage: g = (1-x)**(1/3)
sage: G = g.taylor(x, 0, 10)
sage: 1/G
-4782969/(55913*x^10 + 64515*x^9 + 75735*x^8 + 90882*x^7 + 112266*x^6 + 144342*x^5 + 196830*x^4 + 295245*x^3 + 531441*x^2 + 1594323*x - 4782969)
sage: 1/G + O(x^10)
---------------------------------------------------------------------------
ArithmeticError Traceback (most recent call last)
<ipython-input-12-9fe94787aacb> in <module>()
----> 1 Integer(1)/G + O(x**Integer(10))
/usr/lib/sagemath/local/lib/python2.7/site-packages/sage/rings/big_oh.py in O(*x, **kwds)
154 elif hasattr(x, 'O'):
155 return x.O(**kwds)
--> 156 raise ArithmeticError("O(%s) not defined" % (x,))
ArithmeticError: O(x^10) not defined
sage: G.inverse()
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-14-34018a4209b6> in <module>()
How can I have the best of both worlds? In the end, I would like to have an element in the Laurent Series Ring, for the next stage is to take the formal integral of the result, and the composition inverse of this formal integral.masseygirlWed, 22 Nov 2017 14:36:44 -0600http://ask.sagemath.org/question/39734/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/Constant coefficient of Laurent Polynomialshttp://ask.sagemath.org/question/35746/constant-coefficient-of-laurent-polynomials/I am looking for the constant coefficient of a Laurent polynomial, the issue I am having is that sage is not simplifying the polynomial.
An example:
a = var(",".join( "a%i" %i for i in range(0, 6)))
f = x*y + 1.00000000000000*a6*x + 1.00000000000000*a4*y + x*y^-1 + x^-1*y + 1.00000000000000*a3*y^-1 + 1.00000000000000*a1*x^-1 + x^-1*y^-1
Then I ask
f/(x^1*y^0) # (The powers have to be in this way, just from the context of the work I am doing)
and it outputs:
1.00000000000000/x*x*y + 1.00000000000000*a6/x*x + 1.00000000000000*a4/x*y + 1.00000000000000/x*x*y^-1 + 1.00000000000000/x*x^-1*y + 1.00000000000000*a3/x*y^-1 + 1.00000000000000*a1/x*x^-1 + 1.00000000000000/x*x^-1*y^-1
Now when I ask for the constant coefficient of this LP it tells me its 0 when it is a6.
How can I fix this.
Thanks in advanceEd CalSat, 26 Nov 2016 17:35:11 -0600http://ask.sagemath.org/question/35746/Coercion and Laurent polynomialhttp://ask.sagemath.org/question/33650/coercion-and-laurent-polynomial/
Hi! Is there a simple way to make easy coercion from Symbolic Ring to Laurent polynomial ring (or even algebraic extension)? I've only been able to bypass the problem by the following trick (and due the amount of time I've spent on this I'm happy to share it!) :
# Polynomial in the Symbolic Ring
var('t')
P = t^3 + 1/10*t + 3*t^-1
# Laurent polynomial
ringS.<t> = LaurentPolynomialRing(QQ)
#PP = ringS(P) # Not working
PP = ringS(sage_eval(str(P),locals={'t':t}))
print P, P.parent()
print PP, PP.parent()Arnaud1418Thu, 02 Jun 2016 13:11:36 -0500http://ask.sagemath.org/question/33650/GCD of multivariable polynomials and conversion of Laurent polynomials to ordinary polynomialshttp://ask.sagemath.org/question/33260/gcd-of-multivariable-polynomials-and-conversion-of-laurent-polynomials-to-ordinary-polynomials/Let's assume that I am working with some set of Laurent polynomials in $\mathbb{C}[t_1^{\pm1}, \ldots, t_n^{\pm 1}]$.
R = LaurentPolynomialRing(CC, 't', n)
My first question: is there any method which would multiply elements of $R$ by a big enough monomial $t_1^{k_1}\cdot \ldots \cdot t_n^{k_n}$ to get rid of the negative powers and after that changed them to ordinary polynomials? I will consider resulting polynomials up to $t_1^{k_1}\cdot \ldots \cdot t_n^{k_n}$, so $k_i$'s don't matter that much as long as multiplication will result in a Laurent polynomial with non-negative powers (however I would like to avoid shifting exponents by some huge constant). At the moment I am using following workaround which I hope is redundant to some sage method.
# Since I am working over C I would like to get rid of summands coming from numeric errors
def clean_poly(laurent_poly, precision):
decomp = list(laurent_poly)
ret = 0
for (coeff, monom) in decomp:
if(coeff * coeff.conjugate() >= precision):
ret += coeff * monom
return ret
# Here I am finding lowest exponents of laurent_poly corresponding to particular t_i's
def find_shift(laurent_poly, n):
shift = [0 for i in range(0, n)]
for exp in laurent_poly.exponents():
for i in range(0, n):
shift[i] = max(shift[i], -exp[i])
return shift
def change_laurent_poly_to_ordinary(laurent_poly, R_ordinary, n):
laurent_poly = clean_poly(laurent_poly, 0.00000000001)
decomp = list(laurent_poly)
shift = find_shift(laurent_poly, n)
ret = 0
for (coeff, monom) in decomp:
exp = monom.exponents()
exp = exp[0]
summand = 1
for i in range(0, n):
summand *= (R_ordinary.gen(i)) ^ (exp[i] + shift[i])
ret += coeff * summand
return ret
Where $R_{\text{ordinary}} = \mathbb{C}[t_1, \ldots, t_n]$ is passed as argument in the last method.
R_ordinary = PolynomialRing(CC, 's', n)
My second and the most important question is how to fix the last method to return a polynomial which posses a gcd() method just like in this snippet which I've found in the documentation (I can't post a link due to insufficient karma):
sage: R, (x, y) = PolynomialRing(RationalField(), 2, 'xy').objgens()
sage: f = (x^3 + 2*y^2*x)^2
sage: g = x^2*y^2
sage: f.gcd(g)
x^2
Unfortunately at the moment method change_laurent_poly_to_ordinary returns class of type MPolynomial_polydict which doesn't have gcd() method, what results in the following error after attempting to use them:
Traceback (most recent call last):
File "/projects/sage/sage-6.10/local/lib/python2.7/site-packages/smc_sagews/sage_server.py", line 905, in execute
exec compile(block+'\n', '', 'single') in namespace, locals
File "", line 28, in <module>
File "sage/structure/element.pyx", line 420, in sage.structure.element.Element.__getattr__ (/projects/sage/sage-6.10/src/build/cythonized/sage/structure/element.c:4675)
return getattr_from_other_class(self, P._abstract_element_class, name)
File "sage/structure/misc.pyx", line 259, in sage.structure.misc.getattr_from_other_class (/projects/sage/sage-6.10/src/build/cythonized/sage/structure/misc.c:1771)
raise dummy_attribute_error
AttributeError: 'MPolynomial_polydict' object has no attribute 'gcd'
I am working with sage version offered by cloud sagemath.EilenbergFri, 29 Apr 2016 17:21:39 -0500http://ask.sagemath.org/question/33260/Multivariate 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/Eigenvalues of matrices of Laurent polynomialshttp://ask.sagemath.org/question/28844/eigenvalues-of-matrices-of-laurent-polynomials/Say that I have a matrix whose entries are univariate Laurent polynomials over complex numbers. In that case, I can substitute the variable for non-zero complex numbers to obtain an ordinary complex matrix. My question is the following: what the correct way to obtain the eigenvalues of the resulting complex matrix? My first guess was to do something like the following which just throws a NotImplementedError:
sage: R = LaurentPolynomialRing(CC, 'x')
sage: x = R.gens()[0]
sage: m = matrix([[x]])
sage: m.subs({x: 2}).eigenvalues()fugledeFri, 14 Aug 2015 09:26:16 -0500http://ask.sagemath.org/question/28844/Implement mapping symmetric polynomial to Laurent polynomialhttp://ask.sagemath.org/question/28717/implement-mapping-symmetric-polynomial-to-laurent-polynomial/ How can you implement transforming a symmetric polynomial into a Laurent polynomial by mapping some variables to the inverses of others? In other words, given, say, a polynomial in $x_0,y_0,x_1,y_1$, how can we output this polynomial under the map sending $y_i$ to $x_i^{-1}$? I'm specifically looking to apply this to Hall-Littlewood polynomials if that helps.rogervanpeskiMon, 27 Jul 2015 17:01:08 -0500http://ask.sagemath.org/question/28717/TypeError for hom between multivariate Laurent polynomial rings?http://ask.sagemath.org/question/26813/typeerror-for-hom-between-multivariate-laurent-polynomial-rings/I am having an error whenever I attempt to construct a homomorphism
- from a Laurent polynomial ring
- to a Laurent polynomial ring in more than one variable.
Ex (SageMath Cloud, 5/12/15):
> R.<a>=LaurentPolynomialRing(ZZ)
>
> S.<b,c>=LaurentPolynomialRing(ZZ)
>
> phi=Hom(R,S)([b])
>
>>TypeError: images do not define a valid homomorphism
Additional data:
- An identical error occurs with the variant syntax R.hom([b]).
- An identical error occurs when trying to construct the identity homomorphism on LaurentPolynomialRing(ZZ,'x,y').
- There is no error if the domain is replaced by PolynomialRing(ZZ,'a').
- There is no error if the image of 'a' is 1.
- There is no error if the codomain is replaced by its own fraction field.
It appears that Sage is incorrectly determining that the reciprocal of the image of the generator(s) is not in the codomain.Greg MullerTue, 12 May 2015 11:47:39 -0500http://ask.sagemath.org/question/26813/monomial orders in Laurent polynomialshttp://ask.sagemath.org/question/25411/monomial-orders-in-laurent-polynomials/ in Sage you can compare Laurent polynomials using a specified monomial order, one of the following standard ones: lex, grlex, invergrlex etc.
does anyone know how these monomial orders are defined for Laurent polynomials? are they well-orders too?marcin.szalskiTue, 06 Jan 2015 05:05:24 -0600http://ask.sagemath.org/question/25411/How to compute the asymptotics of a polynomial fraction?http://ask.sagemath.org/question/10907/how-to-compute-the-asymptotics-of-a-polynomial-fraction/How to compute the asymptotic of the coefficients of the Laurent serie of a polynomial fraction?slabbeFri, 24 Jan 2014 01:10:40 -0600http://ask.sagemath.org/question/10907/How to differentiate in the Laurent polynomial ring?http://ask.sagemath.org/question/10767/how-to-differentiate-in-the-laurent-polynomial-ring/ R.<x> = LaurentPolynomialRing(ZZ,1); R
f = x^2 - 2*x^-2
diff(f,x)
Expected: 2*x+4/x^3
TypeError: no canonical coercion from Univariate Laurent
Polynomial Ring in x over Integer Ring to Symbolic Ring.
petropolisSat, 23 Nov 2013 01:17:33 -0600http://ask.sagemath.org/question/10767/