Skip to content
This repository was archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
py3: fix a doctest in multi_polynomial_element (refactoring)
Browse files Browse the repository at this point in the history
  • Loading branch information
fchapoton committed May 4, 2019
1 parent d765ee2 commit 0db6b0d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 47 deletions.
57 changes: 16 additions & 41 deletions src/sage/rings/polynomial/multi_polynomial_element.py
Original file line number Diff line number Diff line change
Expand Up @@ -2016,29 +2016,24 @@ def reduce(self, I):
# Useful for some geometry code.
###############################################################

def degree_lowest_rational_function(r,x):
def degree_lowest_rational_function(r, x):
r"""
INPUT:
Return the difference of valuations of r with respect to variable x.
- ``r`` - a multivariate rational function
INPUT:
- ``x`` - a multivariate polynomial ring generator x
- ``r`` -- a multivariate rational function
- ``x`` -- a multivariate polynomial ring generator x
OUTPUT:
- ``integer`` -- the difference val_x(p) - val_x(q) where r = p/q
- ``integer`` - the degree of r in x and its "leading"
(in the x-adic sense) coefficient.
.. NOTE::
.. note::
This function is dependent on the ordering of a python dict.
Thus, it isn't really mathematically well-defined. I think that
it should made a method of the FractionFieldElement class and
rewritten.
This function should be made a method of the
FractionFieldElement class.
EXAMPLES::
Expand All @@ -2057,35 +2052,15 @@ def degree_lowest_rational_function(r,x):
sage: r = f/g; r
(-b*c^2 + 2)/(a*b^3*c^6 - 2*a*c)
sage: degree_lowest_rational_function(r,a)
(-1, 3)
-1
sage: degree_lowest_rational_function(r,b)
(0, 4)
0
sage: degree_lowest_rational_function(r,c)
(-1, 4)
-1
"""
from sage.rings.fraction_field import FractionField
R = r.parent()
F = FractionField(R)
F = FractionField(r.parent())
r = F(r)
if r == 0:
return (0, F(0))
L = next(iter(x.dict()))
for ix in range(len(L)):
if L[ix] != 0:
break
f = r.numerator()
g = r.denominator()
M = f.dict()
keys = list(M)
numtermsf = len(M)
degreesf = [keys[j][ix] for j in range(numtermsf)]
lowdegf = min(degreesf)
cf = M[keys[degreesf.index(lowdegf)]] ## constant coeff of lowest degree term
M = g.dict()
keys = list(M)
numtermsg = len(M)
degreesg = [keys[j][ix] for j in range(numtermsg)]
lowdegg = min(degreesg)
cg = M[keys[degreesg.index(lowdegg)]] ## constant coeff of lowest degree term
return (lowdegf-lowdegg,cf/cg)

f = r.numerator().polynomial(x)
g = r.denominator().polynomial(x)
return f.valuation() - g.valuation()
8 changes: 4 additions & 4 deletions src/sage/schemes/curves/affine_curve.py
Original file line number Diff line number Diff line change
Expand Up @@ -1011,16 +1011,16 @@ def divisor_of_function(self, r):
yt = lcs[1]
xt = lcs[0]
ldg = degree_lowest_rational_function(r(xt, yt), t)
if ldg[0] != 0:
divf.append([ldg[0], pt0])
if ldg != 0:
divf.append([ldg, pt0])
return divf

def local_coordinates(self, pt, n):
r"""
Return local coordinates to precision n at the given point.
Behaviour is flaky - some choices of `n` are worst that
others.
Behaviour is flaky - some choices of `n` are worst that
others.
INPUT:
Expand Down
4 changes: 2 additions & 2 deletions src/sage/schemes/curves/projective_curve.py
Original file line number Diff line number Diff line change
Expand Up @@ -618,8 +618,8 @@ def divisor_of_function(self, r):
# What is the '5' in this line and the 'r()' in the next???
lcs = self.local_coordinates(P,5)
ldg = degree_lowest_rational_function(r(lcs[0],lcs[1]),z)
if ldg[0] != 0:
divf.append([ldg[0],P])
if ldg != 0:
divf.append([ldg, P])
return divf


Expand Down

0 comments on commit 0db6b0d

Please sign in to comment.