This repository has been archived by the owner on Jan 30, 2023. It is now read-only.
/
variety.py
3556 lines (2783 loc) · 119 KB
/
variety.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# -*- coding: utf-8 -*-
r"""
Toric varieties
This module provides support for (normal) toric varieties, corresponding to
:class:`rational polyhedral fans <sage.geometry.fan.RationalPolyhedralFan>`.
See also :mod:`~sage.schemes.toric.fano_variety` for a more
restrictive class of (weak) Fano toric varieties.
An **excellent reference on toric varieties** is the book "Toric
Varieties" by David A. Cox, John B. Little, and Hal Schenck
[CLS]_.
The interface to this module is provided through functions
:func:`AffineToricVariety` and :func:`ToricVariety`, although you may
also be interested in :func:`normalize_names`.
.. NOTE::
We do NOT build "general toric varieties" from affine toric varieties.
Instead, we are using the quotient representation of toric varieties with
the homogeneous coordinate ring (a.k.a. Cox's ring or the total coordinate
ring). This description works best for simplicial fans of the full
dimension.
REFERENCES:
.. [CLS]
David A. Cox, John B. Little, Hal Schenck,
"Toric Varieties", Graduate Studies in Mathematics,
Amer. Math. Soc., Providence, RI, 2011
AUTHORS:
- Andrey Novoseltsev (2010-05-17): initial version.
- Volker Braun (2010-07-24): Cohomology and characteristic classes added.
EXAMPLES:
We start with constructing the affine plane as an affine toric variety. First,
we need to have a corresponding cone::
sage: quadrant = Cone([(1,0), (0,1)])
If you don't care about variable names and the base field, that's all we need
for now::
sage: A2 = AffineToricVariety(quadrant)
sage: A2
2-d affine toric variety
sage: origin = A2(0,0)
sage: origin
[0 : 0]
Only affine toric varieties have points whose (homogeneous) coordinates
are all zero. ::
sage: parent(origin)
Set of rational points of 2-d affine toric variety
As you can see, by default toric varieties live over the field of rational
numbers::
sage: A2.base_ring()
Rational Field
While usually toric varieties are considered over the field of complex
numbers, for computational purposes it is more convenient to work with fields
that have exact representation on computers. You can also always do ::
sage: C2 = AffineToricVariety(quadrant, base_field=CC)
sage: C2.base_ring()
Complex Field with 53 bits of precision
sage: C2(1,2+i)
[1.00000000000000 : 2.00000000000000 + 1.00000000000000*I]
or even ::
sage: F = CC["a, b"].fraction_field()
sage: F.inject_variables()
Defining a, b
sage: A2 = AffineToricVariety(quadrant, base_field=F)
sage: A2(a,b)
[a : b]
OK, if you need to work only with affine spaces,
:func:`~sage.schemes.affine.affine_space.AffineSpace` may be a better way to
construct them. Our next example is the product of two projective lines
realized as the toric variety associated to the
:func:`face fan <sage.geometry.fan.FaceFan>` of the "diamond"::
sage: diamond = lattice_polytope.cross_polytope(2)
sage: diamond.vertices_pc()
M( 1, 0),
M( 0, 1),
M(-1, 0),
M( 0, -1)
in 2-d lattice M
sage: fan = FaceFan(diamond)
sage: P1xP1 = ToricVariety(fan)
sage: P1xP1
2-d toric variety covered by 4 affine patches
sage: P1xP1.fan().rays()
M( 1, 0),
M( 0, 1),
M(-1, 0),
M( 0, -1)
in 2-d lattice M
sage: P1xP1.gens()
(z0, z1, z2, z3)
We got four coordinates - two for each of the projective lines, but their
names are perhaps not very well chosen. Let's make `(x,y)` to be coordinates
on the first line and `(s,t)` on the second one::
sage: P1xP1 = ToricVariety(fan, coordinate_names="x s y t")
sage: P1xP1.gens()
(x, s, y, t)
Now, if we want to define subschemes of this variety, the defining polynomials
must be homogeneous in each of these pairs::
sage: P1xP1.inject_variables()
Defining x, s, y, t
sage: P1xP1.subscheme(x)
Closed subscheme of 2-d toric variety
covered by 4 affine patches defined by:
x
sage: P1xP1.subscheme(x^2 + y^2)
Closed subscheme of 2-d toric variety
covered by 4 affine patches defined by:
x^2 + y^2
sage: P1xP1.subscheme(x^2 + s^2)
Traceback (most recent call last):
...
ValueError: x^2 + s^2 is not homogeneous
on 2-d toric variety covered by 4 affine patches!
sage: P1xP1.subscheme([x^2*s^2 + x*y*t^2 +y^2*t^2, s^3 + t^3])
Closed subscheme of 2-d toric variety
covered by 4 affine patches defined by:
x^2*s^2 + x*y*t^2 + y^2*t^2,
s^3 + t^3
While we don't build toric varieties from affine toric varieties, we still can
access the "building pieces"::
sage: patch = P1xP1.affine_patch(2)
sage: patch
2-d affine toric variety
sage: patch.fan().rays()
M(1, 0),
M(0, 1)
in 2-d lattice M
sage: patch.embedding_morphism()
Scheme morphism:
From: 2-d affine toric variety
To: 2-d toric variety covered by 4 affine patches
Defn: Defined on coordinates by sending [x : s] to
[x : s : 1 : 1]
The patch above was specifically chosen to coincide with our representation of
the affine plane before, but you can get the other three patches as well.
(While any cone of a fan will correspond to an affine toric variety, the main
interest is usually in the generating fans as "the biggest" affine
subvarieties, and these are precisely the patches that you can get from
:meth:`~ToricVariety_field.affine_patch`.)
All two-dimensional toric varieties are "quite nice" because any
two-dimensional cone is generated by exactly two rays. From the point of view
of the corresponding toric varieties, this means that they have at worst
quotient singularities::
sage: P1xP1.is_orbifold()
True
sage: P1xP1.is_smooth()
True
sage: TV = ToricVariety(NormalFan(diamond))
sage: TV.fan().rays()
N(-1, 1),
N( 1, 1),
N(-1, -1),
N( 1, -1)
in 2-d lattice N
sage: TV.is_orbifold()
True
sage: TV.is_smooth()
False
In higher dimensions worse things can happen::
sage: TV3 = ToricVariety(NormalFan(lattice_polytope.cross_polytope(3)))
sage: TV3.fan().rays()
N(-1, -1, 1),
N( 1, -1, 1),
N(-1, 1, 1),
N( 1, 1, 1),
N(-1, -1, -1),
N( 1, -1, -1),
N(-1, 1, -1),
N( 1, 1, -1)
in 3-d lattice N
sage: TV3.is_orbifold()
False
Fortunately, we can perform a (partial) resolution::
sage: TV3_res = TV3.resolve_to_orbifold()
sage: TV3_res.is_orbifold()
True
sage: TV3_res.fan().ngenerating_cones()
12
sage: TV3.fan().ngenerating_cones()
6
In this example we had to double the number of affine patches. The result is
still singular::
sage: TV3_res.is_smooth()
False
You can resolve it further using :meth:`~ToricVariety_field.resolve` method,
but (at least for now) you will have to specify which rays should be inserted
into the fan. See also
:func:`~sage.schemes.toric.fano_variety.CPRFanoToricVariety`,
which can construct some other "nice partial resolutions."
The intersection theory on toric varieties is very well understood,
and there are explicit algorithms to compute many quantities of
interest. The most important tools are the :class:`cohomology ring
<CohomologyRing>` and the :mod:`Chow group
<sage.schemes.toric.chow_group>`. For `d`-dimensional compact
toric varieties with at most orbifold singularities, the rational
cohomology ring `H^*(X,\QQ)` and the rational Chow ring `A^*(X,\QQ) =
A_{d-*}(X)\otimes \QQ` are isomorphic except for a doubling in
degree. More precisely, the Chow group has the same rank
.. math::
A_{d-k}(X) \otimes \QQ \simeq H^{2k}(X,\QQ)
and the intersection in of Chow cycles matches the cup product in
cohomology.
In this case, you should work with the cohomology ring description
because it is much faster. For example, here is a weighted projective
space with a curve of `\ZZ_3`-orbifold singularities::
sage: P4_11133 = toric_varieties.P4_11133()
sage: P4_11133.is_smooth(), P4_11133.is_orbifold()
(False, True)
sage: cone = P4_11133.fan(3)[8]
sage: cone.is_smooth(), cone.is_simplicial()
(False, True)
sage: HH = P4_11133.cohomology_ring(); HH
Rational cohomology ring of a 4-d CPR-Fano toric variety covered by 5 affine patches
sage: P4_11133.cohomology_basis()
(([1],), ([z4],), ([z4^2],), ([z4^3],), ([z4^4],))
Every cone defines a torus orbit closure, and hence a (co)homology class::
sage: HH.gens()
([3*z4], [3*z4], [z4], [z4], [z4])
sage: map(HH, P4_11133.fan(1))
[[3*z4], [3*z4], [z4], [z4], [z4]]
sage: map(HH, P4_11133.fan(4) )
[[9*z4^4], [9*z4^4], [9*z4^4], [9*z4^4], [9*z4^4]]
sage: HH(cone)
[3*z4^3]
We can compute intersection numbers by integrating top-dimensional
cohomology classes::
sage: D = P4_11133.divisor(0)
sage: HH(D)
[3*z4]
sage: P4_11133.integrate( HH(D)^4 )
9
sage: P4_11133.integrate( HH(D) * HH(cone) )
1
Although computationally less efficient, we can do the same
computations with the rational Chow group::
sage: AA = P4_11133.Chow_group(QQ)
sage: map(AA, P4_11133.fan(1)) # long time (5s on sage.math, 2012)
[( 0 | 0 | 0 | 3 | 0 ), ( 0 | 0 | 0 | 3 | 0 ), ( 0 | 0 | 0 | 1 | 0 ), ( 0 | 0 | 0 | 1 | 0 ), ( 0 | 0 | 0 | 1 | 0 )]
sage: map(AA, P4_11133.fan(4)) # long time (5s on sage.math, 2012)
[( 1 | 0 | 0 | 0 | 0 ), ( 1 | 0 | 0 | 0 | 0 ), ( 1 | 0 | 0 | 0 | 0 ), ( 1 | 0 | 0 | 0 | 0 ), ( 1 | 0 | 0 | 0 | 0 )]
sage: AA(cone).intersection_with_divisor(D) # long time (4s on sage.math, 2013)
( 1 | 0 | 0 | 0 | 0 )
sage: AA(cone).intersection_with_divisor(D).count_points() # long time
1
The real advantage of the Chow group is that
* it works just as well over `\ZZ`, so torsion information is also
easily available, and
* its combinatorial description also works over worse-than-orbifold
singularities. By contrast, the cohomology groups can become very
complicated to compute in this case, and one usually only has a
spectral sequence but no toric algorithm.
Below you will find detailed descriptions of available functions. If you are
familiar with toric geometry, you will likely see that many important objects
and operations are unavailable. However, this module is under active
development and hopefully will improve in future releases of Sage. If there
are some particular features that you would like to see implemented ASAP,
please consider reporting them to the Sage Development Team or even
implementing them on your own as a patch for inclusion!
"""
#*****************************************************************************
# Copyright (C) 2010 Volker Braun <vbraun.name@gmail.com>
# Copyright (C) 2010 Andrey Novoseltsev <novoselt@gmail.com>
# Copyright (C) 2010 William Stein <wstein@gmail.com>
#
# Distributed under the terms of the GNU General Public License (GPL)
# as published by the Free Software Foundation; either version 2 of
# the License, or (at your option) any later version.
# http://www.gnu.org/licenses/
#*****************************************************************************
import sys
from sage.functions.all import factorial
from sage.geometry.cone import Cone, is_Cone
from sage.geometry.fan import Fan
from sage.matrix.all import matrix
from sage.misc.all import latex, prod, uniq, cached_method
from sage.structure.unique_representation import UniqueRepresentation
from sage.modules.free_module_element import vector
from sage.rings.all import Infinity, PolynomialRing, ZZ, QQ
from sage.rings.quotient_ring_element import QuotientRingElement
from sage.rings.quotient_ring import QuotientRing_generic
from sage.schemes.affine.affine_space import AffineSpace
from sage.schemes.generic.ambient_space import AmbientSpace
from sage.schemes.toric.homset import SchemeHomset_points_toric_field
from sage.categories.fields import Fields
from sage.misc.cachefunc import ClearCacheOnPickle
_Fields = Fields()
# Default prefix for indexed coordinates
DEFAULT_PREFIX = "z"
def is_ToricVariety(x):
r"""
Check if ``x`` is a toric variety.
INPUT:
- ``x`` -- anything.
OUTPUT:
- ``True`` if ``x`` is a :class:`toric variety <ToricVariety_field>` and
``False`` otherwise.
.. NOTE::
While projective spaces are toric varieties mathematically, they are
not toric varieties in Sage due to efficiency considerations, so this
function will return ``False``.
EXAMPLES::
sage: from sage.schemes.toric.variety import is_ToricVariety
sage: is_ToricVariety(1)
False
sage: fan = FaceFan(lattice_polytope.cross_polytope(2))
sage: P = ToricVariety(fan)
sage: P
2-d toric variety covered by 4 affine patches
sage: is_ToricVariety(P)
True
sage: is_ToricVariety(ProjectiveSpace(2))
False
"""
return isinstance(x, ToricVariety_field)
def ToricVariety(fan,
coordinate_names=None,
names=None,
coordinate_indices=None,
base_ring=QQ, base_field=None):
r"""
Construct a toric variety.
INPUT:
- ``fan`` -- :class:`rational polyhedral fan
<sage.geometry.fan.RationalPolyhedralFan>`;
- ``coordinate_names`` -- names of variables for the coordinate ring, see
:func:`normalize_names` for acceptable formats. If not given, indexed
variable names will be created automatically;
- ``names`` -- an alias of ``coordinate_names`` for internal
use. You may specify either ``names`` or ``coordinate_names``,
but not both;
- ``coordinate_indices`` -- list of integers, indices for indexed
variables. If not given, the index of each variable will coincide with
the index of the corresponding ray of the fan;
- ``base_ring`` -- base ring of the toric variety (default:
`\QQ`). Must be a field.
- ``base_field`` -- alias for ``base_ring``. Takes precedence if
both are specified.
OUTPUT:
- :class:`toric variety <ToricVariety_field>`.
EXAMPLES:
We will create the product of two projective lines::
sage: fan = FaceFan(lattice_polytope.cross_polytope(2))
sage: fan.rays()
M( 1, 0),
M( 0, 1),
M(-1, 0),
M( 0, -1)
in 2-d lattice M
sage: P1xP1 = ToricVariety(fan)
sage: P1xP1.gens()
(z0, z1, z2, z3)
Let's create some points::
sage: P1xP1(1,1,1,1)
[1 : 1 : 1 : 1]
sage: P1xP1(0,1,1,1)
[0 : 1 : 1 : 1]
sage: P1xP1(0,1,0,1)
Traceback (most recent call last):
...
TypeError: coordinates (0, 1, 0, 1)
are in the exceptional set!
We cannot set to zero both coordinates of the same projective line!
Let's change the names of the variables. We have to re-create our toric
variety::
sage: P1xP1 = ToricVariety(fan, "x s y t")
sage: P1xP1.gens()
(x, s, y, t)
Now `(x, y)` correspond to one line and `(s, t)` to the other one. ::
sage: P1xP1.inject_variables()
Defining x, s, y, t
sage: P1xP1.subscheme(x*s-y*t)
Closed subscheme of 2-d toric variety
covered by 4 affine patches defined by:
x*s - y*t
Here is a shorthand for defining the toric variety and homogeneous
coordinates in one go::
sage: P1xP1.<a,b,c,d> = ToricVariety(fan)
sage: (a^2+b^2) * (c+d)
a^2*c + b^2*c + a^2*d + b^2*d
"""
if base_field is not None:
base_ring = base_field
if names is not None:
if coordinate_names is not None:
raise ValueError('You must not specify both coordinate_names and names!')
coordinate_names = names
if base_ring not in _Fields:
raise TypeError("need a field to construct a toric variety!\n Got %s"
% base_ring)
return ToricVariety_field(fan, coordinate_names, coordinate_indices,
base_ring)
def AffineToricVariety(cone, *args, **kwds):
r"""
Construct an affine toric variety.
INPUT:
- ``cone`` -- :class:`strictly convex rational polyhedral cone
<sage.geometry.cone.ConvexRationalPolyhedralCone>`.
This cone will be used to construct a :class:`rational polyhedral fan
<sage.geometry.fan.RationalPolyhedralFan>`, which will be passed to
:func:`ToricVariety` with the rest of positional and keyword arguments.
OUTPUT:
- :class:`toric variety <ToricVariety_field>`.
.. NOTE::
The generating rays of the fan of this variety are guaranteed to be
listed in the same order as the rays of the original cone.
EXAMPLES:
We will create the affine plane as an affine toric variety::
sage: quadrant = Cone([(1,0), (0,1)])
sage: A2 = AffineToricVariety(quadrant)
sage: origin = A2(0,0)
sage: origin
[0 : 0]
sage: parent(origin)
Set of rational points of 2-d affine toric variety
Only affine toric varieties have points whose (homogeneous) coordinates
are all zero.
"""
if not cone.is_strictly_convex():
raise ValueError("affine toric varieties are defined for strictly "
"convex cones only!")
# We make sure that Fan constructor does not meddle with the order of
# rays, this is very important for affine patches construction
fan = Fan([tuple(range(cone.nrays()))], cone.rays(),
check=False, normalize=False)
return ToricVariety(fan, *args, **kwds)
class ToricVariety_field(ClearCacheOnPickle, AmbientSpace):
r"""
Construct a toric variety associated to a rational polyhedral fan.
.. WARNING::
This class does not perform any checks of correctness of input. Use
:func:`ToricVariety` and :func:`AffineToricVariety` to construct toric
varieties.
INPUT:
- ``fan`` -- :class:`rational polyhedral fan
<sage.geometry.fan.RationalPolyhedralFan>`;
- ``coordinate_names`` -- names of variables, see :func:`normalize_names`
for acceptable formats. If ``None``, indexed variable names will be
created automatically;
- ``coordinate_indices`` -- list of integers, indices for indexed
variables. If ``None``, the index of each variable will coincide with
the index of the corresponding ray of the fan;
- ``base_field`` -- base field of the toric variety.
OUTPUT:
- :class:`toric variety <ToricVariety_field>`.
TESTS::
sage: fan = FaceFan(lattice_polytope.cross_polytope(2))
sage: P1xP1 = ToricVariety(fan)
"""
def __init__(self, fan, coordinate_names, coordinate_indices, base_field):
r"""
See :class:`ToricVariety_field` for documentation.
TESTS::
sage: fan = FaceFan(lattice_polytope.cross_polytope(2))
sage: P1xP1 = ToricVariety(fan)
"""
self._fan = fan
super(ToricVariety_field, self).__init__(fan.lattice_dim(),
base_field)
self._torus_factor_dim = fan.lattice_dim() - fan.dim()
coordinate_names = normalize_names(coordinate_names,
fan.nrays() + self._torus_factor_dim, DEFAULT_PREFIX,
coordinate_indices, return_prefix=True)
# Save the prefix for use in resolutions
self._coordinate_prefix = coordinate_names.pop()
self._assign_names(names=coordinate_names, normalize=False)
def __cmp__(self, right):
r"""
Compare ``self`` and ``right``.
INPUT:
- ``right`` -- anything.
OUTPUT:
- 0 if ``right`` is of the same type as ``self``, their fans are the
same, names of variables are the same and stored in the same order,
and base fields are the same. 1 or -1 otherwise.
TESTS::
sage: fan = FaceFan(lattice_polytope.cross_polytope(2))
sage: P1xP1 = ToricVariety(fan)
sage: P1xP1a = ToricVariety(fan, "x s y t")
sage: P1xP1b = ToricVariety(fan)
sage: cmp(P1xP1, P1xP1a)
1
sage: cmp(P1xP1a, P1xP1)
-1
sage: cmp(P1xP1, P1xP1b)
0
sage: P1xP1 is P1xP1b
False
sage: cmp(P1xP1, 1) * cmp(1, P1xP1)
-1
"""
c = cmp(type(self), type(right))
if c:
return c
return cmp([self.fan(),
self.variable_names(),
self.base_ring()],
[right.fan(),
right.variable_names(),
right.base_ring()])
def _an_element_(self):
r"""
Construct an element of ``self``.
This function is needed (in particular) for the test framework.
OUTPUT:
- a point of ``self`` with coordinates [1 : 2: ... : n].
TESTS::
sage: P1xP1 = toric_varieties.P1xP1()
sage: P1xP1._an_element_()
[1 : 2 : 3 : 4]
"""
return self(range(1, self.ngens() + 1))
def _check_satisfies_equations(self, coordinates):
r"""
Check if ``coordinates`` define a valid point of ``self``.
INPUT:
- ``coordinates`` -- list of elements of the base field of ``self``.
OUTPUT:
- ``True`` if ``coordinates`` do define a valid point of ``self``,
otherwise a ``TypeError`` or ``ValueError`` exception is raised.
TESTS::
sage: P1xP1 = toric_varieties.P1xP1()
sage: P1xP1._check_satisfies_equations([1,1,1,1])
True
sage: P1xP1._check_satisfies_equations([0,1,0,1])
True
sage: P1xP1._check_satisfies_equations([0,0,1,1])
Traceback (most recent call last):
...
TypeError: coordinates (0, 0, 1, 1)
are in the exceptional set!
sage: P1xP1._check_satisfies_equations([1,1,1])
Traceback (most recent call last):
...
TypeError: coordinates (1, 1, 1) must have 4 components!
sage: P1xP1._check_satisfies_equations(1)
Traceback (most recent call last):
...
TypeError: 1 can not be used as coordinates!
Use a list or a tuple.
sage: P1xP1._check_satisfies_equations([1,1,1,P1xP1.fan()])
Traceback (most recent call last):
...
TypeError: coordinate Rational polyhedral fan
in 2-d lattice N is not an element of Rational Field!
"""
try:
coordinates = tuple(coordinates)
except TypeError:
raise TypeError("%s can not be used as coordinates! "
"Use a list or a tuple." % coordinates)
n = self.ngens()
if len(coordinates) != n:
raise TypeError("coordinates %s must have %d components!"
% (coordinates, n))
base_field = self.base_ring()
for coordinate in coordinates:
if coordinate not in base_field:
raise TypeError("coordinate %s is not an element of %s!"
% (coordinate, base_field))
zero_positions = set(position
for position, coordinate in enumerate(coordinates)
if coordinate == 0)
if not zero_positions:
return True
for i in range(n - self._torus_factor_dim, n):
if i in zero_positions:
raise ValueError("coordinates on the torus factor cannot be "
"zero! Got %s" % str(coordinates))
if len(zero_positions) == 1:
return True
fan = self.fan()
possible_charts = set(fan._ray_to_cones(zero_positions.pop()))
for i in zero_positions:
possible_charts.intersection_update(fan._ray_to_cones(i))
if possible_charts:
return True # All zeros are inside one generating cone
raise TypeError("coordinates %s are in the exceptional set!"
% str(coordinates)) # Need str, coordinates is a tuple
def _point_homset(self, *args, **kwds):
r"""
Construct a Hom-set for ``self``.
INPUT:
- same as for
:class:`~sage.schemes.generic.homset.SchemeHomset_points_toric_field`.
OUPUT:
-
:class:`~sage.schemes.generic.homset.SchemeHomset_points_toric_field`.
TESTS::
sage: P1xA1 = toric_varieties.P1xA1()
sage: P1xA1._point_homset(Spec(QQ), P1xA1)
Set of rational points of 2-d toric variety
covered by 2 affine patches
"""
return SchemeHomset_points_toric_field(*args, **kwds)
def _latex_(self):
r"""
Return a LaTeX representation of ``self``.
OUTPUT:
- string.
TESTS::
sage: P1xA1 = toric_varieties.P1xA1()
sage: print P1xA1._latex_()
\mathbb{X}_{\Sigma^{2}}
"""
return r"\mathbb{X}_{%s}" % latex(self.fan())
def _latex_generic_point(self, coordinates=None):
"""
Return a LaTeX representation of a point of ``self``.
INPUT:
- ``coordinates`` -- list of coordinates of a point of ``self``.
If not given, names of coordinates of ``self`` will be used.
OUTPUT:
- string.
EXAMPLES::
sage: P1xA1 = toric_varieties.P1xA1()
sage: print P1xA1._latex_generic_point()
\left[s : t : z\right]
sage: print P1xA1._latex_generic_point([1,2,3])
\left[1 : 2 : 3\right]
"""
if coordinates is None:
coordinates = self.gens()
return r"\left[%s\right]" % (" : ".join(str(latex(coord))
for coord in coordinates))
def _point(self, *args, **kwds):
r"""
Construct a point of ``self``.
INPUT:
- same as for
:class:`~sage.schemes.generic.morphism.SchemeMorphism_point_toric_field`.
OUPUT:
:class:`~sage.schemes.generic.morphism.SchemeMorphism_point_toric_field`.
TESTS::
sage: P1xP1 = toric_varieties.P1xP1()
sage: P1xP1._point(P1xP1, [1,2,3,4])
[1 : 2 : 3 : 4]
"""
from sage.schemes.toric.morphism import SchemeMorphism_point_toric_field
return SchemeMorphism_point_toric_field(*args, **kwds)
def _homset(self, *args, **kwds):
r"""
Return the homset between two toric varieties.
INPUT:
Same as :class:`sage.schemes.generic.homset.SchemeHomset_generic`.
OUTPUT:
A :class:`sage.schemes.toric.homset.SchemeHomset_toric_variety`.
EXAMPLES::
sage: P1xP1 = toric_varieties.P1xP1()
sage: P1 = toric_varieties.P1()
sage: hom_set = P1xP1.Hom(P1); hom_set
Set of morphisms
From: 2-d CPR-Fano toric variety covered by 4 affine patches
To: 1-d CPR-Fano toric variety covered by 2 affine patches
sage: type(hom_set)
<class 'sage.schemes.toric.homset.SchemeHomset_toric_variety_with_category'>
This is also the Hom-set for algebraic subschemes of toric varieties::
sage: P1xP1.inject_variables()
Defining s, t, x, y
sage: P1 = P1xP1.subscheme(s-t)
sage: hom_set = P1xP1.Hom(P1)
sage: hom_set([s,s,x,y])
Scheme morphism:
From: 2-d CPR-Fano toric variety covered by 4 affine patches
To: Closed subscheme of 2-d CPR-Fano toric variety covered by 4 affine patches defined by:
s - t
Defn: Defined on coordinates by sending [s : t : x : y] to
[s : s : x : y]
sage: hom_set = P1.Hom(P1)
sage: hom_set([s,s,x,y])
Scheme endomorphism of Closed subscheme of 2-d CPR-Fano toric
variety covered by 4 affine patches defined by:
s - t
Defn: Defined on coordinates by sending [s : t : x : y] to
[t : t : x : y]
"""
from sage.schemes.toric.homset import SchemeHomset_toric_variety
return SchemeHomset_toric_variety(*args, **kwds)
def _repr_(self):
r"""
Return a string representation of ``self``.
OUTPUT:
- string.
TESTS::
sage: P1xA1 = toric_varieties.P1xA1()
sage: print P1xA1._repr_()
2-d toric variety covered by 2 affine patches
"""
result = "%d-d" % self.dimension_relative()
if self.fan().ngenerating_cones() == 1:
result += " affine toric variety"
else:
result += (" toric variety covered by %d affine patches"
% self.fan().ngenerating_cones())
return result
def _repr_generic_point(self, coordinates=None):
r"""
Return a string representation of a point of ``self``.
INPUT:
- ``coordinates`` -- list of coordinates of a point of ``self``.
If not given, names of coordinates of ``self`` will be used.
OUTPUT:
- string.
EXAMPLES::
sage: P1xP1 = toric_varieties.P1xP1()
sage: print P1xP1._repr_generic_point()
[s : t : x : y]
sage: print P1xP1._repr_generic_point([1,2,3,4])
[1 : 2 : 3 : 4]
"""
if coordinates is None:
coordinates = self.gens()
return "[%s]" % (" : ".join(str(coord) for coord in coordinates))
def _validate(self, polynomials):
"""
Check if ``polynomials`` define valid functions on ``self``.
Since this is a toric variety, polynomials must be homogeneous in the
total coordinate ring of ``self``.
INPUT:
- ``polynomials`` -- list of polynomials in the coordinate ring of
``self`` (this function does not perform any conversions).
OUTPUT:
- ``polynomials`` (the input parameter without any modifications) if
``polynomials`` do define valid polynomial functions on ``self``,
otherwise a ``ValueError`` exception is raised.
TESTS:
We will use the product of two projective lines with coordinates
`(x, y)` for one and `(s, t)` for the other::
sage: P1xP1 = toric_varieties.P1xP1("x y s t")
sage: P1xP1.inject_variables()
Defining x, y, s, t
sage: P1xP1._validate([x - y, x*s + y*t])
[x - y, x*s + y*t]
sage: P1xP1._validate([x + s])
Traceback (most recent call last):
...
ValueError: x + s is not homogeneous on
2-d CPR-Fano toric variety covered by 4 affine patches!
"""
for p in polynomials:
if not self.is_homogeneous(p):
raise ValueError("%s is not homogeneous on %s!" % (p, self))
return polynomials
def affine_patch(self, i):
r"""
Return the ``i``-th affine patch of ``self``.
INPUT:
- ``i`` -- integer, index of a generating cone of the fan of ``self``.
OUTPUT:
- affine :class:`toric variety <ToricVariety_field>` corresponding to
the ``i``-th generating cone of the fan of ``self``.
The result is cached, so the ``i``-th patch is always the same object
in memory.
See also :meth:`affine_algebraic_patch`, which expresses the
patches as subvarieties of affine space instead.
EXAMPLES::
sage: fan = FaceFan(lattice_polytope.cross_polytope(2))
sage: P1xP1 = ToricVariety(fan, "x s y t")
sage: patch0 = P1xP1.affine_patch(0)
sage: patch0
2-d affine toric variety
sage: patch0.embedding_morphism()
Scheme morphism:
From: 2-d affine toric variety
To: 2-d toric variety covered by 4 affine patches
Defn: Defined on coordinates by sending [x : t] to
[x : 1 : 1 : t]
sage: patch1 = P1xP1.affine_patch(1)
sage: patch1.embedding_morphism()
Scheme morphism:
From: 2-d affine toric variety
To: 2-d toric variety covered by 4 affine patches
Defn: Defined on coordinates by sending [y : t] to
[1 : 1 : y : t]
sage: patch1 is P1xP1.affine_patch(1)
True
"""
i = int(i) # implicit type checking
try:
return self._affine_patches[i]
except AttributeError:
self._affine_patches = dict()
except KeyError:
pass
cone = self.fan().generating_cone(i)
names = self.variable_names()
# Number of "honest fan coordinates"
n = self.fan().nrays()
# Number of "torus factor coordinates"
t = self._torus_factor_dim
names = ([names[ray] for ray in cone.ambient_ray_indices()]
+ list(names[n:]))
patch = AffineToricVariety(cone, names, base_field=self.base_ring())
embedding_coordinates = [1] * n