Ticket #9337: trac_9337_final.patch
| File trac_9337_final.patch, 48.7 KB (added by vbraun, 3 years ago) |
|---|
-
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 119 119 from sage.rings.real_double import RDF 120 120 from sage.modules.free_module_element import vector 121 121 from sage.matrix.constructor import matrix, identity_matrix 122 from sage.functions.other import sqrt 122 from sage.functions.other import sqrt, floor, ceil 123 123 from sage.functions.trig import sin, cos 124 124 125 125 from sage.plot.all import point2d, line2d, arrow, polygon2d … … 3632 3632 3633 3633 return True 3634 3634 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 3636 3798 3637 3799 ############################################################# 3638 3800 def cyclic_sort_vertices_2d(Vlist): … … 4409 4571 for f in self.polygons ]) 4410 4572 4411 4573 4412 4413 4574 ######################################################################### 4414 4575 class Polytopes(): 4415 4576 """ -
sage/schemes/generic/divisor.py
diff -r 3e8a10545e10 -r 448d739f20e7 sage/schemes/generic/divisor.py
a b 127 127 Construct a :class:`Divisor_generic`. 128 128 129 129 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``. 132 152 133 153 EXAMPLES:: 134 154 -
sage/schemes/generic/toric_divisor.py
diff -r 3e8a10545e10 -r 448d739f20e7 sage/schemes/generic/toric_divisor.py
a b 78 78 **Picard group** `\mathop{\mathrm{Pic}}(X)`. We continue using del Pezzo 79 79 surface of degree 6 introduced above:: 80 80 81 sage: Cl = dP6. divisor_class_group(); Cl81 sage: Cl = dP6.rational_class_group(); Cl 82 82 The toric rational divisor class group 83 83 of a 2-d CPR-Fano toric variety covered by 6 affine patches 84 84 sage: Cl.ngens() … … 134 134 135 135 sage: M = P2.fan().lattice().dual() 136 136 sage: H.cohomology(deg=0, weight=M(-1,0)) 137 Vector space of dimension 1 over Rational Field 138 sage: _.dimension() 137 139 1 138 140 139 141 Here is a more complicated example with `h^1(dP_6, \mathcal{O}(D))=4` :: 140 142 141 143 sage: D = dP6.divisor([0, 0, -1, 0, 2, -1]) 142 144 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) 143 149 (0, 4, 0) 150 151 AUTHORS: 152 153 - Volker Braun, Andrey Novoseltsev (2010-09-07): initial version. 144 154 """ 145 155 146 156 … … 157 167 from sage.structure.element import is_Vector 158 168 from sage.combinat.combination import Combinations 159 169 from sage.geometry.cone import is_Cone 160 from sage.geometry.lattice_polytope import LatticePolytope161 170 from sage.geometry.polyhedra import Polyhedron 162 171 from sage.geometry.toric_lattice_element import is_ToricLatticeElement 163 172 from sage.homology.simplicial_complex import SimplicialComplex … … 407 416 408 417 409 418 #******************************************************** 410 def ToricDivisor(toric_variety, arg=None, ring=None, check= False, reduce=False):419 def ToricDivisor(toric_variety, arg=None, ring=None, check=True, reduce=True): 411 420 r""" 412 421 Construct a divisor of ``toric_variety``. 413 422 … … 437 446 divisor group. If ``ring`` is not specified, a coefficient ring 438 447 suitable for ``arg`` is derived. 439 448 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``. 441 462 442 463 OUTPUT: 443 464 … … 466 487 sage: N = dP6.fan().lattice() 467 488 sage: ToricDivisor(dP6, N(1,1) ) 468 489 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)]! 469 505 """ 470 506 assert is_ToricVariety(toric_variety) 507 508 ##### First convert special arguments into lists 509 ##### of multiplicities or (multiplicity,coordinate) 471 510 # Zero divisor 472 511 if arg is None: 473 512 arg = [] 513 check = False 514 reduce = False 474 515 # Divisor by lattice point (corresponding to a ray) 475 516 if is_ToricLatticeElement(arg): 476 517 if arg not in toric_variety.fan().lattice(): … … 486 527 # Divisor by a ray index 487 528 if arg in ZZ: 488 529 arg = [(1, toric_variety.gen(arg))] 530 check = True # ensure that the 1 will be coerced into the coefficient ring 531 reduce = False 489 532 # Divisor by monomial 490 533 if arg in toric_variety.coordinate_ring(): 491 534 if len(list(arg)) != 1: … … 498 541 arg = list(arg) 499 542 except TypeError: 500 543 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) 503 558 if ring is None: 559 # if the coefficient ring was not given, try to use the most common ones. 504 560 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) 507 564 except TypeError: 508 565 pass 509 566 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) 512 570 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) 527 572 TDiv = ToricDivisorGroup(toric_variety, ring) 528 573 return ToricDivisor_generic(arg, TDiv, check, reduce) 529 574 … … 657 702 variable = self.parent().scheme().gen(index) 658 703 except TypeError: 659 704 variable = x 660 total = self.base_ring().zero() 705 661 706 for coeff, var in self: 662 707 if var == variable: 663 total +=coeff664 return total708 return coeff 709 return self.base_ring().zero() 665 710 666 711 def function_value(self, point): 667 712 r""" … … 896 941 897 942 def is_integral(self): 898 943 r""" 899 Return whether the support function is integral on the rays.944 Return whether the coefficients of the divisor are all integral. 900 945 901 946 EXAMPLES:: 902 947 … … 910 955 sage: DQQ.is_integral() 911 956 True 912 957 """ 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 ) 915 959 916 960 def move_away_from(self, cone): 917 961 """ … … 1013 1057 1014 1058 Returns the class of the divisor in `\mathop{Cl}(X) 1015 1059 \otimes_\ZZ \QQ` as an instance of 1016 :class:`ToricRationalDivisorClass `.1060 :class:`ToricRationalDivisorClassGroup`. 1017 1061 1018 EXAMPLE :1062 EXAMPLES:: 1019 1063 1020 1064 sage: dP6 = toric_varieties.dP6() 1021 1065 sage: D = dP6.divisor(0) … … 1023 1067 Divisor class [1, 0, 0, 0] 1024 1068 """ 1025 1069 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) 1027 1071 return self._divisor_class 1028 1072 1029 1073 def is_ample(self): … … 1040 1084 multiple is Cartier. We return wheher this associtated 1041 1085 divisor is ample, i.e. corresponds to an ample line bundle. 1042 1086 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). 1044 1098 1045 1099 * See also :meth:`is_nef`. 1046 1100 … … 1058 1112 sage: (-K).is_ample() 1059 1113 True 1060 1114 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]_:: 1062 1116 1063 1117 sage: fan = Fan(cones=[(0,1), (1,2), (2,3), (3,0)], 1064 1118 ... rays=[(-1,2), (0,1), (1,0), (0,-1)]) … … 1072 1126 ... if D(a,b).is_nef() ] 1073 1127 [(0, 0), (0, 1), (0, 2), (1, 0), 1074 1128 (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 1075 1144 """ 1076 1145 try: 1077 1146 return self._is_ample … … 1079 1148 pass 1080 1149 1081 1150 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()) 1085 1153 return self._is_ample 1086 1154 1087 1155 def is_nef(self): … … 1120 1188 sage: (-K).is_nef() 1121 1189 True 1122 1190 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]_:: 1124 1192 1125 1193 sage: fan = Fan(cones=[(0,1), (1,2), (2,3), (3,0)], 1126 1194 ... rays=[(-1,2), (0,1), (1,0), (0,-1)]) … … 1144 1212 self._is_nef = self.divisor_class() in self.parent().scheme().Kaehler_cone() 1145 1213 return self._is_nef 1146 1214 1147 def poly tope(self):1215 def polyhedron(self): 1148 1216 r""" 1149 Return the lattice polytope `P_D\subset M` associated to a nef1150 Cartierdivisor `D`.1217 Return the polyhedron `P_D\subset M` associated to a toric 1218 divisor `D`. 1151 1219 1152 1220 OUTPUT: 1153 1221 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`. 1158 1223 1159 1224 EXAMPLES:: 1160 1225 1161 1226 sage: dP7 = toric_varieties.dP7() 1162 1227 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)] 1168 1232 sage: D.is_nef() 1169 1233 False 1170 1234 sage: dP7.integrate( D.ch() * dP7.Td() ) 1171 1235 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)] 1177 1243 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]_:: 1179 1245 1180 1246 sage: fan = Fan(cones=[(0,1), (1,2), (2,3), (3,0)], 1181 1247 ... rays=[(-1,2), (0,1), (1,0), (0,-1)]) 1182 1248 sage: F2 = ToricVariety(fan,'u1, u2, u3, u4') 1183 1249 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)] 1187 1252 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)] 1191 1255 sage: D.is_ample() 1192 1256 False 1193 1257 sage: D.is_nef() 1194 1258 True 1195 1259 sage: Dprime.is_nef() 1196 1260 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)] 1197 1288 """ 1198 1289 try: 1199 return self._poly tope1290 return self._polyhedron 1200 1291 except AttributeError: 1201 1292 pass 1202 1293 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() 1208 1295 divisor = vector(self) 1209 1296 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 1218 1299 1219 1300 def sections(self): 1220 1301 """ … … 1250 1331 self._sections = () 1251 1332 else: 1252 1333 self._sections = tuple(M(m) 1253 for m in self.polytope().points().columns())1334 for m in self.polyhedron().integral_points()) 1254 1335 return self._sections 1255 1336 1256 1337 def sections_monomials(self): … … 1279 1360 1280 1361 From [CoxTutorial]_ page 38:: 1281 1362 1363 sage: from sage.geometry.lattice_polytope import LatticePolytope 1282 1364 sage: lp = LatticePolytope(matrix([[1,1,0,-1,0], [0,1,1,0,-1]])) 1283 1365 sage: lp 1284 1366 A lattice polytope: 2-dimensional, 5 vertices. … … 1314 1396 monomials in :meth:`ToricVariety.coordinate_ring 1315 1397 <sage.schemes.generic.toric_variety.ToricVariety_field.coordinate_ring>`. 1316 1398 Alternatively, the monomials can be described as `M`-lattice 1317 points in the polyhedron ``D.poly tope()``. This method converts the1318 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. 1319 1401 1320 1402 EXAMPLES:: 1321 1403 … … 1403 1485 HH = cplx.homology(base_ring=QQ, cohomology=True) 1404 1486 HH_list = [0]*(d+1) 1405 1487 for h in HH.iteritems(): 1488 if h[0]==d: 1489 assert(h[1].dimension()==0) 1490 continue 1406 1491 HH_list[ h[0]+1 ] = h[1].dimension() 1407 1492 1408 1493 return vector(ZZ, HH_list) … … 1413 1498 1414 1499 OUTPUT: 1415 1500 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. 1418 1511 1419 1512 EXAMPLES:: 1420 1513 … … 1425 1518 sage: D = -D0 + 2*D2 - D3 1426 1519 sage: supp = D._sheaf_cohomology_support() 1427 1520 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)] 1432 1524 """ 1433 1525 X = self.parent().scheme() 1526 fan = X.fan() 1434 1527 if not X.is_complete(): 1435 1528 raise ValueError("%s is not complete, its cohomology is not " 1436 1529 "finite-dimensional!" % X) 1437 1530 d = X.dimension() 1438 1531 chamber_vertices = [] 1439 for p list 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 ]) 1442 1535 try: 1443 1536 chamber_vertices.append(A.solve_right(-b)) 1444 1537 except ValueError: 1445 1538 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) 1452 1540 1453 def cohomology(self, weight=None, deg=None ):1541 def cohomology(self, weight=None, deg=None, dim=False): 1454 1542 r""" 1455 1543 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. 1457 1546 1458 1547 .. NOTE:: 1459 1548 … … 1466 1555 1467 1556 - ``deg`` -- (optional) the degree of the cohomology group. 1468 1557 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 1469 1562 OUTPUT: 1470 1563 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. 1474 1576 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 1475 1620 EXAMPLES: 1476 1621 1477 1622 Example 9.1.7 of Cox, Little, Schenck: "Toric Varieties" [CLS]_:: … … 1484 1629 sage: D6 = dP6.divisor(5) 1485 1630 sage: D = -D3 + 2*D5 - D6 1486 1631 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 1490 1637 sage: M = F.dual_lattice() 1491 1638 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 1495 1644 sage: dP6.integrate( D.ch() * dP6.Td() ) 1496 1645 -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)) 1497 1739 """ 1498 1740 X = self.parent().scheme() 1499 1741 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) 1510 1751 1511 1752 1512 1753 #******************************************************** … … 1530 1771 .. WARNING:: 1531 1772 1532 1773 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` 1534 1775 method of :class:`toric varieties 1535 1776 <sage.schemes.generic.toric_variety.ToricVariety_field>` if you need 1536 1777 the divisor class group. Or you can obtain it as the parent of any … … 1549 1790 EXAMPLES:: 1550 1791 1551 1792 sage: P2 = toric_varieties.P2() 1552 sage: P2. divisor_class_group()1793 sage: P2.rational_class_group() 1553 1794 The toric rational divisor class group of a 2-d CPR-Fano 1554 1795 toric variety covered by 3 affine patches 1555 1796 sage: D = P2.divisor(1); D … … 1637 1878 EXAMPLES:: 1638 1879 1639 1880 sage: dP6 = toric_varieties.dP6() 1640 sage: Cl = dP6. divisor_class_group()1881 sage: Cl = dP6.rational_class_group() 1641 1882 sage: D = dP6.divisor(2) 1642 1883 sage: Cl._element_constructor_(D) 1643 1884 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 14 14 toric variety, represented as rational vectors in some basis:: 15 15 16 16 sage: dP6 = toric_varieties.dP6() 17 sage: Cl = dP6. divisor_class_group()17 sage: Cl = dP6.rational_class_group() 18 18 sage: D = Cl([1, -2, 3, -4]) 19 19 sage: D 20 20 Divisor class [1, -2, 3, -4] … … 87 87 sage: is_ToricRationalDivisorClass(1) 88 88 False 89 89 sage: dP6 = toric_varieties.dP6() 90 sage: D = dP6. divisor_class_group().gen(0)90 sage: D = dP6.rational_class_group().gen(0) 91 91 sage: D 92 92 Divisor class [1, 0, 0, 0] 93 93 sage: is_ToricRationalDivisorClass(D) … … 116 116 TESTS:: 117 117 118 118 sage: dP6 = toric_varieties.dP6() 119 sage: Cl = dP6. divisor_class_group()119 sage: Cl = dP6.rational_class_group() 120 120 sage: D = dP6.divisor(2) 121 121 sage: Cl(D) 122 122 Divisor class [0, 0, 1, 0] … … 129 129 TESTS:: 130 130 131 131 sage: dP6 = toric_varieties.dP6() 132 sage: Cl = dP6. divisor_class_group()132 sage: Cl = dP6.rational_class_group() 133 133 sage: D = Cl([1, -2, 3, -4]) 134 134 sage: D 135 135 Divisor class [1, -2, 3, -4] … … 163 163 TESTS:: 164 164 165 165 sage: dP6 = toric_varieties.dP6() 166 sage: Cl = dP6. divisor_class_group()166 sage: Cl = dP6.rational_class_group() 167 167 sage: D = Cl([1, -2, 3, -4]) 168 168 sage: D 169 169 Divisor class [1, -2, 3, -4] … … 226 226 227 227 TESTS:: 228 228 229 sage: c = toric_varieties.dP8(). divisor_class_group().gens()229 sage: c = toric_varieties.dP8().rational_class_group().gens() 230 230 sage: c[0]._dot_product_(c[1]) 231 231 Traceback (most recent call last): 232 232 ... … … 319 319 TESTS:: 320 320 321 321 sage: dP6 = toric_varieties.dP6() 322 sage: Cl = dP6. divisor_class_group()322 sage: Cl = dP6.rational_class_group() 323 323 sage: D = Cl([1, -2, 3, -4]) 324 324 sage: D 325 325 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 1355 1355 1356 1356 This cone sits in the rational divisor class group of ``self`` and 1357 1357 the choice of coordinates agrees with 1358 :meth:` divisor_class_group`.1358 :meth:`rational_class_group`. 1359 1359 1360 1360 EXAMPLES:: 1361 1361 … … 1380 1380 for cone in fan: 1381 1381 sigma = Cone([GT[i] for i in range(n) 1382 1382 if i not in cone.ambient_ray_indices()], 1383 lattice = self. divisor_class_group())1383 lattice = self.rational_class_group()) 1384 1384 K = K.intersection(sigma) if K is not None else sigma 1385 1385 self._Kaehler_cone = K 1386 1386 return self._Kaehler_cone … … 1429 1429 self._Mori_cone = Cone(rays, lattice=ZZ**(self._fan.nrays()+1)) 1430 1430 return self._Mori_cone 1431 1431 1432 def divisor_class_group(self):1432 def rational_class_group(self): 1433 1433 r""" 1434 1434 Return the rational divisor class group of ``self``. 1435 1435 … … 1462 1462 1463 1463 sage: fan = FaceFan(lattice_polytope.octahedron(2)) 1464 1464 sage: P1xP1 = ToricVariety(fan) 1465 sage: P1xP1. divisor_class_group()1465 sage: P1xP1.rational_class_group() 1466 1466 The toric rational divisor class group 1467 1467 of a 2-d toric variety covered by 4 affine patches 1468 1468 """ … … 2096 2096 from sage.schemes.generic.toric_divisor import ToricDivisor 2097 2097 return ToricDivisor(self, [-1]*self._fan.nrays()) 2098 2098 2099 def divisor(self, arg, base_ring=None, check= False, reduce=False):2099 def divisor(self, arg, base_ring=None, check=True, reduce=True): 2100 2100 r""" 2101 2101 Return a divisor. 2102 2102 2103 2103 INPUT: 2104 2104 2105 - ``arg`` -- something that identifies a divisor, see2106 :func:`sage.schemes.generic.toric_divisor.ToricDivisor`.2105 The arguments are the same as in 2106 :func:`sage.schemes.generic.toric_divisor.ToricDivisor`. 2107 2107 2108 2108 OUTPUT: 2109 2109 -
sage/schemes/generic/toric_variety_library.py
diff -r 3e8a10545e10 -r 448d739f20e7 sage/schemes/generic/toric_variety_library.py
a b 135 135 ( 1, 0, 4)], 136 136 [[0,4,2],[0,4,5],[0,5,3],[0,1,3],[0,1,2], 137 137 [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]] ], 138 144 'P4_11169':[ 139 145 [(1, 0, 0, 0), (0, 1, 0, 0), (0, 0, 1, 0), (0, 0, 0, 1), (-9, -6, -1, -1)], 140 146 [[0,1,2,3],[0,1,2,4],[0,1,3,4],[0,2,3,4],[1,2,3,4]] ], … … 795 801 """ 796 802 return self._make_ToricVariety('BCdlOG_base', 'd4 d3 r2 r1 d2 u d1') 797 803 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 798 850 def P4_11169(self): 799 851 r""" 800 852 Construct the weighted projective space -
sage/schemes/plane_curves/curve.py
diff -r 3e8a10545e10 -r 448d739f20e7 sage/schemes/plane_curves/curve.py
a b 61 61 def divisor(self, v, base_ring=None, check=True, reduce=True): 62 62 r""" 63 63 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``. 64 71 """ 65 72 return Divisor_curve(v, check=check, reduce=reduce, parent=self.divisor_group(base_ring)) 66 73 -
sage/structure/formal_sum.py
diff -r 3e8a10545e10 -r 448d739f20e7 sage/structure/formal_sum.py
a b 65 65 #***************************************************************************** 66 66 67 67 import sage.misc.misc 68 import element69 68 import operator 70 69 import sage.misc.latex 71 70 … … 278 277 279 278 sage: FormalSum([(1,2/3), (3,2/3), (-5, 7)], parent=FormalSums(GF(5)), check=False) 280 279 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 281 292 """ 282 293 if x == 0: 283 294 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"%msg290 295 self._data = x 291 296 if parent is None: 292 297 parent = formal_sums 293 298 ModuleElement.__init__(self, parent) 294 if reduce: 299 if reduce: # first reduce 295 300 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 296 307 297 308 def __iter__(self): 298 309 """ … … 450 461 """ 451 462 if len(self) == 0: 452 463 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] 454 465 if len(v) == 0: 455 466 self._data = v 456 467 return … … 466 477 w.append((coeff, last)) 467 478 last = x 468 479 coeff = c 469 if not coeff.is_zero():480 if coeff != 0: 470 481 w.append((coeff,last)) 471 482 self._data = w
