Ask Your Question

Polynomial becoming FractionFieldElement?

asked 2021-09-08 05:15:47 +0200

anonymous user


updated 2021-09-08 05:31:41 +0200

I have a polynomial Phi(x,y) over the finite field \F_{p^2}, and I tried to set the first variable to a constant and then divide it by (x - one of the roots) so I could use .roots() to find its other roots. The problem is that, when running the following lines,

f = Phi(x=current[mu]).univariate_polynomial()/(y - previous[mu])

roots = f.roots(multiplicities=False)

I get the following error:

AttributeError: 'sage.rings.fraction_field_element.FractionFieldElement' object has no attribute 'roots'

I set it up to print f before the line that causes the crash, and the value of f was a reasonable y^2 + y - 8. I don't know why this is being implicitly converted to a polynomial fraction, but I need to find its roots as a polynomial over a finite field.

edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted

answered 2021-09-12 09:44:51 +0200

slelievre gravatar image

If you know for sure that P is divisible by Q, you can use P // Q to get the quotient in the ring where P and Q live, rather than in the fraction field.

edit flag offensive delete link more

answered 2021-09-08 10:33:03 +0200

Emmanuel Charpentier gravatar image

By dividing two polynomials, you ask quite explicitly for an element of the fraction field of the polynomials' parent :

sage: R1.<t>=ZZ[]
sage: foo=(t-1)*(t-2)*(t-3) ; foo
t^3 - 6*t^2 + 11*t - 6
sage: foo.parent()
Univariate Polynomial Ring in t over Integer Ring
sage: foo/(t-2)
t^2 - 4*t + 3
sage: (foo/(t-2)).parent()
Fraction Field of Univariate Polynomial Ring in t over Integer Ring

If you need a polynomial, you can try the explicit conversion :

sage: R1(foo/(t-2)).parent()
Univariate Polynomial Ring in t over Integer Ring

... except that it will fail if the conversion is impossible (i. e. your divisor is not a (product of) $t-u$ monomial(s) where (all the) $u$(s) is (are) root(s) of the polynomial :

sage: foo/(t-4)
(t^3 - 6*t^2 + 11*t - 6)/(t - 4)

Note that the result is not simplified (it cannot be...).

sage: (foo/(t-4)).parent()
Fraction Field of Univariate Polynomial Ring in t over Integer Ring

as expected. Therefore :

sage: R1(foo/(t-24))
TypeError                                 Traceback (most recent call last)
<ipython-input-38-eda6314d7474> in <module>
----> 1 R1(foo/(t-Integer(24)))

/usr/local/sage-9/local/lib/python3.9/site-packages/sage/structure/parent.pyx in sage.structure.parent.Parent.__call__ (build/cythonized/sage/structure/parent.c:9351)()
    896         if mor is not None:
    897             if no_extra_args:
--> 898                 return mor._call_(x)
    899             else:
    900                 return mor._call_with_args(x, args, kwds)

/usr/local/sage-9/local/lib/python3.9/site-packages/sage/categories/map.pyx in (build/cythonized/sage/categories/map.c:7089)()
    788         return self._call_with_args(x, args, kwds)
--> 790     cpdef Element _call_(self, x):
    791         """
    792         Call method with a single argument, not implemented in the base class.

/usr/local/sage-9/local/lib/python3.9/site-packages/sage/rings/ in _call_(self, x, check)
   1240             # However, too much existing code is expecting this to throw a
   1241             # TypeError, so we decided to keep it for the time being.
-> 1242             raise TypeError("fraction must have unit denominator")
   1243         return num * den.inverse_of_unit()

TypeError: fraction must have unit denominator

You can also try the euclidean division :

sage: q, r = foo.quo_rem(t-4) ; (q, r)
(t^2 - 2*t + 3, 6)
sage: q.parent()
Univariate Polynomial Ring in t over Integer Ring

but be damn sure to check that r is zero !


edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2021-09-08 05:15:47 +0200

Seen: 73 times

Last updated: Sep 12