1 | initial version |
As a workaround, evaluate a rational function at zero to get its constant term as a number field element.
Below some musings around the question, including the workaround already suggested in the question.
Define the number field, the polynomial ring, and the field of rational functions:
sage: x = polygen(ZZ)
sage: F.<u> = NumberField(x^2 - 3)
sage: R.<y> = PolynomialRing(F)
sage: Q = R.fraction_field()
A constant rational function:
sage: a = Q(2*u)
sage: a
2*u
Membership tests, with one surprise:
sage: a in Q, a in R, a in F
(True, True, False)
Forcing a
into F
does not work:
sage: F(a)
Traceback (most recent call last)
...
TypeError: unable to convert 2*u to Number Field in u with defining polynomial x^2 - 3
Going through the polynomial ring:
sage: b = R(a)
sage: b
2*u
sage: b in Q, b in R, b in F
(True, True, True)
Evaluating at zero to get the constant term as a base field element:
sage: c = a(0)
sage: c
2*u
sage: c in Q, c in R, c in F
(True, True, True)