Skip to content

Commit

Permalink
Trac #27471: py3:fix last doctest in affine_curve.py
Browse files Browse the repository at this point in the history
by cleaning up the code

URL: https://trac.sagemath.org/27471
Reported by: chapoton
Ticket author(s): Frédéric Chapoton
Reviewer(s): Travis Scrimshaw
  • Loading branch information
Release Manager authored and vbraun committed Mar 14, 2019
2 parents 5fab23b + 052ae75 commit c26f30d
Showing 1 changed file with 26 additions and 39 deletions.
65 changes: 26 additions & 39 deletions src/sage/schemes/curves/affine_curve.py
Expand Up @@ -98,11 +98,11 @@ def __init__(self, A, X):
Affine Curve over Finite Field of size 7 defined by x^2 - z, -x + z
"""
if not is_AffineSpace(A):
raise TypeError("A (=%s) must be an affine space"%A)
raise TypeError("A (=%s) must be an affine space" % A)
Curve_generic.__init__(self, A, X)
d = self.dimension()
if d != 1:
raise ValueError("defining equations (=%s) define a scheme of dimension %s != 1"%(X,d))
raise ValueError("defining equations (=%s) define a scheme of dimension %s != 1" % (X, d))

def projective_closure(self, i=0, PP=None):
r"""
Expand Down Expand Up @@ -278,14 +278,14 @@ def projection(self, indices, AS=None):
if self.base_ring() not in Fields():
raise TypeError("this curve must be defined over a field")
if len(indices) < 2 or len(indices) >= n:
raise ValueError("(=%s) must be a list or tuple of length between 2 and (=%s), inclusive"%(indices,n - 1))
raise ValueError("(=%s) must be a list or tuple of length between 2 and (=%s), inclusive" % (indices, n - 1))
if len(set(indices)) < len(indices):
raise ValueError("(=%s) must be a list or tuple of distinct indices or variables"%indices)
raise ValueError("(=%s) must be a list or tuple of distinct indices or variables" % indices)
if not AS is None:
if not is_AffineSpace(AS):
raise TypeError("(=%s) must be an affine space"%AS)
raise TypeError("(=%s) must be an affine space" % AS)
if AS.dimension_relative() != len(indices):
raise TypeError("(=%s) must have dimension (=%s)"%(AS, len(indices)))
raise TypeError("(=%s) must have dimension (=%s)" % (AS, len(indices)))
if AS.base_ring() != AA.base_ring():
raise TypeError("(=%s) must be defined over the same base field as this curve" % AS)
indices = list(indices)
Expand Down Expand Up @@ -566,7 +566,7 @@ def blowup(self, P=None):
try:
self(P)
except TypeError:
raise TypeError("(=%s) must be a point on this curve"%P)
raise TypeError("(=%s) must be a point on this curve" % P)
if not self.base_ring() in Fields():
raise TypeError("the base ring of this curve must be a field")
if not self.is_irreducible():
Expand Down Expand Up @@ -951,7 +951,7 @@ def __init__(self, A, f):
by x^2 + y^2
"""
if not (is_AffineSpace(A) and A.dimension != 2):
raise TypeError("Argument A (= %s) must be an affine plane."%A)
raise TypeError("Argument A (= %s) must be an affine plane." % A)
Curve_generic.__init__(self, A, [f])

def _repr_type(self):
Expand Down Expand Up @@ -1063,9 +1063,9 @@ def local_coordinates(self, pt, n):
S = singular
S.eval('ring s = '+str(p)+','+str(R0.gens())+',lp;')
S.eval('poly f = '+str(ft) + ';')
c = S('coeffs(%s, t)'%ft)
c = S('coeffs(%s, t)' % ft)
N = int(c.size())
b = ["%s[%s,1],"%(c.name(), i) for i in range(2,N//2-4)]
b = ["%s[%s,1]," % (c.name(), i) for i in range(2,N//2-4)]
b = ''.join(b)
b = b[:len(b)-1] # to cut off the trailing comma
cmd = 'ideal I = '+b
Expand Down Expand Up @@ -1182,7 +1182,7 @@ def is_transverse(self, C, P):
True
"""
if not self.intersects_at(C, P):
raise TypeError("(=%s) must be a point in the intersection of (=%s) and this curve"%(P,C))
raise TypeError("(=%s) must be a point in the intersection of (=%s) and this curve" % (P, C))
if self.is_singular(P) or C.is_singular(P):
return False

