# Absolute value of a polynomial Anonymous

How can I generate a random polynomial with two variables x, y of fix degree which is not of type : <type 'sage.rings.polynomial.multi_polynomial_libsingular.MPolynomial_libsingular' ?

I would like to compute the absolute value of this polynomial, but when I generate it using : R = ZZ['x','y']; F = R.random_element(4, 1000)

for example, I get : TypeError: bad operand type for abs(): 'sage.rings.polynomial.multi_polynomial_libsingular.MPolynomial_libsingular'

What would be a good alternative to get |F(x,y)| ? Thanks

edit retag close merge delete

Sort by » oldest newest most voted

You can turn your polynomial into a symbolic expression, then it is possible to take its absolute value:

sage: f = SR(F) ; f
-x^3*y - x^2*y^2 + x*y^3 + y^4 - x^3 - 3*x^2*y + 9*x*y^2 + 2*y^3 + x^2 - x*y + 3*x + 2*y + 1
sage: g = abs(f) ; g
abs(-x^3*y - x^2*y^2 + x*y^3 + y^4 - x^3 - 3*x^2*y + 9*x*y^2 + 2*y^3 + x^2 - x*y + 3*x + 2*y + 1)
sage: g.parent()
Symbolic Ring
sage: g(x=2,y=3)
258

more