Ticket #9337: trac_9337_final.patch

File trac_9337_final.patch, 48.7 KB (added by vbraun, 3 years ago)

Updated patch

  • sage/geometry/polyhedra.py

    # HG changeset patch
    # User Volker Braun <vbraun@stp.dias.ie>
    # Date 1284031305 -3600
    # Node ID 448d739f20e7837687f8c2b22f717bfe0c093f4f
    # Parent  3e8a10545e10b7f34ac53ec7976ea8aa581ca132
    Trac 9337: The (hopefully) final patch.
    
      * Polyhedron can now determine integral points in not necessarily integral polytopes.
      * Used this to extend cohomology computation to reflexive sheaves.
      * Renamed ToricDivisor.polytope() to polyhedron() since its not a lattice polytope in general.
      * Documentation added to cohomology algorithm.
      * Output of ToricDivisor.cohomology() is now analogous to the output of SimplicialComplex.homology()
      * renamed ToricVariety.divisor_class_group() to rational_class_group()
      * added ToricDivisor.cohomology_support()
      * Change to FormalSum to first reduce then check types instead of the other way round
      * bugfixes to toric code
    
    diff -r 3e8a10545e10 -r 448d739f20e7 sage/geometry/polyhedra.py
    a b  
    119119from sage.rings.real_double import RDF 
    120120from sage.modules.free_module_element import vector 
    121121from sage.matrix.constructor import matrix, identity_matrix 
    122 from sage.functions.other import sqrt 
     122from sage.functions.other import sqrt, floor, ceil 
    123123from sage.functions.trig import sin, cos 
    124124 
    125125from sage.plot.all import point2d, line2d, arrow, polygon2d 
     
    36323632 
    36333633        return True 
    36343634 
    3635  
     3635    def is_lattice_polytope(self): 
     3636        r""" 
     3637        Return whether the polyhedron is a lattice polytope. 
     3638         
     3639        OUTPUT: 
     3640 
     3641        ``True`` if the polyhedron is compact and has only integral 
     3642        vertices, ``False`` otherwise. 
     3643         
     3644        EXAMPLES:: 
     3645         
     3646            sage: polytopes.cross_polytope(3).is_lattice_polytope() 
     3647            True 
     3648            sage: polytopes.regular_polygon(5).is_lattice_polytope() 
     3649            False 
     3650        """ 
     3651        try:  
     3652            return self._is_lattice_polytope 
     3653        except AttributeError: 
     3654            pass 
     3655 
     3656        self._is_lattice_polytope = False 
     3657        if self.is_compact(): 
     3658            try: 
     3659                matrix(ZZ, self.vertices()) 
     3660                self._is_lattice_polytope = True 
     3661            except TypeError: 
     3662                pass 
     3663         
     3664        return self._is_lattice_polytope 
     3665         
     3666    def lattice_polytope(self, envelope=False): 
     3667        r""" 
     3668        Return an encompassing lattice polytope. 
     3669         
     3670        INPUT: 
     3671 
     3672        - ``envelope`` -- boolean (default: ``False``). If the 
     3673          polyhedron has non-integral vertices, this option decides 
     3674          whether to return a strictly larger lattice polytope or 
     3675          raise a ``ValueError``. This option has no effect if the 
     3676          polyhedron has already integral vertices. 
     3677 
     3678        OUTPUT: 
     3679 
     3680        A :class:`LatticePolytope 
     3681        <sage.geometry.lattice_polytope.LatticePolytopeClass>`. If the 
     3682        polyhedron is compact and has integral vertices, the lattice 
     3683        polytope equals the polyhedron. If the polyhedron is compact 
     3684        but has at least one non-integral vertex, a strictly larger 
     3685        lattice polytope is returned.  
     3686 
     3687        If the polyhedron is not compact, a ``NotImplementedError`` is 
     3688        raised. 
     3689 
     3690        If the polyhedron is not integral and ``envelope=False``, a 
     3691        ``ValueError`` is raised. 
     3692 
     3693        ALGORITHM: 
     3694 
     3695        For each non-integral vertex, a bounding box of integral 
     3696        points is added and the convex hull of these integral points 
     3697        is returned. 
     3698 
     3699        EXAMPLES: 
     3700         
     3701        First, a polyhedron with integral vertices:: 
     3702 
     3703            sage: P = Polyhedron( vertices = [(1, 0), (0, 1), (-1, 0), (0, -1)]) 
     3704            sage: lp = P.lattice_polytope(); lp 
     3705            A lattice polytope: 2-dimensional, 4 vertices. 
     3706            sage: lp.vertices() 
     3707            [ 1  0 -1  0] 
     3708            [ 0  1  0 -1] 
     3709 
     3710        Here is a polyhedron with non-integral vertices:: 
     3711 
     3712            sage: P = Polyhedron( vertices = [(1/2, 1/2), (0, 1), (-1, 0), (0, -1)]) 
     3713            sage: lp = P.lattice_polytope() 
     3714            Traceback (most recent call last): 
     3715            ... 
     3716            ValueError: Some vertices are not integral. You probably want  
     3717            to add the argument "envelope=True" to compute an enveloping  
     3718            lattice polytope. 
     3719            sage: lp = P.lattice_polytope(True); lp 
     3720            A lattice polytope: 2-dimensional, 5 vertices. 
     3721            sage: lp.vertices() 
     3722            [ 0  1  1 -1  0] 
     3723            [ 1  0  1  0 -1] 
     3724        """ 
     3725        if not self.is_compact(): 
     3726            raise NotImplementedError, 'Only compact lattice polytopes are allowed.' 
     3727 
     3728        def nonintegral_error(): 
     3729            raise ValueError, 'Some vertices are not integral. '+\ 
     3730                'You probably want to add the argument '+\ 
     3731                '"envelope=True" to compute an enveloping lattice polytope.'  
     3732 
     3733        # try to make use of cached values, if possible 
     3734        if envelope: 
     3735            try:  
     3736                return self._lattice_polytope 
     3737            except AttributeError: 
     3738                pass 
     3739        else: 
     3740            try:  
     3741                assert self._is_lattice_polytope 
     3742                return self._lattice_polytope 
     3743            except AttributeError: 
     3744                pass 
     3745            except AssertionError: 
     3746                nonintegral_error() 
     3747 
     3748        # find the integral vertices 
     3749        try: 
     3750            vertices = matrix(ZZ, self.vertices()).transpose() 
     3751            self._is_lattice_polytope = True 
     3752        except TypeError: 
     3753            self._is_lattice_polytope = False 
     3754            if envelope==False: nonintegral_error() 
     3755            vertices = [] 
     3756            from sage.combinat.cartesian_product import CartesianProduct 
     3757            for v in self.vertex_generator(): 
     3758                vbox = [ set([floor(x),ceil(x)]) for x in v ] 
     3759                vertices.extend( CartesianProduct(*vbox) ) 
     3760            vertices = matrix(ZZ, vertices).transpose() 
     3761 
     3762        # construct the (enveloping) lattice polytope 
     3763        from sage.geometry.lattice_polytope import LatticePolytope 
     3764        self._lattice_polytope = LatticePolytope(vertices) 
     3765        return self._lattice_polytope 
     3766 
     3767    def integral_points(self): 
     3768        r""" 
     3769        Return the integral points in the polyhedron. 
     3770 
     3771        OUTPUT: 
     3772         
     3773        The list of integral points in the polyhedron. If the 
     3774        polyhedron is not compact, a ``ValueError`` is raised. 
     3775 
     3776        EXAMPLES:: 
     3777         
     3778            sage: Polyhedron(vertices=[(-1,-1),(1,0),(1,1),(0,1)]).integral_points() 
     3779            [(-1, -1), (1, 0), (1, 1), (0, 1), (0, 0)] 
     3780            sage: Polyhedron(vertices=[(-1/2,-1/2),(1,0),(1,1),(0,1)]).lattice_polytope(True).points() 
     3781            [ 0 -1 -1  1  1  0  0] 
     3782            [-1  0 -1  0  1  1  0] 
     3783            sage: Polyhedron(vertices=[(-1/2,-1/2),(1,0),(1,1),(0,1)]).integral_points() 
     3784            [(1, 0), (1, 1), (0, 1), (0, 0)] 
     3785        """ 
     3786        if not self.is_compact(): 
     3787            raise ValueError, 'Can only enumerate points in a compact polyhedron.' 
     3788 
     3789        lp = self.lattice_polytope(True) 
     3790 
     3791        if self.is_lattice_polytope(): 
     3792            return lp.points().columns() 
     3793 
     3794        points = filter(lambda p: self.contains(p),  
     3795                        lp.points().columns()) 
     3796        return points 
     3797             
    36363798 
    36373799############################################################# 
    36383800def cyclic_sort_vertices_2d(Vlist): 
     
    44094571                     for f in self.polygons ]) 
    44104572 
    44114573 
    4412  
    44134574######################################################################### 
    44144575class Polytopes(): 
    44154576    """ 
  • sage/schemes/generic/divisor.py

    diff -r 3e8a10545e10 -r 448d739f20e7 sage/schemes/generic/divisor.py
    a b  
    127127        Construct a :class:`Divisor_generic`. 
    128128 
    129129        INPUT: 
    130          
    131         See :meth:`sage.structure.formal_sum.FormalSum.__init__` 
     130 
     131        INPUT: 
     132 
     133        - ``v`` -- object. Usually a list of pairs 
     134          ``(coefficient,divisor)``. 
     135 
     136        - ``parent`` -- FormalSums(R) module (default: FormalSums(ZZ)) 
     137 
     138        - ``check`` -- bool (default: True). Whether to coerce 
     139          coefficients into base ring. Setting it to ``False`` can 
     140          speed up construction. 
     141 
     142        - ``reduce`` -- reduce (default: True). Whether to combine 
     143          common terms. Setting it to ``False`` can speed up 
     144          construction. 
     145 
     146        .. WARNING:: 
     147 
     148            The coefficients of the divisor must be in the base ring 
     149            and the terms must be reduced. If you set ``check=False`` 
     150            and/or ``reduce=False`` it is your responsibility to pass 
     151            a valid object ``v``. 
    132152         
    133153        EXAMPLES:: 
    134154         
  • sage/schemes/generic/toric_divisor.py

    diff -r 3e8a10545e10 -r 448d739f20e7 sage/schemes/generic/toric_divisor.py
    a b  
    7878**Picard group** `\mathop{\mathrm{Pic}}(X)`. We continue using del Pezzo 
    7979surface of degree 6 introduced above:: 
    8080 
    81     sage: Cl = dP6.divisor_class_group(); Cl 
     81    sage: Cl = dP6.rational_class_group(); Cl 
    8282    The toric rational divisor class group 
    8383    of a 2-d CPR-Fano toric variety covered by 6 affine patches 
    8484    sage: Cl.ngens() 
     
    134134   
    135135    sage: M = P2.fan().lattice().dual() 
    136136    sage: H.cohomology(deg=0, weight=M(-1,0)) 
     137    Vector space of dimension 1 over Rational Field 
     138    sage: _.dimension() 
    137139    1 
    138140 
    139141Here is a more complicated example with `h^1(dP_6, \mathcal{O}(D))=4` :: 
    140142 
    141143    sage: D = dP6.divisor([0, 0, -1, 0, 2, -1]) 
    142144    sage: D.cohomology() 
     145    {0: Vector space of dimension 0 over Rational Field,  
     146     1: Vector space of dimension 4 over Rational Field,  
     147     2: Vector space of dimension 0 over Rational Field} 
     148    sage: D.cohomology(dim=True) 
    143149    (0, 4, 0) 
     150 
     151AUTHORS: 
     152 
     153- Volker Braun, Andrey Novoseltsev (2010-09-07): initial version. 
    144154""" 
    145155 
    146156 
     
    157167from sage.structure.element import is_Vector 
    158168from sage.combinat.combination import Combinations 
    159169from sage.geometry.cone import is_Cone 
    160 from sage.geometry.lattice_polytope import LatticePolytope 
    161170from sage.geometry.polyhedra import Polyhedron 
    162171from sage.geometry.toric_lattice_element import is_ToricLatticeElement 
    163172from sage.homology.simplicial_complex import SimplicialComplex 
     
    407416 
    408417 
    409418#******************************************************** 
    410 def ToricDivisor(toric_variety, arg=None, ring=None, check=False, reduce=False): 
     419def ToricDivisor(toric_variety, arg=None, ring=None, check=True, reduce=True): 
    411420    r""" 
    412421    Construct a divisor of ``toric_variety``. 
    413422 
     
    437446      divisor group. If ``ring`` is not specified, a coefficient ring 
    438447      suitable for ``arg`` is derived. 
    439448 
    440     - for ``check`` and ``reduce`` see :meth:`ToricDivisor_generic`. 
     449    - ``check`` -- bool (default: True). Whether to coerce 
     450      coefficients into base ring. Setting it to ``False`` can speed 
     451      up construction. 
     452 
     453    - ``reduce`` -- reduce (default: True). Whether to combine common 
     454      terms. Setting it to ``False`` can speed up construction. 
     455 
     456    .. WARNING:: 
     457 
     458        The coefficients of the divisor must be in the base ring and 
     459        the terms must be reduced. If you set ``check=False`` and/or 
     460        ``reduce=False`` it is your responsibility to pass valid input 
     461        data ``arg``. 
    441462 
    442463    OUTPUT: 
    443464     
     
    466487        sage: N = dP6.fan().lattice() 
    467488        sage: ToricDivisor(dP6, N(1,1) ) 
    468489        V(w) 
     490 
     491    We attempt to guess the correct base ring:: 
     492 
     493        sage: ToricDivisor(dP6, [(1/2,u)]) 
     494        1/2*V(u) 
     495        sage: _.parent() 
     496        Group of toric QQ-Weil divisors on 2-d CPR-Fano toric variety covered by 6 affine patches 
     497        sage: ToricDivisor(dP6, [(1/2,u), (1/2,u)]) 
     498        V(u) 
     499        sage: _.parent() 
     500        Group of toric ZZ-Weil divisors on 2-d CPR-Fano toric variety covered by 6 affine patches 
     501        sage: ToricDivisor(dP6, [(u,u)]) 
     502        Traceback (most recent call last): 
     503        ... 
     504        TypeError: Cannot deduce coefficient ring for [(u, u)]! 
    469505    """ 
    470506    assert is_ToricVariety(toric_variety) 
     507 
     508    ##### First convert special arguments into lists  
     509    ##### of multiplicities or (multiplicity,coordinate) 
    471510    # Zero divisor 
    472511    if arg is None: 
    473512        arg = [] 
     513        check = False 
     514        reduce = False 
    474515    # Divisor by lattice point (corresponding to a ray) 
    475516    if is_ToricLatticeElement(arg): 
    476517        if arg not in toric_variety.fan().lattice(): 
     
    486527    # Divisor by a ray index 
    487528    if arg in ZZ: 
    488529        arg = [(1, toric_variety.gen(arg))] 
     530        check = True    # ensure that the 1 will be coerced into the coefficient ring 
     531        reduce = False 
    489532    # Divisor by monomial 
    490533    if arg in toric_variety.coordinate_ring(): 
    491534        if len(list(arg)) != 1: 
     
    498541            arg = list(arg) 
    499542        except TypeError: 
    500543            raise TypeError("%s does not define a divisor!" % arg) 
    501     # Now we have a list of multiplicities or pairs multiplicity-coordinate, 
    502     # if the coefficient ring was not given, try to use the most common ones. 
     544 
     545    ##### Now convert a list of multiplicities into pairs multiplicity-coordinate 
     546    try: 
     547        assert all(len(item)==2 for item in arg) 
     548    except (AssertionError, TypeError): 
     549        n_rays = toric_variety.fan().nrays()     
     550        assert len(arg)==n_rays, \ 
     551            'Argument list {0} is not of the required length {1}!' \ 
     552            .format(arg, n_rays) 
     553        arg = zip(arg, toric_variety.gens()) 
     554        reduce = False 
     555 
     556    ##### Now we must have a list of multiplicity-coordinate pairs 
     557    assert all(len(item)==2 for item in arg) 
    503558    if ring is None: 
     559        # if the coefficient ring was not given, try to use the most common ones. 
    504560        try: 
    505             return ToricDivisor(toric_variety, arg, ring=ZZ, 
    506                                 check=check, reduce=reduce) 
     561            TDiv = ToricDivisorGroup(toric_variety, base_ring=ZZ) 
     562            return ToricDivisor_generic(arg, TDiv,  
     563                                        check=True, reduce=reduce) 
    507564        except TypeError: 
    508565            pass 
    509566        try: 
    510             return ToricDivisor(toric_variety, arg, ring=QQ, 
    511                                 check=check, reduce=reduce) 
     567            TDiv = ToricDivisorGroup(toric_variety, base_ring=QQ) 
     568            return ToricDivisor_generic(arg, TDiv,  
     569                                        check=True, reduce=reduce) 
    512570        except TypeError: 
    513             raise TypeError("cannot deduce coefficient ring for %s!" % arg) 
    514     # The ring was given, if we are still here 
    515     n_rays = toric_variety.fan().nrays()     
    516     if len(arg) == n_rays and arg[0] in ring: 
    517         arg = zip(arg, toric_variety.gens()) 
    518     # Now we MUST have a LIST of multiplicity-coordinate pairs 
    519     try: 
    520         for i, pair in enumerate(arg): 
    521             pair = tuple(pair) 
    522             if len(pair) != 2 or pair[1] not in toric_variety.gens(): 
    523                 raise TypeError 
    524             arg[i] = (ring(pair[0]), pair[1]) 
    525     except TypeError: 
    526         raise TypeError("%s does not define a divisor!" % arg) 
     571            raise TypeError("Cannot deduce coefficient ring for %s!" % arg) 
    527572    TDiv = ToricDivisorGroup(toric_variety, ring) 
    528573    return ToricDivisor_generic(arg, TDiv, check, reduce) 
    529574 
     
    657702            variable = self.parent().scheme().gen(index) 
    658703        except TypeError: 
    659704            variable = x 
    660         total = self.base_ring().zero() 
     705 
    661706        for coeff, var in self: 
    662707            if var == variable: 
    663                 total += coeff 
    664         return total 
     708                return coeff 
     709        return self.base_ring().zero() 
    665710 
    666711    def function_value(self, point): 
    667712        r""" 
     
    896941    
    897942    def is_integral(self): 
    898943        r""" 
    899         Return whether the support function is integral on the rays. 
     944        Return whether the coefficients of the divisor are all integral. 
    900945 
    901946        EXAMPLES:: 
    902947         
     
    910955            sage: DQQ.is_integral() 
    911956            True 
    912957        """ 
    913         return all( self.function_value(r) in ZZ  
    914                     for r in self.parent().scheme().fan().rays() ) 
     958        return all( coeff in ZZ for coeff, variable in self ) 
    915959 
    916960    def move_away_from(self, cone): 
    917961        """ 
     
    10131057 
    10141058        Returns the class of the divisor in `\mathop{Cl}(X) 
    10151059        \otimes_\ZZ \QQ` as an instance of 
    1016         :class:`ToricRationalDivisorClass`.  
     1060        :class:`ToricRationalDivisorClassGroup`.  
    10171061 
    1018         EXAMPLE: 
     1062        EXAMPLES:: 
    10191063         
    10201064            sage: dP6 = toric_varieties.dP6() 
    10211065            sage: D = dP6.divisor(0) 
     
    10231067            Divisor class [1, 0, 0, 0] 
    10241068        """ 
    10251069        if '_divisor_class' not in self.__dict__: 
    1026             self._divisor_class = self.parent().scheme().divisor_class_group()(self) 
     1070            self._divisor_class = self.parent().scheme().rational_class_group()(self) 
    10271071        return self._divisor_class 
    10281072 
    10291073    def is_ample(self): 
     
    10401084              multiple is Cartier. We return wheher this associtated 
    10411085              divisor is ample, i.e. corresponds to an ample line bundle. 
    10421086 
    1043             * The ample cone is an open cone. 
     1087            * In the orbifold case, the ample cone is an open 
     1088              and full-dimensional cone in the rational divisor class 
     1089              group :class:`ToricRationalDivisorClassGroup`. 
     1090              
     1091            * If the variety has worse than orbifold singularities, 
     1092              the ample cone is a full-dimensional cone within the 
     1093              (not full-dimensional) subspace spanned by the Cartier 
     1094              divisors inside the rational (Weil) divisor class group, 
     1095              that is, :class:`ToricRationalDivisorClassGroup`. The 
     1096              ample cone is then relative open (open in this 
     1097              subspace). 
    10441098 
    10451099            * See also :meth:`is_nef`. 
    10461100 
     
    10581112            sage: (-K).is_ample() 
    10591113            True 
    10601114 
    1061         Example 6.1.3, 6.1.11, 6.1.17 from Cox/Little/Schenck:: 
     1115        Example 6.1.3, 6.1.11, 6.1.17 of [CLS]_:: 
    10621116 
    10631117            sage: fan = Fan(cones=[(0,1), (1,2), (2,3), (3,0)], 
    10641118            ...             rays=[(-1,2), (0,1), (1,0), (0,-1)]) 
     
    10721126            ...           if D(a,b).is_nef() ] 
    10731127            [(0, 0), (0, 1), (0, 2), (1, 0), 
    10741128             (1, 1), (1, 2), (2, 0), (2, 1), (2, 2)] 
     1129 
     1130        A (worse than orbifold) singular Fano threefold:: 
     1131             
     1132            sage: points = [(1,0,0),(0,1,0),(0,0,1),(-2,0,-1),(-2,-1,0),(-3,-1,-1),(1,1,1)] 
     1133            sage: facets = [[0,1,3],[0,1,6],[0,2,4],[0,2,6],[0,3,5],[0,4,5],[1,2,3,4,5,6]] 
     1134            sage: X = ToricVariety(Fan(cones=facets, rays=points)) 
     1135            sage: X.rational_class_group().dimension() 
     1136            4 
     1137            sage: X.Kaehler_cone().rays() 
     1138            (Divisor class [1, 0, 0, 0],) 
     1139            sage: antiK = -X.K() 
     1140            sage: antiK.divisor_class() 
     1141            Divisor class [2, 0, 0, 0] 
     1142            sage: antiK.is_ample() 
     1143            True 
    10751144        """ 
    10761145        try: 
    10771146            return self._is_ample 
     
    10791148            pass 
    10801149         
    10811150        assert self.is_QQ_Cartier(), 'The divisor must be QQ-Cartier.' 
    1082         self._is_ample = \ 
    1083             self.parent().scheme().Kaehler_cone().interior_contains( 
    1084                                                         self.divisor_class()) 
     1151        Kc = self.parent().scheme().Kaehler_cone() 
     1152        self._is_ample = Kc.relative_interior_contains(self.divisor_class()) 
    10851153        return self._is_ample 
    10861154 
    10871155    def is_nef(self): 
     
    11201188            sage: (-K).is_nef() 
    11211189            True 
    11221190 
    1123         Example 6.1.3, 6.1.11, 6.1.17 from Cox/Little/Schenck:: 
     1191        Example 6.1.3, 6.1.11, 6.1.17 of [CLS]_:: 
    11241192 
    11251193            sage: fan = Fan(cones=[(0,1), (1,2), (2,3), (3,0)], 
    11261194            ...             rays=[(-1,2), (0,1), (1,0), (0,-1)]) 
     
    11441212        self._is_nef = self.divisor_class() in self.parent().scheme().Kaehler_cone() 
    11451213        return self._is_nef 
    11461214    
    1147     def polytope(self): 
     1215    def polyhedron(self): 
    11481216        r"""  
    1149         Return the lattice polytope `P_D\subset M` associated to a nef 
    1150         Cartier divisor `D`. 
     1217        Return the polyhedron `P_D\subset M` associated to a toric 
     1218        divisor `D`. 
    11511219       
    11521220        OUTPUT: 
    11531221       
    1154         - If `P_D` is not empty, the corresponding :class:`LatticePolytope 
    1155           <sage.geometry.lattice_polytope.LatticePolytopeClass>` object. 
    1156  
    1157         - If `P_D` is empty this method returns ``None``. 
     1222        `P_D` as an instance of :class:`~sage.geometry.polyhedra.Polyhedron`. 
    11581223 
    11591224        EXAMPLES:: 
    11601225       
    11611226            sage: dP7 = toric_varieties.dP7() 
    11621227            sage: D = dP7.divisor(2) 
    1163             sage: D.polytope() 
    1164             A lattice polytope: 0-dimensional, 1 vertices. 
    1165             sage: _.vertices() 
    1166             [0] 
    1167             [0] 
     1228            sage: P_D = D.polyhedron(); P_D 
     1229            A 0-dimensional polyhedron in QQ^2 defined as the convex hull of 1 vertex. 
     1230            sage: P_D.Vrepresentation() 
     1231            [A vertex at (0, 0)] 
    11681232            sage: D.is_nef() 
    11691233            False 
    11701234            sage: dP7.integrate( D.ch() * dP7.Td() ) 
    11711235            1 
    1172             sage: (-dP7.K()).polytope() 
    1173             A lattice polytope: 2-dimensional, 5 vertices. 
    1174             sage: _.points() 
    1175             [ 1  0  1 -1 -1 -1  0  0] 
    1176             [-1  1  0  1 -1  0 -1  0] 
     1236            sage: P_antiK = (-dP7.K()).polyhedron(); P_antiK 
     1237            A 2-dimensional polyhedron in QQ^2 defined as the convex hull of 5 vertices. 
     1238            sage: P_antiK.Vrepresentation() 
     1239            [A vertex at (1, -1), A vertex at (0, 1), A vertex at (1, 0),  
     1240             A vertex at (-1, 1), A vertex at (-1, -1)] 
     1241            sage: P_antiK.integral_points() 
     1242            [(1, -1), (0, 1), (1, 0), (-1, 1), (-1, -1), (-1, 0), (0, -1), (0, 0)] 
    11771243 
    1178         Example 6.1.3, 6.1.11, 6.1.17 from Cox/Little/Schenck:: 
     1244        Example 6.1.3, 6.1.11, 6.1.17 of [CLS]_:: 
    11791245 
    11801246            sage: fan = Fan(cones=[(0,1), (1,2), (2,3), (3,0)], 
    11811247            ...             rays=[(-1,2), (0,1), (1,0), (0,-1)]) 
    11821248            sage: F2 = ToricVariety(fan,'u1, u2, u3, u4') 
    11831249            sage: D = F2.divisor(3) 
    1184             sage: D.polytope().vertices() 
    1185             [2 0 0] 
    1186             [1 1 0] 
     1250            sage: D.polyhedron().Vrepresentation() 
     1251            [A vertex at (2, 1), A vertex at (0, 1), A vertex at (0, 0)] 
    11871252            sage: Dprime = F2.divisor(1) + D 
    1188             sage: Dprime.polytope().vertices() 
    1189             [2 0 0] 
    1190             [1 1 0] 
     1253            sage: Dprime.polyhedron().Vrepresentation() 
     1254            [A vertex at (2, 1), A vertex at (0, 1), A vertex at (0, 0)] 
    11911255            sage: D.is_ample() 
    11921256            False 
    11931257            sage: D.is_nef() 
    11941258            True 
    11951259            sage: Dprime.is_nef() 
    11961260            False 
     1261 
     1262        A more complicated example where `P_D` is not a lattice polytope:: 
     1263 
     1264            sage: X = toric_varieties.BCdlOG_base() 
     1265            sage: antiK = -X.K() 
     1266            sage: P_D = antiK.polyhedron() 
     1267            sage: P_D 
     1268            A 3-dimensional polyhedron in QQ^3 defined as the convex hull of 8 vertices. 
     1269            sage: P_D.Vrepresentation() 
     1270            [A vertex at (1, -1, 0), A vertex at (1, 1, 1),  
     1271             A vertex at (1, -3, 1), A vertex at (-5, 1, 1),  
     1272             A vertex at (-5, -3, 1), A vertex at (1, 1, -1/2),  
     1273             A vertex at (1, 1/2, -1/2), A vertex at (-1, -1, 0)] 
     1274            sage: P_D.Hrepresentation() 
     1275            [An inequality (-1, 0, 0) x + 1 >= 0, An inequality (0, -1, 0) x + 1 >= 0,  
     1276             An inequality (0, 0, -1) x + 1 >= 0, An inequality (0, 1, 2) x + 1 >= 0,  
     1277             An inequality (0, 1, 3) x + 1 >= 0, An inequality (1, 0, 4) x + 1 >= 0] 
     1278            sage: P_D.integral_points() 
     1279            [(1, 1, 1), (1, -3, 1), (-5, 1, 1), (-5, -3, 1), (0, 1, 1),  
     1280             (-1, 1, 1), (-2, 1, 1), (-3, 1, 1), (-4, 1, 1), (1, 0, 1),  
     1281             (0, 0, 1), (-1, 0, 1), (-2, 0, 1), (-3, 0, 1), (-4, 0, 1),  
     1282             (-5, 0, 1), (1, -1, 1), (0, -1, 1), (-1, -1, 1), (-2, -1, 1),  
     1283             (-3, -1, 1), (-4, -1, 1), (-5, -1, 1), (1, -2, 1), (0, -2, 1),  
     1284             (-1, -2, 1), (-2, -2, 1), (-3, -2, 1), (-4, -2, 1), (-5, -2, 1),  
     1285             (0, -3, 1), (-1, -3, 1), (-2, -3, 1), (-3, -3, 1), (-4, -3, 1),  
     1286             (1, 1, 0), (0, 1, 0), (-1, 1, 0), (1, 0, 0), (0, 0, 0), (-1, 0, 0),  
     1287             (1, -1, 0), (0, -1, 0), (-1, -1, 0)] 
    11971288        """ 
    11981289        try:  
    1199             return self._polytope 
     1290            return self._polyhedron 
    12001291        except AttributeError: 
    12011292            pass 
    12021293 
    1203         X = self.parent().scheme() 
    1204         if not X.is_complete(): 
    1205             raise ValueError("%s is not complete!" % X) 
    1206         fan = X.fan() 
    1207          
     1294        fan = self.parent().scheme().fan() 
    12081295        divisor = vector(self) 
    12091296        ieqs = [ [divisor[i]] + list(fan.ray(i)) for i in range(fan.nrays()) ] 
    1210         P = Polyhedron(ieqs=ieqs) 
    1211  
    1212         if P.dim()==-1: 
    1213             self._polytope = None 
    1214         else: 
    1215             vertices = matrix(ZZ, P.vertices()).transpose() 
    1216             self._polytope = LatticePolytope(vertices) 
    1217         return self._polytope 
     1297        self._polyhedron = Polyhedron(ieqs=ieqs) 
     1298        return self._polyhedron 
    12181299 
    12191300    def sections(self): 
    12201301        """ 
     
    12501331            self._sections = () 
    12511332        else: 
    12521333            self._sections = tuple(M(m) 
    1253                                 for m in self.polytope().points().columns()) 
     1334                                   for m in self.polyhedron().integral_points()) 
    12541335        return self._sections 
    12551336       
    12561337    def sections_monomials(self): 
     
    12791360             
    12801361        From [CoxTutorial]_ page 38:: 
    12811362 
     1363            sage: from sage.geometry.lattice_polytope import LatticePolytope 
    12821364            sage: lp = LatticePolytope(matrix([[1,1,0,-1,0], [0,1,1,0,-1]])) 
    12831365            sage: lp 
    12841366            A lattice polytope: 2-dimensional, 5 vertices. 
     
    13141396        monomials in :meth:`ToricVariety.coordinate_ring 
    13151397        <sage.schemes.generic.toric_variety.ToricVariety_field.coordinate_ring>`. 
    13161398        Alternatively, the monomials can be described as `M`-lattice 
    1317         points in the polyhedron ``D.polytope()``. This method converts the 
    1318         points `m\in M` into homogeneous polynomials. 
     1399        points in the polyhedron ``D.polyhedron()``. This method 
     1400        converts the points `m\in M` into homogeneous polynomials. 
    13191401 
    13201402        EXAMPLES:: 
    13211403 
     
    14031485        HH = cplx.homology(base_ring=QQ, cohomology=True) 
    14041486        HH_list = [0]*(d+1) 
    14051487        for h in HH.iteritems(): 
     1488            if h[0]==d: 
     1489                assert(h[1].dimension()==0) 
     1490                continue 
    14061491            HH_list[ h[0]+1 ] = h[1].dimension() 
    14071492 
    14081493        return vector(ZZ, HH_list) 
     
    14131498 
    14141499        OUTPUT: 
    14151500 
    1416         A ``LatticePolytope`` object that contains all weights `m` 
    1417         for which the sheaf cohomology is *potentially* non-vanishing. 
     1501        A :class:`~sage.geometry.polyhedra.Polyhedron` object that 
     1502        contains all weights `m` for which the sheaf cohomology is 
     1503        *potentially* non-vanishing.  
     1504 
     1505        ALGORITHM: 
     1506 
     1507        See :meth:`cohomology` and note that every `d`-tuple 
     1508        (`d`=dimension of the variety) of rays determines one vertex 
     1509        in the chamber decomposition if none of the hyperplanes are 
     1510        parallel. 
    14181511 
    14191512        EXAMPLES:: 
    14201513 
     
    14251518            sage: D = -D0 + 2*D2 - D3 
    14261519            sage: supp = D._sheaf_cohomology_support() 
    14271520            sage: supp 
    1428             A lattice polytope: 2-dimensional, 4 vertices. 
    1429             sage: supp.vertices() 
    1430             [-1  0  0  3] 
    1431             [ 1  2 -1 -1] 
     1521            A 2-dimensional polyhedron in QQ^2 defined as the convex hull of 4 vertices. 
     1522            sage: supp.Vrepresentation() 
     1523            [A vertex at (-1, 1), A vertex at (0, 2), A vertex at (0, -1), A vertex at (3, -1)] 
    14321524        """ 
    14331525        X = self.parent().scheme() 
     1526        fan = X.fan() 
    14341527        if not X.is_complete(): 
    14351528            raise ValueError("%s is not complete, its cohomology is not " 
    14361529                             "finite-dimensional!" % X) 
    14371530        d = X.dimension()       
    14381531        chamber_vertices = [] 
    1439         for plist in Combinations(X.fan().rays(), d): 
    1440             A = matrix(ZZ, list(plist)) 
    1441             b = vector([ self.function_value(p) for p in plist ]) 
     1532        for pindexlist in Combinations(range(0,fan.nrays()), d): 
     1533            A = matrix(ZZ, [fan.ray(p) for p in pindexlist]) 
     1534            b = vector([ self.coefficient(p) for p in pindexlist ]) 
    14421535            try: 
    14431536                chamber_vertices.append(A.solve_right(-b)) 
    14441537            except ValueError: 
    14451538                pass 
    1446         # Some of the obtained points may be non-integral, so we cannot use 
    1447         # LatticePolytope constructor immediately 
    1448         chamber_vertices = Polyhedron(vertices=chamber_vertices).vertices() 
    1449         # Now we hope that we got vertices indeed and they are integral 
    1450         chamber_vertices = matrix(chamber_vertices).transpose() 
    1451         return LatticePolytope(chamber_vertices, compute_vertices=False) 
     1539        return Polyhedron(vertices=chamber_vertices) 
    14521540 
    1453     def cohomology(self, weight=None, deg=None): 
     1541    def cohomology(self, weight=None, deg=None, dim=False): 
    14541542        r"""  
    14551543        Return the cohomology of the line bundle associated to the 
    1456         Cartier divisor, or sheaf associated to the Weil divisor. 
     1544        Cartier divisor or reflexive sheaf associated to the Weil 
     1545        divisor. 
    14571546 
    14581547        .. NOTE:: 
    14591548 
     
    14661555 
    14671556        - ``deg`` -- (optional) the degree of the cohomology group. 
    14681557 
     1558        - ``dim`` -- boolean. If ``False`` (default), the cohomology 
     1559          groups are returned as vector spaces. If ``True``, only the 
     1560          dimension of the vector space(s) is returned. 
     1561 
    14691562        OUTPUT: 
    14701563       
    1471         The dimension of `H^\text{deg}(X,\mathcal{O}(D))_\text{weight}` (if 
    1472         ``deg`` is specified) or a vector of all such dimensions. If ``weight`` 
    1473         is not specified, return the sum of dimensions for all weights. 
     1564        The vector space `H^\text{deg}(X,\mathcal{O}(D))` (if ``deg`` 
     1565        is specified) or a dictionary ``{degree:cohomology(degree)}`` 
     1566        of all degrees between 0 and the dimension of the variety. 
     1567 
     1568        If ``weight`` is specified, return only the subspace 
     1569        `H^\text{deg}(X,\mathcal{O}(D))_\text{weight}` of the 
     1570        cohomology of the given weight. 
     1571 
     1572        If ``dim==True``, the dimension of the cohomology vector space 
     1573        is returned instead of actual vector space. Moreover, if 
     1574        ``deg`` was not specified, a vector whose entries are the 
     1575        dimensions is returned instead of a dictionary. 
    14741576       
     1577        ALGORITHM: 
     1578 
     1579        Roughly, Chech cohomology is used to compute the 
     1580        cohomology. For toric divisors, the local sections can be 
     1581        chosen to be monomials (instead of general homogeneous 
     1582        polynomials), this is the reason for the extra grading by 
     1583        `m\in M`. General refrences would be [Fulton]_, [CLS]_. Here 
     1584        are some salient features of our implementation: 
     1585         
     1586        * First, a finite set of `M`-lattice points is identified that 
     1587          supports the cohomology. The toric divisor determines a 
     1588          (polyhedral) chamber decomposition of `M_\RR`, see Section 
     1589          9.1 and Figure 4 of [CLS]_. The cohomology vanishes on the 
     1590          non-compact chambers. Hence, the convex hull of the vertices 
     1591          of the chamber decomposition contains all non-vanishing 
     1592          cohomology groups. This is returned by the private method 
     1593          :meth:`_sheaf_cohomology_support`. 
     1594 
     1595          It would be more efficient, but more difficult to implement, 
     1596          to keep track of all of the individual chambers. We leave 
     1597          this for future work. 
     1598 
     1599        * For each point `m\in M`, the weight-`m` part of the 
     1600          cohomology can be rewritten as the cohomology of a 
     1601          simplicial complex, see Exercise 9.1.10 of [CLS]_, 
     1602          [Perling]_. This is returned by the private method 
     1603          :meth:`_sheaf_complex`. 
     1604 
     1605          The simplicial complex is the same for all points in a 
     1606          chamber, but we currently do not make use of this and 
     1607          compute each point `m\in M` separately. 
     1608           
     1609        * Finally, the cohomology (over `\QQ`) of this simplicial 
     1610          complex is computed in the private method 
     1611          :meth:`_sheaf_cohomology`. Summing over the supporting 
     1612          points `m\in M` yields the cohomology of the sheaf`. 
     1613 
     1614        REFERENCES: 
     1615         
     1616        ..  [Perling] 
     1617            Markus Perling: Divisorial Cohomology Vanishing on Toric Varieties,  
     1618            http://arxiv.org/abs/0711.4836v2 
     1619 
    14751620        EXAMPLES: 
    14761621       
    14771622        Example 9.1.7 of Cox, Little, Schenck: "Toric Varieties" [CLS]_:: 
     
    14841629            sage: D6 = dP6.divisor(5) 
    14851630            sage: D = -D3 + 2*D5 - D6 
    14861631            sage: D.cohomology() 
    1487             (0, 4, 0) 
    1488             sage: D.cohomology( deg=1 ) 
    1489             4 
     1632            {0: Vector space of dimension 0 over Rational Field,  
     1633             1: Vector space of dimension 4 over Rational Field,  
     1634             2: Vector space of dimension 0 over Rational Field} 
     1635            sage: D.cohomology(deg=1) 
     1636            Vector space of dimension 4 over Rational Field 
    14901637            sage: M = F.dual_lattice() 
    14911638            sage: D.cohomology( M(0,0) ) 
    1492             (0, 1, 0) 
    1493             sage: D.cohomology( M(0,0), deg=1 ) 
    1494             1 
     1639            {0: Vector space of dimension 0 over Rational Field,  
     1640             1: Vector space of dimension 1 over Rational Field,  
     1641             2: Vector space of dimension 0 over Rational Field} 
     1642            sage: D.cohomology( weight=M(0,0), deg=1 ) 
     1643            Vector space of dimension 1 over Rational Field 
    14951644            sage: dP6.integrate( D.ch() * dP6.Td() ) 
    14961645            -4 
     1646 
     1647        Note the different output options:: 
     1648 
     1649            sage: D.cohomology() 
     1650            {0: Vector space of dimension 0 over Rational Field,  
     1651             1: Vector space of dimension 4 over Rational Field,  
     1652             2: Vector space of dimension 0 over Rational Field} 
     1653            sage: D.cohomology(dim=True) 
     1654            (0, 4, 0) 
     1655            sage: D.cohomology(weight=M(0,0)) 
     1656            {0: Vector space of dimension 0 over Rational Field,  
     1657             1: Vector space of dimension 1 over Rational Field,  
     1658             2: Vector space of dimension 0 over Rational Field} 
     1659            sage: D.cohomology(weight=M(0,0), dim=True) 
     1660            (0, 1, 0) 
     1661            sage: D.cohomology(deg=1) 
     1662            Vector space of dimension 4 over Rational Field 
     1663            sage: D.cohomology(deg=1, dim=True) 
     1664            4 
     1665            sage: D.cohomology(weight=M(0,0), deg=1) 
     1666            Vector space of dimension 1 over Rational Field 
     1667            sage: D.cohomology(weight=M(0,0), deg=1, dim=True) 
     1668            1 
     1669 
     1670        Here is a Weil (non-Cartier) divisor example:: 
     1671 
     1672            sage: K = toric_varieties.Cube_nonpolyhedral().K() 
     1673            sage: K.is_Weil() 
     1674            True 
     1675            sage: K.is_QQ_Cartier() 
     1676            False 
     1677            sage: K.cohomology(dim=True) 
     1678            (0, 0, 0, 1) 
     1679        """ 
     1680        if '_cohomology_vector' in self.__dict__ and weight is None: 
     1681            # cache the cohomology but not the individual weight pieces 
     1682            HH = self._cohomology_vector 
     1683        else: 
     1684            X = self.parent().scheme() 
     1685            M = X.fan().dual_lattice() 
     1686            support = self._sheaf_cohomology_support() 
     1687            if weight is None: 
     1688                m_list = [ M(p) for p in support.integral_points() ] 
     1689            else: 
     1690                m_list = [ M(weight) ] 
     1691          
     1692            HH = vector(ZZ, [0]*(X.dimension()+1)) 
     1693            for m_point in m_list: 
     1694                cplx = self._sheaf_complex(m_point) 
     1695                HH += self._sheaf_cohomology(cplx) 
     1696 
     1697            if weight is None: 
     1698                self._cohomology_vector = HH 
     1699 
     1700        if dim: 
     1701            if deg is None: 
     1702                return HH 
     1703            else: 
     1704                return HH[deg] 
     1705        else: 
     1706            from sage.modules.free_module import VectorSpace 
     1707            vectorspaces = dict( [k,VectorSpace(self.scheme().base_ring(),HH[k])] 
     1708                                 for k in range(0,len(HH)) ) 
     1709            if deg is None: 
     1710                return vectorspaces 
     1711            else: 
     1712                return vectorspaces[deg] 
     1713 
     1714    def cohomology_support(self): 
     1715        r""" 
     1716        Return the weights for which the cohomology groups do not vanish. 
     1717         
     1718        OUTPUT: 
     1719 
     1720        A tuple of dual lattice points. ``self.cohomology(weight=m)`` 
     1721        does not vanish if and only if ``m`` is in the output. 
     1722 
     1723        .. NOTE:: 
     1724         
     1725            This method is provided for educational purposes and it is 
     1726            not an efficient way of computing the cohomology groups. 
     1727 
     1728        EXAMPLES:: 
     1729 
     1730            sage: F = Fan(cones=[(0,1), (1,2), (2,3), (3,4), (4,5), (5,0)], 
     1731            ...           rays=[(1,0), (1,1), (0,1), (-1,0), (-1,-1), (0,-1)]) 
     1732            sage: dP6 = ToricVariety(F) 
     1733            sage: D3 = dP6.divisor(2) 
     1734            sage: D5 = dP6.divisor(4) 
     1735            sage: D6 = dP6.divisor(5) 
     1736            sage: D = -D3 + 2*D5 - D6 
     1737            sage: D.cohomology_support() 
     1738            (M(2, 0), M(1, 0), M(0, 0), M(1, 1)) 
    14971739        """ 
    14981740        X = self.parent().scheme() 
    14991741        M = X.fan().dual_lattice() 
    1500         if weight is None: 
    1501             m_list = [ M(p) for p in self._sheaf_cohomology_support().points().columns() ] 
    1502         else: 
    1503             m_list = [weight] 
    1504           
    1505         HH = vector(ZZ, [0]*(X.dimension()+1)) 
    1506         for m_point in m_list: 
    1507             cplx = self._sheaf_complex(m_point) 
    1508             HH += self._sheaf_cohomology(cplx) 
    1509         return HH if deg is None else HH[deg] 
     1742        support_hull = self._sheaf_cohomology_support() 
     1743        support_hull = [ M(p) for p in support_hull.integral_points() ] 
     1744        support = [] 
     1745        for m in support_hull: 
     1746            cplx = self._sheaf_complex(m) 
     1747            HH = self._sheaf_cohomology(cplx) 
     1748            if sum(HH)>0: 
     1749                support.append(m) 
     1750        return tuple(support) 
    15101751 
    15111752 
    15121753#******************************************************** 
     
    15301771    .. WARNING:: 
    15311772 
    15321773        Do not instantiate this class yourself. Use 
    1533         :meth:`~sage.schemes.generic.toric_variety.ToricVariety_field.divisor_class_group` 
     1774        :meth:`~sage.schemes.generic.toric_variety.ToricVariety_field.rational_class_group` 
    15341775        method of :class:`toric varieties 
    15351776        <sage.schemes.generic.toric_variety.ToricVariety_field>` if you need 
    15361777        the divisor class group. Or you can obtain it as the parent of any 
     
    15491790    EXAMPLES:: 
    15501791 
    15511792        sage: P2 = toric_varieties.P2() 
    1552         sage: P2.divisor_class_group() 
     1793        sage: P2.rational_class_group() 
    15531794        The toric rational divisor class group of a 2-d CPR-Fano  
    15541795        toric variety covered by 3 affine patches 
    15551796        sage: D = P2.divisor(1); D 
     
    16371878        EXAMPLES:: 
    16381879 
    16391880            sage: dP6 = toric_varieties.dP6() 
    1640             sage: Cl = dP6.divisor_class_group() 
     1881            sage: Cl = dP6.rational_class_group() 
    16411882            sage: D = dP6.divisor(2) 
    16421883            sage: Cl._element_constructor_(D) 
    16431884            Divisor class [0, 0, 1, 0] 
  • sage/schemes/generic/toric_divisor_class.pyx

    diff -r 3e8a10545e10 -r 448d739f20e7 sage/schemes/generic/toric_divisor_class.pyx
    a b  
    1414toric variety, represented as rational vectors in some basis:: 
    1515 
    1616    sage: dP6 = toric_varieties.dP6() 
    17     sage: Cl = dP6.divisor_class_group() 
     17    sage: Cl = dP6.rational_class_group() 
    1818    sage: D = Cl([1, -2, 3, -4]) 
    1919    sage: D 
    2020    Divisor class [1, -2, 3, -4] 
     
    8787        sage: is_ToricRationalDivisorClass(1) 
    8888        False 
    8989        sage: dP6 = toric_varieties.dP6() 
    90         sage: D = dP6.divisor_class_group().gen(0) 
     90        sage: D = dP6.rational_class_group().gen(0) 
    9191        sage: D 
    9292        Divisor class [1, 0, 0, 0] 
    9393        sage: is_ToricRationalDivisorClass(D) 
     
    116116    TESTS:: 
    117117 
    118118        sage: dP6 = toric_varieties.dP6() 
    119         sage: Cl = dP6.divisor_class_group() 
     119        sage: Cl = dP6.rational_class_group() 
    120120        sage: D = dP6.divisor(2) 
    121121        sage: Cl(D) 
    122122        Divisor class [0, 0, 1, 0] 
     
    129129        TESTS:: 
    130130 
    131131            sage: dP6 = toric_varieties.dP6() 
    132             sage: Cl = dP6.divisor_class_group() 
     132            sage: Cl = dP6.rational_class_group() 
    133133            sage: D = Cl([1, -2, 3, -4]) 
    134134            sage: D 
    135135            Divisor class [1, -2, 3, -4] 
     
    163163        TESTS:: 
    164164 
    165165            sage: dP6 = toric_varieties.dP6() 
    166             sage: Cl = dP6.divisor_class_group() 
     166            sage: Cl = dP6.rational_class_group() 
    167167            sage: D = Cl([1, -2, 3, -4]) 
    168168            sage: D 
    169169            Divisor class [1, -2, 3, -4] 
     
    226226 
    227227        TESTS:: 
    228228 
    229             sage: c = toric_varieties.dP8().divisor_class_group().gens() 
     229            sage: c = toric_varieties.dP8().rational_class_group().gens() 
    230230            sage: c[0]._dot_product_(c[1]) 
    231231            Traceback (most recent call last): 
    232232            ... 
     
    319319    TESTS:: 
    320320       
    321321        sage: dP6 = toric_varieties.dP6() 
    322         sage: Cl = dP6.divisor_class_group() 
     322        sage: Cl = dP6.rational_class_group() 
    323323        sage: D = Cl([1, -2, 3, -4]) 
    324324        sage: D 
    325325        Divisor class [1, -2, 3, -4] 
  • sage/schemes/generic/toric_variety.py

    diff -r 3e8a10545e10 -r 448d739f20e7 sage/schemes/generic/toric_variety.py
    a b  
    13551355 
    13561356            This cone sits in the rational divisor class group of ``self`` and 
    13571357            the choice of coordinates agrees with 
    1358             :meth:`divisor_class_group`. 
     1358            :meth:`rational_class_group`. 
    13591359 
    13601360        EXAMPLES:: 
    13611361 
     
    13801380            for cone in fan: 
    13811381                sigma = Cone([GT[i] for i in range(n) 
    13821382                                    if i not in cone.ambient_ray_indices()], 
    1383                              lattice = self.divisor_class_group()) 
     1383                             lattice = self.rational_class_group()) 
    13841384                K = K.intersection(sigma) if K is not None else sigma 
    13851385            self._Kaehler_cone = K 
    13861386        return self._Kaehler_cone 
     
    14291429            self._Mori_cone = Cone(rays, lattice=ZZ**(self._fan.nrays()+1)) 
    14301430        return self._Mori_cone 
    14311431         
    1432     def divisor_class_group(self): 
     1432    def rational_class_group(self): 
    14331433        r""" 
    14341434        Return the rational divisor class group of ``self``. 
    14351435 
     
    14621462 
    14631463            sage: fan = FaceFan(lattice_polytope.octahedron(2)) 
    14641464            sage: P1xP1 = ToricVariety(fan) 
    1465             sage: P1xP1.divisor_class_group() 
     1465            sage: P1xP1.rational_class_group() 
    14661466            The toric rational divisor class group 
    14671467            of a 2-d toric variety covered by 4 affine patches 
    14681468        """ 
     
    20962096        from sage.schemes.generic.toric_divisor import ToricDivisor 
    20972097        return ToricDivisor(self, [-1]*self._fan.nrays()) 
    20982098 
    2099     def divisor(self, arg, base_ring=None, check=False, reduce=False): 
     2099    def divisor(self, arg, base_ring=None, check=True, reduce=True): 
    21002100        r""" 
    21012101        Return a divisor. 
    21022102 
    21032103        INPUT: 
    21042104 
    2105         - ``arg`` -- something that identifies a divisor, see 
    2106           :func:`sage.schemes.generic.toric_divisor.ToricDivisor`. 
     2105        The arguments are the same as in 
     2106        :func:`sage.schemes.generic.toric_divisor.ToricDivisor`. 
    21072107 
    21082108        OUTPUT: 
    21092109 
  • sage/schemes/generic/toric_variety_library.py

    diff -r 3e8a10545e10 -r 448d739f20e7 sage/schemes/generic/toric_variety_library.py
    a b  
    135135         ( 1, 0, 4)], 
    136136        [[0,4,2],[0,4,5],[0,5,3],[0,1,3],[0,1,2], 
    137137         [6,4,2],[6,4,5],[6,5,3],[6,1,3],[6,1,2]] ], 
     138    'P2_112':[ 
     139        [(1,0), (0, 1), (-1, -2)], 
     140        [[0,1],[1,2],[2,0]] ], 
     141    'P2_123':[ 
     142        [(1,0), (0, 1), (-2, -3)], 
     143        [[0,1],[1,2],[2,0]] ], 
    138144    'P4_11169':[ 
    139145        [(1, 0, 0, 0), (0, 1, 0, 0), (0, 0, 1, 0), (0, 0, 0, 1), (-9, -6, -1, -1)], 
    140146        [[0,1,2,3],[0,1,2,4],[0,1,3,4],[0,2,3,4],[1,2,3,4]] ], 
     
    795801        """ 
    796802        return self._make_ToricVariety('BCdlOG_base', 'd4 d3 r2 r1 d2 u d1') 
    797803 
     804    def P2_112(self): 
     805        r""" 
     806        Construct the weighted projective space 
     807        `\mathbb{P}^2(1,1,2)`. 
     808         
     809        OUTPUT: 
     810 
     811        A :class:`CPR-Fano toric variety 
     812        <sage.schemes.generic.fano_toric_variety.CPRFanoToricVariety_field>`. 
     813 
     814        EXAMPLES:: 
     815         
     816            sage: P2_112 = toric_varieties.P2_112() 
     817            sage: P2_112 
     818            2-d CPR-Fano toric variety covered by 3 affine patches 
     819            sage: P2_112.fan().ray_matrix() 
     820            [ 1  0 -1] 
     821            [ 0  1 -2] 
     822            sage: P2_112.gens() 
     823            (z0, z1, z2) 
     824        """ 
     825        return self._make_CPRFanoToricVariety('P2_112', None) 
     826 
     827    def P2_123(self): 
     828        r""" 
     829        Construct the weighted projective space 
     830        `\mathbb{P}^2(1,2,3)`. 
     831         
     832        OUTPUT: 
     833 
     834        A :class:`CPR-Fano toric variety 
     835        <sage.schemes.generic.fano_toric_variety.CPRFanoToricVariety_field>`. 
     836 
     837        EXAMPLES:: 
     838         
     839            sage: P2_123 = toric_varieties.P2_123() 
     840            sage: P2_123 
     841            2-d CPR-Fano toric variety covered by 3 affine patches 
     842            sage: P2_123.fan().ray_matrix() 
     843            [ 1  0 -2] 
     844            [ 0  1 -3] 
     845            sage: P2_123.gens() 
     846            (z0, z1, z2) 
     847        """ 
     848        return self._make_CPRFanoToricVariety('P2_123', None) 
     849 
    798850    def P4_11169(self): 
    799851        r""" 
    800852        Construct the weighted projective space 
  • sage/schemes/plane_curves/curve.py

    diff -r 3e8a10545e10 -r 448d739f20e7 sage/schemes/plane_curves/curve.py
    a b  
    6161    def divisor(self, v, base_ring=None, check=True, reduce=True): 
    6262        r""" 
    6363        Return the divisor specified by ``v``. 
     64 
     65        .. WARNING:: 
     66 
     67            The coefficients of the divisor must be in the base ring 
     68            and the terms must be reduced. If you set ``check=False`` 
     69            and/or ``reduce=False`` it is your responsibility to pass 
     70            a valid object ``v``. 
    6471        """ 
    6572        return Divisor_curve(v, check=check, reduce=reduce, parent=self.divisor_group(base_ring)) 
    6673 
  • sage/structure/formal_sum.py

    diff -r 3e8a10545e10 -r 448d739f20e7 sage/structure/formal_sum.py
    a b  
    6565#***************************************************************************** 
    6666 
    6767import sage.misc.misc 
    68 import element 
    6968import operator 
    7069import sage.misc.latex 
    7170 
     
    278277         
    279278            sage: FormalSum([(1,2/3), (3,2/3), (-5, 7)], parent=FormalSums(GF(5)), check=False) 
    280279            4*2/3 - 5*7 
     280 
     281        Make sure we first reduce before checking coefficient types:: 
     282          
     283            sage: x,y = var('x, y') 
     284            sage: FormalSum([(1/2,x), (2,y)], FormalSums(QQ)) 
     285            1/2*x + 2*y 
     286            sage: FormalSum([(1/2,x), (2,y)], FormalSums(ZZ)) 
     287            Traceback (most recent call last): 
     288            ... 
     289            TypeError: no conversion of this rational to integer 
     290            sage: FormalSum([(1/2,x), (1/2,x), (2,y)], FormalSums(ZZ)) 
     291            x + 2*y 
    281292        """ 
    282293        if x == 0: 
    283294            x = [] 
    284         if check: 
    285             k = parent.base_ring() 
    286             try: 
    287                 x = [(k(t[0]), t[1]) for t in x] 
    288             except (IndexError, KeyError), msg: 
    289                 raise TypeError, "%s\nInvalid formal sum"%msg 
    290295        self._data = x 
    291296        if parent is None: 
    292297            parent = formal_sums 
    293298        ModuleElement.__init__(self, parent) 
    294         if reduce: 
     299        if reduce:  # first reduce 
    295300            self.reduce() 
     301        if check:   # then check 
     302            k = parent.base_ring() 
     303            try: 
     304                self._data = [(k(t[0]), t[1]) for t in self._data] 
     305            except (IndexError, KeyError), msg: 
     306                raise TypeError, "%s\nInvalid formal sum"%msg 
    296307 
    297308    def __iter__(self): 
    298309        """ 
     
    450461        """ 
    451462        if len(self) == 0: 
    452463            return 
    453         v = [(x,c) for c, x in self if not c.is_zero()] 
     464        v = [(x,c) for c, x in self if c!=0] 
    454465        if len(v) == 0: 
    455466            self._data = v 
    456467            return 
     
    466477                    w.append((coeff, last)) 
    467478                last = x 
    468479                coeff = c 
    469         if not coeff.is_zero(): 
     480        if coeff != 0: 
    470481            w.append((coeff,last)) 
    471482        self._data = w