Expand Down Expand Up @@ -1247,7 +1247,7 @@ def multiplicity(self, P):
try:
P = self(P)
except TypeError:
raise TypeError("(=%s) is not a point on (=%s)"%(P,self))
raise TypeError("(=%s) is not a point on (=%s)" % (P, self))

# Apply a linear change of coordinates to self so that P becomes (0,0)
AA = self.ambient_space()
Expand Down Expand Up @@ -1407,7 +1407,7 @@ def is_ordinary_singularity(self, P):
"""
r = self.multiplicity(P)
if r < 2:
raise TypeError("(=%s) is not a singular point of (=%s)"%(P,self))
raise TypeError("(=%s) is not a singular point of (=%s)" % (P,self))

T = self.tangents(P, factor=False)[0]
vars = self.ambient_space().gens()
Expand Down Expand Up @@ -1607,35 +1607,22 @@ def riemann_roch_basis(self, D):
sage: C = Curve(f)
sage: D = [6,0,0,0,0,0]
sage: C.riemann_roch_basis(D)
[1, (y^2*z^4 - x*z^5)/x^6, (y^2*z^5 - x*z^6)/x^7, (y^2*z^6 - x*z^7)/x^8]
[1, (-x*z^5 + y^2*z^4)/x^6, (-x*z^6 + y^2*z^5)/x^7, (-x*z^7 + y^2*z^6)/x^8]
"""
f = self.defining_polynomial()
R = f.parent()
F = self.base_ring()
p = F.characteristic()
gens = f.parent().gens()
p = self.base_ring().characteristic()
G = singular(','.join(str(x) for x in D), type='intvec')

singular.LIB('brnoeth.lib')
singular.lib('brnoeth')
singular.ring(p, gens, 'lp')

S = singular.ring(p, R.gens(), 'lp')
fsing = singular(str(f))

X = fsing.Adj_div()
X = singular(f).Adj_div()
P = singular.NSplaces(1, X)
T = P[1][2]
T.set_ring()

LG = G.BrillNoether(P)

dim = len(LG)
basis = [(LG[i][1], LG[i][2]) for i in range(1,dim+1)]
x, y, z = PolynomialRing(F, 3, names = ["x","y","z"]).gens()
V = []
for g in basis:
T.set_ring() # necessary...
V.append(eval(g[0].sage_polystring())/eval(g[1].sage_polystring()))
return V
T.set_ring() # necessary

return [g[1].sage() / g[2].sage() for g in G.BrillNoether(P)]

def rational_points(self, algorithm="enum"):
r"""
Expand Down Expand Up @@ -1705,18 +1692,18 @@ def rational_points(self, algorithm="enum"):
# with the expect interface could crop up. Also, this is vastly
# faster (and more robust).
v = singular('POINTS').sage_flattened_str_list()
pnts = [self(int(v[3*i]), int(v[3*i+1])) for i in range(len(v)//3) if int(v[3*i+2])!=0]
pnts = [self(int(v[3*i]), int(v[3*i+1]))
for i in range(len(v)//3) if int(v[3*i+2])]
# remove multiple points
pnts = sorted(set(pnts))
return pnts
return sorted(set(pnts))

elif algorithm == "all":

S_enum = self.rational_points(algorithm = "enum")
S_bn = self.rational_points(algorithm = "bn")
if S_enum != S_bn:
raise RuntimeError("Bug in rational_points -- different algorithms give different answers for curve %s!"%self)
raise RuntimeError("Bug in rational_points -- different algorithms give different answers for curve %s!" % self)
return S_enum

else:
raise ValueError("No algorithm '%s' known"%algorithm)
raise ValueError("No algorithm '%s' known" % algorithm)

0 comments on commit c26f30d

Please sign in to comment.