This repository has been archived by the owner on Jan 30, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
algebraic_scheme.py
3540 lines (2920 loc) · 125 KB
/
algebraic_scheme.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
r"""
Algebraic schemes
An algebraic scheme is defined by a set of polynomials in some
suitable affine or projective coordinates. Possible ambient spaces are
* Affine spaces (:class:`AffineSpace
<sage.schemes.affine.affine_space.AffineSpace_generic>`),
* Projective spaces (:class:`ProjectiveSpace
<sage.schemes.projective.projective_space.ProjectiveSpace_ring>`), or
* Toric varieties (:class:`ToricVariety
<sage.schemes.toric.variety.ToricVariety_field>`).
Note that while projective spaces are of course toric varieties themselves,
they are implemented differently in Sage due to efficiency considerations.
You still can create a projective space as a toric variety if you wish.
In the following, we call the corresponding subschemes affine
algebraic schemes, projective algebraic schemes, or toric algebraic
schemes. In the future other ambient spaces, perhaps by means of
gluing relations, may be intoduced.
Generally, polynomials `p_0, p_1, \dots, p_n` define an ideal
`I=\left<p_0, p_1, \dots, p_n\right>`. In the projective and toric case, the
polynomials (and, therefore, the ideal) must be homogeneous. The
associated subscheme `V(I)` of the ambient space is, roughly speaking,
the subset of the ambient space on which all polynomials vanish simultaneously.
.. WARNING::
You should not construct algebraic scheme objects directly. Instead, use
``.subscheme()`` methods of ambient spaces. See below for examples.
EXAMPLES:
We first construct the ambient space, here the affine space `\QQ^2`::
sage: A2 = AffineSpace(2, QQ, 'x, y')
sage: A2.coordinate_ring().inject_variables()
Defining x, y
Now we can write polynomial equations in the variables `x` and `y`. For
example, one equation cuts out a curve (a one-dimensional subscheme)::
sage: V = A2.subscheme([x^2+y^2-1]); V
Closed subscheme of Affine Space of dimension 2
over Rational Field defined by:
x^2 + y^2 - 1
sage: V.dimension()
1
Here is a more complicated example in a projective space::
sage: P3 = ProjectiveSpace(3, QQ, 'x')
sage: P3.inject_variables()
Defining x0, x1, x2, x3
sage: Q = matrix([[x0, x1, x2], [x1, x2, x3]]).minors(2); Q
[-x1^2 + x0*x2, -x1*x2 + x0*x3, -x2^2 + x1*x3]
sage: twisted_cubic = P3.subscheme(Q)
sage: twisted_cubic
Closed subscheme of Projective Space of dimension 3
over Rational Field defined by:
-x1^2 + x0*x2,
-x1*x2 + x0*x3,
-x2^2 + x1*x3
sage: twisted_cubic.dimension()
1
Note that there are 3 equations in the 3-dimensional ambient space,
yet the subscheme is 1-dimensional. One can show that it is not
possible to eliminate any of the equations, that is, the twisted cubic
is **not** a complete intersection of two polynomial equations.
Let us look at one affine patch, for example the one where `x_0=1` ::
sage: patch = twisted_cubic.affine_patch(0)
sage: patch
Closed subscheme of Affine Space of dimension 3
over Rational Field defined by:
-x0^2 + x1,
-x0*x1 + x2,
-x1^2 + x0*x2
sage: patch.embedding_morphism()
Scheme morphism:
From: Closed subscheme of Affine Space of dimension 3
over Rational Field defined by:
-x0^2 + x1,
-x0*x1 + x2,
-x1^2 + x0*x2
To: Closed subscheme of Projective Space of dimension 3
over Rational Field defined by:
-x1^2 + x0*x2,
-x1*x2 + x0*x3,
-x2^2 + x1*x3
Defn: Defined on coordinates by sending (x0, x1, x2) to
(1 : x0 : x1 : x2)
AUTHORS:
- David Kohel (2005): initial version.
- William Stein (2005): initial version.
- Andrey Novoseltsev (2010-05-17): subschemes of toric varieties.
- Volker Braun (2010-12-24): documentation of schemes and
refactoring. Added coordinate neighborhoods and is_smooth()
- Ben Hutz (2014): subschemes of cartesian products of projective space
"""
#*****************************************************************************
# Copyright (C) 2010 Volker Braun <vbraun.name@gmail.com>
# Copyright (C) 2005 David Kohel <kohel@maths.usyd.edu.au>
# Copyright (C) 2010 Andrey Novoseltsev <novoselt@gmail.com>
# Copyright (C) 2005 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/
#*****************************************************************************
#*** A quick overview over the class hierarchy:
# class AlgebraicScheme(scheme.Scheme)
# class AlgebraicScheme_subscheme
# class AlgebraicScheme_subscheme_affine
# class AlgebraicScheme_subscheme_projective
# class AlgebraicScheme_subscheme_toric
# class AlgebraicScheme_subscheme_affine_toric
# class AlgebraicScheme_quasi
from copy import copy
from sage.categories.number_fields import NumberFields
from sage.rings.all import ZZ
from sage.rings.ideal import is_Ideal
from sage.rings.rational_field import is_RationalField
from sage.rings.polynomial.multi_polynomial_ring import is_MPolynomialRing
from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing
from sage.rings.finite_rings.constructor import is_FiniteField
from sage.misc.cachefunc import cached_method
from sage.misc.latex import latex
from sage.misc.misc import is_iterator
from sage.structure.all import Sequence
from sage.calculus.functions import jacobian
import sage.schemes.projective
import sage.schemes.affine
import ambient_space
import scheme
#*******************************************************************
def is_AlgebraicScheme(x):
"""
Test whether ``x`` is an algebraic scheme.
INPUT:
- ``x`` -- anything.
OUTPUT:
Boolean. Whether ``x`` is an an algebraic scheme, that is, a
subscheme of an ambient space over a ring defined by polynomial
equations.
EXAMPLES::
sage: A2 = AffineSpace(2, QQ, 'x, y')
sage: A2.coordinate_ring().inject_variables()
Defining x, y
sage: V = A2.subscheme([x^2+y^2]); V
Closed subscheme of Affine Space of dimension 2 over Rational Field defined by:
x^2 + y^2
sage: from sage.schemes.generic.algebraic_scheme import is_AlgebraicScheme
sage: is_AlgebraicScheme(V)
True
Affine space is itself not an algebraic scheme, though the closed
subscheme defined by no equations is::
sage: from sage.schemes.generic.algebraic_scheme import is_AlgebraicScheme
sage: is_AlgebraicScheme(AffineSpace(10, QQ))
False
sage: V = AffineSpace(10, QQ).subscheme([]); V
Closed subscheme of Affine Space of dimension 10 over Rational Field defined by:
(no polynomials)
sage: is_AlgebraicScheme(V)
True
We create a more complicated closed subscheme::
sage: A,x = AffineSpace(10, QQ).objgens()
sage: X = A.subscheme([sum(x)]); X
Closed subscheme of Affine Space of dimension 10 over Rational Field defined by:
x0 + x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9
sage: is_AlgebraicScheme(X)
True
::
sage: is_AlgebraicScheme(QQ)
False
sage: S = Spec(QQ)
sage: is_AlgebraicScheme(S)
False
"""
return isinstance(x, AlgebraicScheme)
#*******************************************************************
class AlgebraicScheme(scheme.Scheme):
"""
An algebraic scheme presented as a subscheme in an ambient space.
This is the base class for all algebraic schemes, that is, schemes
defined by equations in affine, projective, or toric ambient
spaces.
"""
def __init__(self, A):
"""
TESTS::
sage: from sage.schemes.generic.algebraic_scheme import AlgebraicScheme
sage: P = ProjectiveSpace(3, ZZ)
sage: P.category()
Category of schemes over Integer Ring
sage: S = AlgebraicScheme(P); S
Subscheme of Projective Space of dimension 3 over Integer Ring
sage: S.category()
Category of schemes over Integer Ring
"""
if not ambient_space.is_AmbientSpace(A):
raise TypeError("A (=%s) must be an ambient space")
self.__A = A
self.__divisor_group = {}
scheme.Scheme.__init__(self, A.base_scheme())
def _latex_(self):
"""
Return a LaTeX representation of this algebraic scheme.
TESTS::
sage: from sage.schemes.generic.algebraic_scheme import AlgebraicScheme
sage: P = ProjectiveSpace(3, ZZ)
sage: S = AlgebraicScheme(P); S
Subscheme of Projective Space of dimension 3 over Integer Ring
sage: S._latex_()
'\text{Subscheme of } {\\mathbf P}_{\\Bold{Z}}^3'
"""
return "\text{Subscheme of } %s" % latex(self.__A)
def is_projective(self):
"""
Return True if self is presented as a subscheme of an ambient
projective space.
OUTPUT:
Boolean.
EXAMPLES::
sage: PP.<x,y,z,w> = ProjectiveSpace(3,QQ)
sage: f = x^3 + y^3 + z^3 + w^3
sage: R = f.parent()
sage: I = [f] + [f.derivative(zz) for zz in PP.gens()]
sage: V = PP.subscheme(I)
sage: V.is_projective()
True
sage: AA.<x,y,z,w> = AffineSpace(4,QQ)
sage: V = AA.subscheme(I)
sage: V.is_projective()
False
Note that toric varieties are implemented differently than
projective spaces. This is why this method returns ``False``
for toric varieties::
sage: PP.<x,y,z,w> = toric_varieties.P(3)
sage: V = PP.subscheme(x^3 + y^3 + z^3 + w^3)
sage: V.is_projective()
False
"""
return self.ambient_space().is_projective()
def coordinate_ring(self):
"""
Return the coordinate ring of this algebraic scheme. The
result is cached.
OUTPUT:
The coordinate ring. Usually a polynomial ring, or a quotient
thereof.
EXAMPLES::
sage: P.<x, y, z> = ProjectiveSpace(2, ZZ)
sage: S = P.subscheme([x-y, x-z])
sage: S.coordinate_ring()
Quotient of Multivariate Polynomial Ring in x, y, z over Integer Ring by the ideal (x - y, x - z)
"""
try:
return self._coordinate_ring
except AttributeError:
R = self.__A.coordinate_ring()
I = self.defining_ideal()
Q = R.quotient(I)
self._coordinate_ring = Q
return Q
def ambient_space(self):
"""
Return the ambient space of this algebraic scheme.
EXAMPLES::
sage: A.<x, y> = AffineSpace(2, GF(5))
sage: S = A.subscheme([])
sage: S.ambient_space()
Affine Space of dimension 2 over Finite Field of size 5
sage: P.<x, y, z> = ProjectiveSpace(2, ZZ)
sage: S = P.subscheme([x-y, x-z])
sage: S.ambient_space() is P
True
"""
return self.__A
def embedding_morphism(self):
r"""
Return the default embedding morphism of ``self``.
If the scheme `Y` was constructed as a neighbourhood of a
point `p \in X`, then :meth:`embedding_morphism` returns a
local isomorphism `f:Y\to X` around the preimage point
`f^{-1}(p)`. The latter is returned by
:meth:`embedding_center`.
If the algebraic scheme `Y` was not constructed as a
neighbourhood of a point, then the embedding in its
:meth:`ambient_space` is returned.
OUTPUT:
A scheme morphism whose
:meth:`~morphism.SchemeMorphism.domain` is ``self``.
* By default, it is the tautological embedding into its own
ambient space :meth:`ambient_space`.
* If the algebraic scheme (which itself is a subscheme of an
auxiliary :meth:`ambient_space`) was constructed as a patch
or neighborhood of a point then the embedding is the
embedding into the original scheme.
* A ``NotImplementedError`` is raised if the construction of
the embedding morphism is not implemented yet.
EXAMPLES::
sage: A2.<x,y> = AffineSpace(QQ,2)
sage: C = A2.subscheme(x^2+y^2-1)
sage: C.embedding_morphism()
Scheme morphism:
From: Closed subscheme of Affine Space of dimension 2 over Rational Field defined by:
x^2 + y^2 - 1
To: Affine Space of dimension 2 over Rational Field
Defn: Defined on coordinates by sending (x, y) to
(x, y)
sage: P1xP1.<x,y,u,v> = toric_varieties.P1xP1()
sage: P1 = P1xP1.subscheme(x-y)
sage: P1.embedding_morphism()
Scheme morphism:
From: Closed subscheme of 2-d CPR-Fano toric variety covered
by 4 affine patches defined by:
x - y
To: 2-d CPR-Fano toric variety covered by 4 affine patches
Defn: Defined on coordinates by sending [x : y : u : v] to
[y : y : u : v]
So far, the embedding was just in the own ambient space. Now a
bit more interesting examples::
sage: P2.<x,y,z> = ProjectiveSpace(QQ,2)
sage: X = P2.subscheme((x^2-y^2)*z)
sage: p = (1,1,0)
sage: nbhd = X.neighborhood(p)
sage: nbhd
Closed subscheme of Affine Space of dimension 2 over Rational Field defined by:
-x0^2*x1 - 2*x0*x1
Note that `p=(1,1,0)` is a singular point of `X`. So the
neighborhood of `p` is not just affine space. The
:meth:neighborhood` method returns a presentation of
the neighborhood as a subscheme of an auxiliary 2-dimensional
affine space::
sage: nbhd.ambient_space()
Affine Space of dimension 2 over Rational Field
But its :meth:`embedding_morphism` is not into this auxiliary
affine space, but the original subscheme `X`::
sage: nbhd.embedding_morphism()
Scheme morphism:
From: Closed subscheme of Affine Space of dimension 2 over Rational Field defined by:
-x0^2*x1 - 2*x0*x1
To: Closed subscheme of Projective Space of dimension 2 over Rational Field defined by:
x^2*z - y^2*z
Defn: Defined on coordinates by sending (x0, x1) to
(1 : x0 + 1 : x1)
A couple more examples::
sage: patch1 = P1xP1.affine_patch(1)
sage: patch1
2-d affine toric variety
sage: patch1.embedding_morphism()
Scheme morphism:
From: 2-d affine toric variety
To: 2-d CPR-Fano toric variety covered by 4 affine patches
Defn: Defined on coordinates by sending [y : u] to
[1 : y : u : 1]
sage: subpatch = P1.affine_patch(1)
sage: subpatch
Closed subscheme of 2-d affine toric variety defined by:
-y + 1
sage: subpatch.embedding_morphism()
Scheme morphism:
From: Closed subscheme of 2-d affine toric variety defined by:
-y + 1
To: Closed subscheme of 2-d CPR-Fano toric variety covered
by 4 affine patches defined by:
x - y
Defn: Defined on coordinates by sending [y : u] to
[1 : y : u : 1]
"""
if '_embedding_morphism' in self.__dict__:
hom = self._embedding_morphism
if isinstance(hom, tuple):
raise hom[0]
return hom
ambient = self.ambient_space()
return self.hom(ambient.coordinate_ring().gens(), ambient)
def embedding_center(self):
r"""
Return the distinguished point, if there is any.
If the scheme `Y` was constructed as a neighbourhood of a
point `p \in X`, then :meth:`embedding_morphism` returns a
local isomorphism `f:Y\to X` around the preimage point
`f^{-1}(p)`. The latter is returned by
:meth:`embedding_center`.
OUTPUT:
A point of ``self``. Raises ``AttributeError`` if there is no
distinguished point, depending on how ``self`` was
constructed.
EXAMPLES::
sage: P3.<w,x,y,z> = ProjectiveSpace(QQ,3)
sage: X = P3.subscheme( (w^2-x^2)*(y^2-z^2) )
sage: p = [1,-1,3,4]
sage: nbhd = X.neighborhood(p); nbhd
Closed subscheme of Affine Space of dimension 3 over Rational Field defined by:
x0^2*x2^2 - x1^2*x2^2 + 6*x0^2*x2 - 6*x1^2*x2 + 2*x0*x2^2 +
2*x1*x2^2 - 7*x0^2 + 7*x1^2 + 12*x0*x2 + 12*x1*x2 - 14*x0 - 14*x1
sage: nbhd.embedding_center()
(0, 0, 0)
sage: nbhd.embedding_morphism()(nbhd.embedding_center())
(1/4 : -1/4 : 3/4 : 1)
sage: nbhd.embedding_morphism()
Scheme morphism:
From: Closed subscheme of Affine Space of dimension 3 over Rational Field defined by:
x0^2*x2^2 - x1^2*x2^2 + 6*x0^2*x2 - 6*x1^2*x2 + 2*x0*x2^2 +
2*x1*x2^2 - 7*x0^2 + 7*x1^2 + 12*x0*x2 + 12*x1*x2 - 14*x0 - 14*x1
To: Closed subscheme of Projective Space of dimension 3 over Rational Field defined by:
w^2*y^2 - x^2*y^2 - w^2*z^2 + x^2*z^2
Defn: Defined on coordinates by sending (x0, x1, x2) to
(x0 + 1 : x1 - 1 : x2 + 3 : 4)
"""
if '_embedding_center' in self.__dict__:
return self._embedding_center
raise AttributeError('This algebraic scheme does not have a designated point.')
def ngens(self):
"""
Return the number of generators of the ambient space of this
algebraic scheme.
EXAMPLES::
sage: A.<x, y> = AffineSpace(2, GF(5))
sage: S = A.subscheme([])
sage: S.ngens()
2
sage: P.<x, y, z> = ProjectiveSpace(2, ZZ)
sage: S = P.subscheme([x-y, x-z])
sage: P.ngens()
3
"""
return self.__A.ngens()
def _repr_(self):
"""
Return a string representation of this algebraic scheme.
TESTS::
sage: from sage.schemes.generic.algebraic_scheme import AlgebraicScheme
sage: P = ProjectiveSpace(3, ZZ)
sage: S = AlgebraicScheme(P); S
Subscheme of Projective Space of dimension 3 over Integer Ring
sage: S._repr_()
'Subscheme of Projective Space of dimension 3 over Integer Ring'
"""
return "Subscheme of %s"%self.__A
def _homset(self, *args, **kwds):
"""
Construct the Hom-set
INPUT:
Same as :class:`sage.schemes.generic.homset.SchemeHomset_generic`.
OUTPUT:
The Hom-set of the ambient space.
EXAMPLES::
sage: P1.<x,y> = toric_varieties.P1()
sage: type(P1.Hom(P1))
<class 'sage.schemes.toric.homset.SchemeHomset_toric_variety_with_category'>
sage: X = P1.subscheme(x-y)
sage: type(X.Hom(X))
<class 'sage.schemes.toric.homset.SchemeHomset_toric_variety_with_category'>
::
sage: P1xP1 = toric_varieties.P1xP1()
sage: P1 = toric_varieties.P1()
sage: P1xP1._homset(P1xP1,P1)
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
"""
return self.__A._homset(*args, **kwds)
def _point_homset(self, *args, **kwds):
"""
Construct a point Hom-set. For internal use only.
TESTS::
sage: P2.<x,y,z> = ProjectiveSpace(2, ZZ)
sage: P2._point_homset(Spec(ZZ), P2)
Set of rational points of Projective Space of dimension 2 over Integer Ring
"""
return self.__A._point_homset(*args, **kwds)
def _point(self, *args, **kwds):
r"""
Construct a point of ``self``. For internal use only.
TESTS::
sage: P2.<x,y,z> = ProjectiveSpace(2, QQ)
sage: point_homset = P2._point_homset(Spec(QQ), P2)
sage: P2._point(point_homset, [1,2,1])
(1 : 2 : 1)
"""
return self.__A._point(*args, **kwds)
#*******************************************************************
class AlgebraicScheme_quasi(AlgebraicScheme):
"""
The quasi-affine or quasi-projective scheme `X - Y`, where `X` and `Y`
are both closed subschemes of a common ambient affine or projective
space.
.. WARNING::
You should not create objects of this class directly. The
preferred method to construct such subschemes is to use
:meth:`complement` method of algebraic schemes.
OUTPUT:
An instance of :class:`AlgebraicScheme_quasi`.
EXAMPLES::
sage: P.<x, y, z> = ProjectiveSpace(2, ZZ)
sage: S = P.subscheme([])
sage: T = P.subscheme([x-y])
sage: T.complement(S)
Quasi-projective subscheme X - Y of Projective Space of dimension 2 over
Integer Ring, where X is defined by:
(no polynomials)
and Y is defined by:
x - y
"""
def __init__(self, X, Y):
"""
The constructor.
INPUT:
- ``X``, ``Y`` -- two subschemes of the same ambient space.
TESTS::
sage: P.<x, y, z> = ProjectiveSpace(2, ZZ)
sage: S = P.subscheme([])
sage: T = P.subscheme([x-y])
sage: from sage.schemes.generic.algebraic_scheme import AlgebraicScheme_quasi
sage: AlgebraicScheme_quasi(S, T)
Quasi-projective subscheme X - Y of Projective Space of dimension 2 over Integer Ring, where X is defined by:
(no polynomials)
and Y is defined by:
x - y
"""
self.__X = X
self.__Y = Y
if not isinstance(X, AlgebraicScheme_subscheme):
raise TypeError("X must be a closed subscheme of an ambient space.")
if not isinstance(Y, AlgebraicScheme_subscheme):
raise TypeError("Y must be a closed subscheme of an ambient space.")
if X.ambient_space() != Y.ambient_space():
raise ValueError("X and Y must be embedded in the same ambient space.")
# _latex_ and _repr_ assume all of the above conditions and should be
# probably changed if they are relaxed!
A = X.ambient_space()
self._base_ring = A.base_ring()
AlgebraicScheme.__init__(self, A)
def _latex_(self):
"""
Return a LaTeX representation of this algebraic scheme.
EXAMPLES::
sage: from sage.schemes.generic.algebraic_scheme import AlgebraicScheme_quasi
sage: P.<x, y, z> = ProjectiveSpace(2, ZZ)
sage: S = P.subscheme([])
sage: T = P.subscheme([x-y])
sage: U = AlgebraicScheme_quasi(S, T); U
Quasi-projective subscheme X - Y of Projective Space of dimension 2
over Integer Ring, where X is defined by:
(no polynomials)
and Y is defined by:
x - y
sage: U._latex_()
'\\text{Quasi-projective subscheme }
(X\\setminus Y)\\subset {\\mathbf P}_{\\Bold{Z}}^2,\\text{ where }
X \\text{ is defined by }\\text{no polynomials},\\text{ and }
Y \\text{ is defined by } x - y.'
"""
if sage.schemes.affine.affine_space.is_AffineSpace(self.ambient_space()):
t = "affine"
else:
t = "projective"
X = ', '.join(latex(f) for f in self.__X.defining_polynomials())
if not X:
X = r"\text{no polynomials}"
Y = ', '.join(latex(f) for f in self.__Y.defining_polynomials())
if not Y:
Y = r"\text{no polynomials}"
return (r"\text{Quasi-%s subscheme } (X\setminus Y)\subset %s,"
r"\text{ where } X \text{ is defined by }%s,"
r"\text{ and } Y \text{ is defined by } %s."
% (t, latex(self.ambient_space()), X, Y))
def _repr_(self):
"""
Return a string representation of this algebraic scheme.
EXAMPLES::
sage: from sage.schemes.generic.algebraic_scheme import AlgebraicScheme_quasi
sage: P.<x, y, z> = ProjectiveSpace(2, ZZ)
sage: S = P.subscheme([])
sage: T = P.subscheme([x-y])
sage: U = AlgebraicScheme_quasi(S, T); U
Quasi-projective subscheme X - Y of Projective Space of dimension 2 over Integer Ring, where X is defined by:
(no polynomials)
and Y is defined by:
x - y
sage: U._repr_()
'Quasi-projective subscheme X - Y of Projective Space of dimension 2 over Integer Ring, where X is defined by:\n (no polynomials)\nand Y is defined by:\n x - y'
"""
if sage.schemes.affine.affine_space.is_AffineSpace(self.ambient_space()):
t = "affine"
else:
t = "projective"
return ("Quasi-%s subscheme X - Y of %s, where X is defined by:\n%s\n"
"and Y is defined by:\n%s"
% (t, self.ambient_space(), str(self.__X).split("\n", 1)[1],
str(self.__Y).split("\n", 1)[1]))
def X(self):
"""
Return the scheme `X` such that self is represented as `X - Y`.
EXAMPLES::
sage: P.<x, y, z> = ProjectiveSpace(2, ZZ)
sage: S = P.subscheme([])
sage: T = P.subscheme([x-y])
sage: U = T.complement(S)
sage: U.X() is S
True
"""
return self.__X
def Y(self):
"""
Return the scheme `Y` such that self is represented as `X - Y`.
EXAMPLES::
sage: P.<x, y, z> = ProjectiveSpace(2, ZZ)
sage: S = P.subscheme([])
sage: T = P.subscheme([x-y])
sage: U = T.complement(S)
sage: U.Y() is T
True
"""
return self.__Y
def _check_satisfies_equations(self, v):
"""
Verify that the coordinates of v define a point on this scheme, or
raise a TypeError.
EXAMPLES::
sage: P.<x, y, z> = ProjectiveSpace(2, ZZ)
sage: S = P.subscheme([])
sage: T = P.subscheme([x-y])
sage: U = T.complement(S)
sage: U._check_satisfies_equations([1, 2, 0])
True
sage: U._check_satisfies_equations([1, 1, 0])
Traceback (most recent call last):
...
TypeError: Coordinates [1, 1, 0] do not define a point on
Quasi-projective subscheme X - Y of Projective Space of dimension 2
over Integer Ring, where X is defined by:
(no polynomials)
and Y is defined by:
x - y
sage: U._check_satisfies_equations([1, 4])
Traceback (most recent call last):
...
TypeError: number of arguments does not match number of variables in parent
sage: A.<x, y> = AffineSpace(2, GF(7))
sage: S = A.subscheme([x^2-y])
sage: T = A.subscheme([x-y])
sage: U = T.complement(S)
sage: U._check_satisfies_equations([2, 4])
True
sage: U.point([2,4])
(2, 4)
sage: U._check_satisfies_equations(_)
True
sage: U._check_satisfies_equations([1, 1])
Traceback (most recent call last):
...
TypeError: Coordinates [1, 1] do not define a point on Quasi-affine
subscheme X - Y of Affine Space of dimension 2 over Finite
Field of size 7, where X is defined by:
x^2 - y
and Y is defined by:
x - y
sage: U._check_satisfies_equations([1, 0])
Traceback (most recent call last):
...
TypeError: Coordinates [1, 0] do not define a point on Quasi-affine
subscheme X - Y of Affine Space of dimension 2 over Finite
Field of size 7, where X is defined by:
x^2 - y
and Y is defined by:
x - y
TESTS:
The bug reported at #12211 has been fixed::
sage: P.<x, y, z, w> = ProjectiveSpace(3, QQ)
sage: S = P.subscheme([x])
sage: T = P.subscheme([y, z])
sage: U = T.complement(S)
sage: U._check_satisfies_equations([0, 0, 1, 1])
True
"""
coords = list(v)
for f in self.__X.defining_polynomials():
if f(coords) != 0:
raise TypeError("Coordinates %s do not define a point on %s"%(v,self))
for f in self.__Y.defining_polynomials():
if f(coords) != 0:
return True
raise TypeError("Coordinates %s do not define a point on %s"%(v,self))
def rational_points(self, F=None, bound=0):
"""
Return the set of rational points on this algebraic scheme
over the field `F`.
EXAMPLES::
sage: A.<x, y> = AffineSpace(2, GF(7))
sage: S = A.subscheme([x^2-y])
sage: T = A.subscheme([x-y])
sage: U = T.complement(S)
sage: U.rational_points()
[(2, 4), (3, 2), (4, 2), (5, 4), (6, 1)]
sage: U.rational_points(GF(7^2, 'b'))
[(2, 4), (3, 2), (4, 2), (5, 4), (6, 1), (b, b + 4), (b + 1, 3*b + 5), (b + 2, 5*b + 1),
(b + 3, 6), (b + 4, 2*b + 6), (b + 5, 4*b + 1), (b + 6, 6*b + 5), (2*b, 4*b + 2),
(2*b + 1, b + 3), (2*b + 2, 5*b + 6), (2*b + 3, 2*b + 4), (2*b + 4, 6*b + 4),
(2*b + 5, 3*b + 6), (2*b + 6, 3), (3*b, 2*b + 1), (3*b + 1, b + 2), (3*b + 2, 5),
(3*b + 3, 6*b + 3), (3*b + 4, 5*b + 3), (3*b + 5, 4*b + 5), (3*b + 6, 3*b + 2),
(4*b, 2*b + 1), (4*b + 1, 3*b + 2), (4*b + 2, 4*b + 5), (4*b + 3, 5*b + 3),
(4*b + 4, 6*b + 3), (4*b + 5, 5), (4*b + 6, b + 2), (5*b, 4*b + 2), (5*b + 1, 3),
(5*b + 2, 3*b + 6), (5*b + 3, 6*b + 4), (5*b + 4, 2*b + 4), (5*b + 5, 5*b + 6),
(5*b + 6, b + 3), (6*b, b + 4), (6*b + 1, 6*b + 5), (6*b + 2, 4*b + 1), (6*b + 3, 2*b + 6),
(6*b + 4, 6), (6*b + 5, 5*b + 1), (6*b + 6, 3*b + 5)]
"""
if F is None:
F = self.base_ring()
if bound == 0:
if is_RationalField(F):
raise TypeError("A positive bound (= %s) must be specified."%bound)
if not is_FiniteField(F):
raise TypeError("Argument F (= %s) must be a finite field."%F)
pts = []
for P in self.ambient_space().rational_points(F):
try:
if self._check_satisfies_equations(list(P)):
pts.append(P)
except TypeError:
pass
pts.sort()
return pts
#*******************************************************************
class AlgebraicScheme_subscheme(AlgebraicScheme):
"""
An algebraic scheme presented as a closed subscheme is defined by
explicit polynomial equations. This is as opposed to a general
scheme, which could, e.g., be the Neron model of some object, and
for which we do not want to give explicit equations.
INPUT:
- ``A`` - ambient space (e.g. affine or projective `n`-space)
- ``polynomials`` - single polynomial, ideal or iterable of defining
polynomials; in any case polynomials must belong to the coordinate
ring of the ambient space and define valid polynomial functions (e.g.
they should be homogeneous in the case of a projective space)
OUTPUT:
- algebraic scheme
EXAMPLES::
sage: from sage.schemes.generic.algebraic_scheme import AlgebraicScheme_subscheme
sage: P.<x, y, z> = ProjectiveSpace(2, QQ)
sage: P.subscheme([x^2-y*z])
Closed subscheme of Projective Space of dimension 2 over Rational Field defined by:
x^2 - y*z
sage: AlgebraicScheme_subscheme(P, [x^2-y*z])
Closed subscheme of Projective Space of dimension 2 over Rational Field defined by:
x^2 - y*z
"""
def __init__(self, A, polynomials):
"""
See ``AlgebraicScheme_subscheme`` for documentation.
TESTS::
sage: from sage.schemes.generic.algebraic_scheme import AlgebraicScheme_subscheme
sage: P.<x, y, z> = ProjectiveSpace(2, QQ)
sage: P.subscheme([x^2-y*z])
Closed subscheme of Projective Space of dimension 2 over Rational Field defined by:
x^2 - y*z
sage: AlgebraicScheme_subscheme(P, [x^2-y*z])
Closed subscheme of Projective Space of dimension 2 over Rational Field defined by:
x^2 - y*z
"""
from sage.rings.polynomial.multi_polynomial_sequence import is_PolynomialSequence
AlgebraicScheme.__init__(self, A)
self._base_ring = A.base_ring()
R = A.coordinate_ring()
if is_Ideal(polynomials):
I = polynomials
polynomials = I.gens()
if I.ring() is R: # Otherwise we will recompute I later after
self.__I = I # converting generators to the correct ring
if isinstance(polynomials, tuple) or is_PolynomialSequence(polynomials) or is_iterator(polynomials):
polynomials = list(polynomials)
elif not isinstance(polynomials, list):
# Looks like we got a single polynomial
polynomials = [polynomials]
for n, f in enumerate(polynomials):
try:
polynomials[n] = R(f)
except TypeError:
raise TypeError("%s cannot be converted to a polynomial in "
"the coordinate ring of this %s!" % (f, A))
polynomials = tuple(polynomials)
self.__polys = A._validate(polynomials)
def _check_satisfies_equations(self, v):
"""
Verify that the coordinates of v define a point on this scheme, or
raise a TypeError.
EXAMPLES::
sage: P.<x, y, z> = ProjectiveSpace(2, QQ)
sage: S = P.subscheme([x^2-y*z])
sage: S._check_satisfies_equations([1, 1, 1])
True
sage: S._check_satisfies_equations([1, 0, 1])
Traceback (most recent call last):
...
TypeError: Coordinates [1, 0, 1] do not define a point on Closed subscheme
of Projective Space of dimension 2 over Rational Field defined by:
x^2 - y*z
sage: S._check_satisfies_equations([0, 0, 0])
Traceback (most recent call last):
...
TypeError: Coordinates [0, 0, 0] do not define a point on Closed subscheme
of Projective Space of dimension 2 over Rational Field defined by:
x^2 - y*z
"""
coords = list(v)
for f in self.defining_polynomials():
if f(coords) != 0: # it must be "!=0" instead of "if f(v)", e.g.,
# because of p-adic base rings.
raise TypeError("Coordinates %s do not define a point on %s"%(coords,self))
try:
return self.ambient_space()._check_satisfies_equations(coords)
except TypeError:
raise TypeError("Coordinates %s do not define a point on %s"%(coords,self))
def base_extend(self, R):
"""
Return the base change to the ring `R` of this scheme.
EXAMPLES::
sage: P.<x, y, z> = ProjectiveSpace(2, GF(11))
sage: S = P.subscheme([x^2-y*z])
sage: S.base_extend(GF(11^2, 'b'))
Closed subscheme of Projective Space of dimension 2 over Finite Field in b of size 11^2 defined by:
x^2 - y*z
sage: S.base_extend(ZZ)
Traceback (most recent call last):
...
ValueError: no natural map from the base ring (=Finite Field of size 11) to R (=Integer Ring)!
"""
A = self.ambient_space().base_extend(R)
return A.subscheme(self.__polys)
def __cmp__(self, other):
"""
EXAMPLES::
sage: A.<x, y, z> = AffineSpace(3, QQ)