Hi,
I think, I've spotted my mistake. It was in the way I created the
polynomial ring.
Is it true, that
R.<x,y> = QQ[]
is equivalent to
var('x,y')
R = PolynomialRing(QQ, 'x,y')
x,y = R.gens()
I would not know, how to find the documentation for the first command.
Thanks,
Konstantin
On Feb 18, 11:15 pm, zieglerk <[email protected]> wrote:
> On Feb 18, 10:31 am, John Cremona <[email protected]> wrote:
>
>
>
> > On Feb 18, 9:15 am,zieglerk<[email protected]> wrote:
>
> > > I was pretty sure, that there was a method for polynomials to extract
> > > the coefficient of a certain monomial (say x^2). But the method I
> > > used for that before
>
> > > R = PolynomialRing(QQ, 'x')
> > > f = R.random_element(degree = 3)
> > > f.coeff(x^2)
>
> > > now returns the error
>
> > > AttributeError: 'Polynomial_rational_dense' object has no attribute
> > > 'coeff'
>
> > > Of course, there is always the workaround by the complete list of
> > > coefficients:
>
> > > f.coeffs()[2]
>
> > You can also use f[2] for this. But I agree that a method coeff() for
> > univariate polynomials would be intuitive and useful.
>
> Thanks for the hint to use f[2] or even g[1,2] for multivariate
> polynomials.
>
> > > but this certainly does not generalize to multivariate polynomials.
> > > The code I was using until very recently (sage 4.3.1 I guess) was like
>
> > I tried all the examples you give below in Sage-4.3.2 and they all
> > worked fine, and not as you report.
>
> That's irritating. I am using the binaries for OpenSUSE 11.1 and just
> to make sure, I downloaded them again, checked the MD5-sum, but still
> with the same results/errors as described.
>
> Maybe, I'll just wait for the next release. Or see if I can reproduce
> the errors on the online notebook. But I have to go for now.
>
> Thanks, again,
>
> Konstantin
>
> > > S = PolynomialRing(QQ, 'x, y')
> > > g = S.random_element(degree = 3)
> > > g.coeff(x^2)
>
> > > and now returns
>
> > > AttributeError:
> > > 'sage.rings.polynomial.multi_polynomial_libsingular.MPolynomial_libsingular'
> > > object has no attribute 'coeff'
>
> > > Again, there seems to be a workaround using g.coefficient(), but I am
> > > unable handle this method even with the documentation provided, e.g.
> > > for
>
> > > g = 2*x*y^2 - 2*y^3 + x^2 + 3*y^2 - 4
>
> > > g.coefficient({x:0, y:0}) == g
> > > g.coefficient({x:1, y:2}) == g
> > > g.coefficient({x:2, y:2}) == g
>
> > > are all true?! And
>
> > > g.coefficient(x^2)
>
> > > returns the error
>
> > > TypeError: The input degrees must be a dictionary of variables to
> > > exponents.
>
> > > although the documentation has as an example
>
> > > sage: R.<x,y> = QQ[]
> > > sage: f=(1+y+y^2)*(1+x+x^2)
> > > sage: f.coefficient({x:0})
> > > y^2 + y + 1
> > > sage: f.coefficient([0,None])
> > > y^2 + y + 1
> > > sage: f.coefficient(x)
> > > y^2 + y + 1
>
> > > Am I missing something here?
>
> > > Thanks,
> > > Konstantin
--
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org