Skip to content

Commit

Permalink
Trac #23166: Conversion from a Function Field to its underlying Polyn…
Browse files Browse the repository at this point in the history
…omial Ring

{{{
sage: K.<x> = FunctionField(QQ)
sage: K._ring(x)
Traceback:
...
ValueError: only constants can be converted into the constant base field
but x is not a constant
}}}

URL: https://trac.sagemath.org/23166
Reported by: saraedum
Ticket author(s): David Roe
Reviewer(s): Julian Rüth
  • Loading branch information
Release Manager authored and vbraun committed Jun 10, 2017
2 parents fadc6fe + 3d74661 commit 554fe30
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/sage/rings/function_field/function_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -1427,6 +1427,9 @@ def __init__(self, constant_field, names,
self._ring = R
self._field = R.fraction_field()
self._populate_coercion_lists_(coerce_list=[self._field])
from sage.categories.sets_with_partial_maps import SetsWithPartialMaps
from sage.categories.morphism import SetMorphism
R.register_conversion(SetMorphism(self.Hom(R, SetsWithPartialMaps()), self._to_polynomial))
self._gen = self(R.gen())

def __reduce__(self):
Expand Down Expand Up @@ -1562,6 +1565,25 @@ def _to_constant_base_field(self, f):
return K(f.numerator()) / K(f.denominator())
raise ValueError("only constants can be converted into the constant base field but %r is not a constant"%(f,))

def _to_polynomial(self, f):
"""
If ``f`` is integral, return it as a polynomial.
INPUT:
- ``f`` -- an element of this rational function field whose denominator is a constant.
EXAMPLES::
sage: K.<x> = FunctionField(QQ)
sage: K._ring(x) # indirect doctest
x
"""
K = f.parent().constant_base_field()
if f.denominator() in K:
return f.numerator()/K(f.denominator())
raise ValueError("Only polynomials can be converted to the underlying polynomial ring")

def _to_bivariate_polynomial(self, f):
"""
Convert ``f`` from a univariate polynomial over the rational function
Expand Down

0 comments on commit 554fe30

Please sign in to comment.