Ticket #8997: trac_8997-riemann-roch.patch

File trac_8997-riemann-roch.patch, 6.9 KB (added by wdj, 12 years ago)

apply to 4.4.2

  • sage/schemes/plane_curves/projective_curve.py

    # HG changeset patch
    # User David Joyner <wdjoyner@gmail.com>
    # Date 1274899861 14400
    # Node ID 1f36cec4263025c14226d07688a81e9d0c1062b0
    # Parent  1451c00a8d44f78f01cb0dc22ebb7464cc6ad0e2
    added docstrings and fixed singular;s random seed - wdj
    
    diff -r 1451c00a8d44 -r 1f36cec42630 sage/schemes/plane_curves/projective_curve.py
    a b  
    101101            sage: C.divisor_of_function(r)     # todo: not implemented  !!!!
    102102            [[-3, (0, 0, 1)]]
    103103        """
     104        singular.eval('system("random", 0);')
    104105        F = self.base_ring()
    105106        f = self.defining_polynomial()
    106107        x, y, z = f.parent().gens()
     
    145146            sage: C.local_coordinates(pt,9)     # todo: not implemented  !!!!
    146147                  [2 + t, 3 + 3*t^2 + t^3 + 3*t^4 + 3*t^6 + 3*t^7 + t^8 + 2*t^9 + 3*t^11 + 3*t^12]
    147148        """
    148        
     149        singular.eval('system("random", 0);')       
    149150        f = self.defining_polynomial()
    150151        R = f.parent()
    151152        F = self.base_ring()
     
    471472            [(0 : 0 : 1), (0 : 1 : 0), (1 : 0 : 0)]
    472473
    473474        """
     475        singular.eval('system("random", 0);')
    474476        points = list(self.rational_points_iterator())
    475477        if sort:
    476478            points.sort()
     
    508510           'bn' algorithm. When it fails a RuntimeError exception is
    509511           raised.
    510512        """
     513        singular.eval('system("random", 0);')
    511514        f = self.defining_polynomial()._singular_()
    512         singular = f.parent()
    513         singular.lib('brnoeth')
     515        sing = f.parent()
     516        sing.lib('brnoeth')
    514517        try:
    515518            X1 = f.Adj_div()
    516519        except (TypeError, RuntimeError), s:
    517520            raise RuntimeError, str(s) + "\n\n ** Unable to use the Brill-Noether Singular package to compute all points (see above)."
    518521
    519         X2 = singular.NSplaces(1, X1)
    520         X3 = singular.extcurve(1, X2)
     522        X2 = sing.NSplaces(1, X1)
     523        X3 = sing.extcurve(1, X2)
    521524        R = X3[1][5]
    522         singular.set_ring(R)
     525        sing.set_ring(R)
    523526
    524527        # We use sage_flattened_str_list since iterating through
    525528        # the entire list through the sage/singular interface directly
    526529        # would involve hundreds of calls to singular, and timing issues with
    527530        # the expect interface could crop up.  Also, this is vastly
    528531        # faster (and more robust).
    529         v = singular('POINTS').sage_flattened_str_list()
     532        v = sing('POINTS').sage_flattened_str_list()
    530533        pnts = [self(int(v[3*i]), int(v[3*i+1]), int(v[3*i+2])) for i in range(len(v)/3)]
    531534       
    532535       
     
    539542        Return a basis for the Riemann-Roch space corresponding to
    540543        `D`.
    541544       
    542         .. warning::
    543 
    544           This function calls a Singular function that
    545           appears to be very buggy and should not be trusted.
    546        
    547545        This uses Singular's Brill-Noether implementation.
    548546       
    549547        INPUT:
     
    556554       
    557555        EXAMPLE::
    558556       
     557            sage: R.<x,y,z> = GF(7)[]
     558            sage: f = x^7 - z^5*y^2 - z^6*x
     559            sage: C = Curve(f)
     560            sage: pts = C.rational_points(); pts
     561            [(0 : 0 : 1), (0 : 1 : 0), (1 : 0 : 1), (2 : 0 : 1), (3 : 0 : 1), (4 : 0 : 1), (5 : 0 : 1), (6 : 0 : 1)]
     562            sage: D = C.divisor([ (5, pts[0]) ])
     563            sage: B = C.riemann_roch_basis(D); len(B)
     564            3
     565            sage: R.<x,y,z> = GF(5)[]
     566            sage: f = x^7 + y^7 + z^7
     567            sage: C = Curve(f)  # genus 15
     568            sage: pts = C.rational_points(); pts
     569            [(0 : 4 : 1), (1 : 2 : 1), (2 : 1 : 1), (3 : 3 : 1), (4 : 0 : 1), (4 : 1 : 0)]
     570            sage: D = C.divisor([ (3, pts[0]), (-1,pts[2]), (10, pts[3]) ])
     571            sage: C.riemann_roch_basis(D)
     572            [(x + y)/(x + z), z/(x + z)]
    559573            sage: R.<x,y,z> = GF(2)[]
    560574            sage: f = x^3*y + y^3*z + x*z^3
    561             sage: C = Curve(f); pts = C.rational_points()
     575            sage: C = Curve(f)
     576            sage: pts = C.rational_points(); pts
     577            [(0 : 0 : 1), (0 : 1 : 0), (1 : 0 : 0)]
     578            sage: C.genus()
     579            3
    562580            sage: D = C.divisor([ (4, pts[0]), (0,pts[1]), (4, pts[2]) ])
    563             sage: C.riemann_roch_basis(D)
     581            sage: C.riemann_roch_basis(D)  # dim=deg(D)-g+1, since deg(D)>2g-1
    564582            [x/y, 1, z/y, z^2/y^2, z/x, z^2/(x*y)]
    565        
    566         The following example illustrates that the Riemann-Roch space
    567         function in Singular doesn't *not* work correctly.
    568        
    569         ::
    570        
    571             sage: R.<x,y,z> = GF(5)[]
    572             sage: f = x^7 + y^7 + z^7
    573             sage: C = Curve(f); pts = C.rational_points()
    574             sage: D = C.divisor([ (3, pts[0]), (-1,pts[1]), (10, pts[5]) ])
    575             sage: C.riemann_roch_basis(D)    # output is random (!!!!)
    576             [x/(y + x), (z + y)/(y + x)]
    577        
    578         The answer has dimension 2 (confirmed via Magma). But it varies
    579         between 1 and quite large with Singular.
     583
    580584        """
     585        singular.eval('system("random", 0);')
    581586        f = self.defining_polynomial()._singular_()
    582         singular = f.parent()
    583         singular.lib('brnoeth')
     587        sing = f.parent()
     588        sing.lib('brnoeth')
    584589        try:
    585590            X1 = f.Adj_div()
    586591        except (TypeError, RuntimeError), s:
    587592            raise RuntimeError, str(s) + "\n\n ** Unable to use the Brill-Noether Singular package to compute all points (see above)."
    588593
    589         X2 = singular.NSplaces(1, X1)
    590         X3 = singular.extcurve(1, X2)
     594        X2 = sing.NSplaces(1, X1)
     595        X3 = sing.extcurve(1, X2)
    591596        R = X3[1][5]
    592         singular.set_ring(R)
     597        sing.set_ring(R)
    593598
    594599        # We use sage_flattened_str_list since iterating through
    595600        # the entire list through the sage/singular interface directly
    596601        # would involve hundreds of calls to singular, and timing issues with
    597602        # the expect interface could crop up.  Also, this is vastly
    598603        # faster (and more robust).
    599         v = singular('POINTS').sage_flattened_str_list()
     604        v = sing('POINTS').sage_flattened_str_list()
    600605        pnts = [self(int(v[3*i]), int(v[3*i+1]), int(v[3*i+2])) for i in range(len(v)/3)]
    601606        Dsupport = D.support()
    602607        Dcoeffs = []
    603608        for x in pnts:
    604609            Dcoeffs.append(D.coeff(x))
    605610        Dstr = str(tuple(Dcoeffs))
    606         G = singular(','.join([str(x) for x in Dcoeffs]), type='intvec')
     611        G = sing(','.join([str(x) for x in Dcoeffs]), type='intvec')
    607612        T = X2[1][2]
    608613        T.set_ring()
    609614        LG = G.BrillNoether(X2)
     
    643648           'bn' algorithm. When it fails a RuntimeError exception is
    644649           raised.
    645650        """
     651        singular.eval('system("random", 0);')
    646652        if algorithm == "enum":
    647653
    648654            return ProjectiveCurve_finite_field.rational_points(self, algorithm="enum", sort=sort)