6.4 Another Approach

There is also a more python-like interface to Singular. Using this the code is much simpler, as illustrated below. First we demonstrate computing the places on a curve in a particular case.

sage: singular.lib('brnoeth.lib')
sage: R = singular.ring(5, '(x,y)', 'lp')
sage: f = singular.new('y^2 - x^9 - x')
sage: X1 = f.Adj_div()
sage: X2 = singular.NSplaces(1, X1)
sage: X3 = singular.extcurve(1, X2)
sage: R = X3[1][5]
sage: singular.set_ring(R)
sage: L = singular.new('POINTS')
sage: [(L[i][1], L[i][2], L[i][3]) for i in range(1,7)]
      [(0, 1, 0), (-2, 1, 1), (0, 0, 1), (2, 2, 1), (-2, -1, 1), (2, -2, 1)]
The name method of a Singular object returns the name of that object in the Singular interpreter, so that it can be used as input to a Singular function.

Next we implement the general function (we omit the docstring, which is the same as above). Note that the point_parser function is not required.

def places_on_curve(f,F):
    p = F.characteristic()
    if F.degree() > 1:
        raise NotImplementedError
    singular.lib('brnoeth.lib')
    R = singular.ring(5, '(x,y)', 'lp')
    f = singular.new('y^2 - x^9 - x')
    X1 = f.Adj_div()
    X2 = singular.NSplaces(1, X1)
    X3 = singular.extcurve(1, X2)
    R = X3[1][5]
    singular.setring(R)
    L = singular.new('POINTS')
    return [(int(L[i][1]), int(L[i][2]), int(L[i][3])) \
             for i in range(1,int(L.size())+1)]

This code is much shorter, nice, and more readable. However, it depends on certain functions, e.g., singular.setring having been implemented in the Sage/Singular interface, whereas the code in the previous section used only the barest minimum of that interface.

See About this document... for information on suggesting changes.