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
/
projective_space.py
1509 lines (1192 loc) · 52.4 KB
/
projective_space.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"""
Projective `n` space over a ring
EXAMPLES:
We construct projective space over various rings of various dimensions.
The simplest projective space::
sage: ProjectiveSpace(0)
Projective Space of dimension 0 over Integer Ring
A slightly bigger projective space over `\QQ`::
sage: X = ProjectiveSpace(1000, QQ); X
Projective Space of dimension 1000 over Rational Field
sage: X.dimension()
1000
We can use "over" notation to create projective spaces over various
base rings.
::
sage: X = ProjectiveSpace(5)/QQ; X
Projective Space of dimension 5 over Rational Field
sage: X/CC
Projective Space of dimension 5 over Complex Field with 53 bits of precision
The third argument specifies the printing names of the generators of the
homogenous coordinate ring. Using the method `.objgens()` you can obtain both
the space and the generators as ready to use variables. ::
sage: P2, vars = ProjectiveSpace(10, QQ, 't').objgens()
sage: vars
(t0, t1, t2, t3, t4, t5, t6, t7, t8, t9, t10)
You can alternatively use the special syntax with ``<`` and ``>``.
::
sage: P2.<x,y,z> = ProjectiveSpace(2, QQ)
sage: P2
Projective Space of dimension 2 over Rational Field
sage: P2.coordinate_ring()
Multivariate Polynomial Ring in x, y, z over Rational Field
The first of the three lines above is just equivalent to the two lines::
sage: P2 = ProjectiveSpace(2, QQ, 'xyz')
sage: x,y,z = P2.gens()
For example, we use `x,y,z` to define the intersection of
two lines.
::
sage: V = P2.subscheme([x+y+z, x+y-z]); V
Closed subscheme of Projective Space of dimension 2 over Rational Field defined by:
x + y + z,
x + y - z
sage: V.dimension()
0
AUTHORS:
- Ben Hutz: (June 2012): support for rings
- Ben Hutz (9/2014): added support for Cartesian products
- Rebecca Lauren Miller (March 2016) : added point_transformation_matrix
"""
#*****************************************************************************
# Copyright (C) 2006 William Stein <wstein@gmail.com>
#
# Distributed under the terms of the GNU General Public License (GPL)
#
# http://www.gnu.org/licenses/
#*****************************************************************************
from __future__ import print_function
from sage.rings.all import (PolynomialRing,
Integer,
ZZ)
from sage.rings.ring import CommutativeRing
from sage.rings.rational_field import is_RationalField
from sage.rings.polynomial.multi_polynomial_ring import is_MPolynomialRing
from sage.rings.finite_rings.finite_field_constructor import is_FiniteField
from sage.categories.fields import Fields
_Fields = Fields()
from sage.categories.homset import Hom, End
from sage.categories.number_fields import NumberFields
from sage.categories.map import Map
from sage.misc.all import (latex,
prod)
from sage.structure.category_object import normalize_names
from sage.arith.all import gcd, binomial
from sage.combinat.integer_vector import IntegerVectors
from sage.combinat.tuple import Tuples
from sage.matrix.constructor import matrix
from sage.modules.free_module_element import prepare
from sage.schemes.generic.ambient_space import AmbientSpace
from sage.schemes.projective.projective_homset import (SchemeHomset_points_projective_ring,
SchemeHomset_points_projective_field)
from sage.schemes.projective.projective_point import (SchemeMorphism_point_projective_ring,
SchemeMorphism_point_projective_field,
SchemeMorphism_point_projective_finite_field)
from sage.schemes.projective.projective_morphism import (SchemeMorphism_polynomial_projective_space,
SchemeMorphism_polynomial_projective_space_field,
SchemeMorphism_polynomial_projective_space_finite_field)
def is_ProjectiveSpace(x):
r"""
Return True if ``x`` is a projective space.
In other words, if ``x`` is an ambient space `\mathbb{P}^n_R`,
where `R` is a ring and `n\geq 0` is an integer.
EXAMPLES::
sage: from sage.schemes.projective.projective_space import is_ProjectiveSpace
sage: is_ProjectiveSpace(ProjectiveSpace(5, names='x'))
True
sage: is_ProjectiveSpace(ProjectiveSpace(5, GF(9,'alpha'), names='x'))
True
sage: is_ProjectiveSpace(Spec(ZZ))
False
"""
return isinstance(x, ProjectiveSpace_ring)
def ProjectiveSpace(n, R=None, names='x'):
r"""
Return projective space of dimension ``n`` over the ring ``R``.
EXAMPLES: The dimension and ring can be given in either order.
::
sage: ProjectiveSpace(3, QQ)
Projective Space of dimension 3 over Rational Field
sage: ProjectiveSpace(5, QQ)
Projective Space of dimension 5 over Rational Field
sage: P = ProjectiveSpace(2, QQ, names='XYZ'); P
Projective Space of dimension 2 over Rational Field
sage: P.coordinate_ring()
Multivariate Polynomial Ring in X, Y, Z over Rational Field
The divide operator does base extension.
::
sage: ProjectiveSpace(5)/GF(17)
Projective Space of dimension 5 over Finite Field of size 17
The default base ring is `\ZZ`.
::
sage: ProjectiveSpace(5)
Projective Space of dimension 5 over Integer Ring
There is also an projective space associated each polynomial ring.
::
sage: R = GF(7)['x,y,z']
sage: P = ProjectiveSpace(R); P
Projective Space of dimension 2 over Finite Field of size 7
sage: P.coordinate_ring()
Multivariate Polynomial Ring in x, y, z over Finite Field of size 7
sage: P.coordinate_ring() is R
True
::
sage: ProjectiveSpace(3, Zp(5), 'y')
Projective Space of dimension 3 over 5-adic Ring with capped relative precision 20
::
sage: ProjectiveSpace(2,QQ,'x,y,z')
Projective Space of dimension 2 over Rational Field
::
sage: PS.<x,y>=ProjectiveSpace(1,CC)
sage: PS
Projective Space of dimension 1 over Complex Field with 53 bits of precision
Projective spaces are not cached, i.e., there can be several with
the same base ring and dimension (to facilitate gluing
constructions).
"""
if is_MPolynomialRing(n) and R is None:
A = ProjectiveSpace(n.ngens()-1, n.base_ring())
A._coordinate_ring = n
return A
if isinstance(R, (int, long, Integer)):
n, R = R, n
if R is None:
R = ZZ # default is the integers
if R in _Fields:
if is_FiniteField(R):
return ProjectiveSpace_finite_field(n, R, names)
if is_RationalField(R):
return ProjectiveSpace_rational_field(n, R, names)
else:
return ProjectiveSpace_field(n, R, names)
elif isinstance(R, CommutativeRing):
return ProjectiveSpace_ring(n, R, names)
else:
raise TypeError("R (=%s) must be a commutative ring"%R)
class ProjectiveSpace_ring(AmbientSpace):
"""
Projective space of dimension `n` over the ring
`R`.
EXAMPLES::
sage: X.<x,y,z,w> = ProjectiveSpace(3, QQ)
sage: X.base_scheme()
Spectrum of Rational Field
sage: X.base_ring()
Rational Field
sage: X.structure_morphism()
Scheme morphism:
From: Projective Space of dimension 3 over Rational Field
To: Spectrum of Rational Field
Defn: Structure map
sage: X.coordinate_ring()
Multivariate Polynomial Ring in x, y, z, w over Rational Field
Loading and saving::
sage: loads(X.dumps()) == X
True
"""
def __init__(self, n, R=ZZ, names=None):
"""
Initialization function.
EXAMPLES::
sage: ProjectiveSpace(3, Zp(5), 'y')
Projective Space of dimension 3 over 5-adic Ring with capped relative precision 20
"""
names = normalize_names(n+1, names)
AmbientSpace.__init__(self, n, R)
self._assign_names(names)
def ngens(self):
"""
Return the number of generators of this projective space.
This is the number of variables in the coordinate ring of self.
EXAMPLES::
sage: ProjectiveSpace(3, QQ).ngens()
4
sage: ProjectiveSpace(7, ZZ).ngens()
8
"""
return self.dimension_relative() + 1
def _check_satisfies_equations(self, v):
"""
Return True if ``v`` defines a point on the scheme; raise a
TypeError otherwise.
EXAMPLES::
sage: P = ProjectiveSpace(2, ZZ)
sage: P._check_satisfies_equations([1, 1, 0])
True
::
sage: P = ProjectiveSpace(1, QQ)
sage: P._check_satisfies_equations((1/2, 0))
True
::
sage: P = ProjectiveSpace(2, ZZ)
sage: P._check_satisfies_equations([0, 0, 0])
Traceback (most recent call last):
...
TypeError: the zero vector is not a point in projective space
::
sage: P = ProjectiveSpace(2, ZZ)
sage: P._check_satisfies_equations((1, 0))
Traceback (most recent call last):
...
TypeError: the list v=(1, 0) must have 3 components
::
sage: P = ProjectiveSpace(2, ZZ)
sage: P._check_satisfies_equations([1/2, 0, 1])
Traceback (most recent call last):
...
TypeError: the components of v=[1/2, 0, 1] must be elements of Integer Ring
"""
if not isinstance(v, (list, tuple)):
raise TypeError('the argument v=%s must be a list or tuple'%v)
n = self.ngens()
if not len(v) == n:
raise TypeError('the list v=%s must have %s components'%(v, n))
R = self.base_ring()
for coord in v:
if not coord in R:
raise TypeError('the components of v=%s must be elements of %s'%(v, R))
zero = [R(0)]*n
if v == zero:
raise TypeError('the zero vector is not a point in projective space')
return True
def coordinate_ring(self):
"""
Return the coordinate ring of this scheme.
EXAMPLES::
sage: ProjectiveSpace(3, GF(19^2,'alpha'), 'abcd').coordinate_ring()
Multivariate Polynomial Ring in a, b, c, d over Finite Field in alpha of size 19^2
::
sage: ProjectiveSpace(3).coordinate_ring()
Multivariate Polynomial Ring in x0, x1, x2, x3 over Integer Ring
::
sage: ProjectiveSpace(2, QQ, ['alpha', 'beta', 'gamma']).coordinate_ring()
Multivariate Polynomial Ring in alpha, beta, gamma over Rational Field
"""
try:
return self._coordinate_ring
except AttributeError:
self._coordinate_ring = PolynomialRing(self.base_ring(),
self.variable_names(), self.dimension_relative()+1)
return self._coordinate_ring
def _validate(self, polynomials):
"""
If ``polynomials`` is a tuple of valid polynomial functions on self,
return ``polynomials``, otherwise raise TypeError.
Since this is a projective space, polynomials must be homogeneous.
INPUT:
- ``polynomials`` -- tuple of polynomials in the coordinate ring of
this space.
OUTPUT:
- tuple of polynomials in the coordinate ring of this space.
EXAMPLES::
sage: P.<x, y, z> = ProjectiveSpace(2, ZZ)
sage: P._validate([x*y - z^2, x])
[x*y - z^2, x]
::
sage: P.<x, y, z> = ProjectiveSpace(2, ZZ)
sage: P._validate((x*y - z, x))
Traceback (most recent call last):
...
TypeError: x*y - z is not a homogeneous polynomial
::
sage: P.<x, y, z> = ProjectiveSpace(2, ZZ)
sage: P._validate(x*y - z)
Traceback (most recent call last):
...
TypeError: the argument polynomials=x*y - z must be a list or tuple
"""
if not isinstance(polynomials, (list, tuple)):
raise TypeError('the argument polynomials=%s must be a list or tuple'%polynomials)
for f in polynomials:
if not f.is_homogeneous():
raise TypeError("%s is not a homogeneous polynomial" % f)
return polynomials
def __cmp__(self, right):
"""
Compare equality of two projective spaces.
EXAMPLES::
sage: ProjectiveSpace(QQ, 3, 'a') == ProjectiveSpace(ZZ, 3, 'a')
False
sage: ProjectiveSpace(ZZ, 1, 'a') == ProjectiveSpace(ZZ, 0, 'a')
False
sage: ProjectiveSpace(ZZ, 2, 'a') == AffineSpace(ZZ, 2, 'a')
False
sage: loads(AffineSpace(ZZ, 1, 'x').dumps()) == AffineSpace(ZZ, 1, 'x')
True
"""
if not isinstance(right, ProjectiveSpace_ring):
return -1
return cmp([self.dimension_relative(), self.coordinate_ring()],
[right.dimension_relative(), right.coordinate_ring()])
def _latex_(self):
r"""
Return a LaTeX representation of this projective space.
EXAMPLES::
sage: print(latex(ProjectiveSpace(1, ZZ, 'x')))
{\mathbf P}_{\Bold{Z}}^1
TESTS::
sage: ProjectiveSpace(3, Zp(5), 'y')._latex_()
'{\\mathbf P}_{\\ZZ_{5}}^3'
"""
return "{\\mathbf P}_{%s}^%s"%(latex(self.base_ring()), self.dimension_relative())
def _linear_system_as_kernel(self, d, pt, m):
"""
Return a matrix whose kernel consists of the coefficient vectors
of the degree ``d`` hypersurfaces (wrt lexicographic ordering of its
monomials) with multiplicity at least ``m`` at ``pt``.
INPUT:
- ``d`` -- a nonnegative integer.
- ``pt`` -- a point of self (possibly represented by a list with at \
least one component equal to 1).
- ``m`` -- a nonnegative integer.
OUTPUT:
A matrix of size `{m-1+n \choose n}` x `{d+n \choose n}` where n is the
relative dimension of self. The base ring of the matrix is a ring that
contains the base ring of self and the coefficients of the given point.
EXAMPLES:
If the degree `d` is 0, then a matrix consisting of the first unit vector
is returned::
sage: P = ProjectiveSpace(GF(5), 2, names='x')
sage: pt = P([1, 1, 1])
sage: P._linear_system_as_kernel(0, pt, 3)
[1]
[0]
[0]
[0]
[0]
[0]
If the multiplcity ``m`` is 0, then the a matrix with zero rows is returned::
sage: P = ProjectiveSpace(GF(5), 2, names='x')
sage: pt = P([1, 1, 1])
sage: M = P._linear_system_as_kernel(2, pt, 0)
sage: [M.nrows(), M.ncols()]
[0, 6]
The base ring does not need to be a field or even an integral domain.
In this case, the point can be given by a list::
sage: R = Zmod(4)
sage: P = ProjectiveSpace(R, 2, names='x')
sage: pt = [R(1), R(3), R(0)]
sage: P._linear_system_as_kernel(3, pt, 2)
[1 3 0 1 0 0 3 0 0 0]
[0 1 0 2 0 0 3 0 0 0]
[0 0 1 0 3 0 0 1 0 0]
When representing a point by a list at least one component must be 1
(even when the base ring is a field and the list gives a well-defined
point in projective space)::
sage: R = GF(5)
sage: P = ProjectiveSpace(R, 2, names='x')
sage: pt = [R(3), R(3), R(0)]
sage: P._linear_system_as_kernel(3, pt, 2)
Traceback (most recent call last):
...
TypeError: at least one component of pt=[3, 3, 0] must be equal
to 1
The components of the list do not have to be elements of the base ring
of the projective space. It suffices if there exists a common parent.
For example, the kernel of the following matrix corresponds to
hypersurfaces of degree 2 in 3-space with multiplicity at least 2 at a
general point in the third affine patch::
sage: P = ProjectiveSpace(QQ,3,names='x')
sage: RPol.<t0,t1,t2,t3> = PolynomialRing(QQ,4)
sage: pt = [t0,t1,1,t3]
sage: P._linear_system_as_kernel(2,pt,2)
[ 2*t0 t1 1 t3 0 0 0 0 0 0]
[ 0 t0 0 0 2*t1 1 t3 0 0 0]
[ t0^2 t0*t1 t0 t0*t3 t1^2 t1 t1*t3 1 t3 t3^2]
[ 0 0 0 t0 0 0 t1 0 1 2*t3]
.. TODO::
Use this method as starting point to implement a class
LinearSystem for linear systems of hypersurfaces.
"""
if not isinstance(d, (int, Integer)):
raise TypeError('the argument d=%s must be an integer'%d)
if d < 0:
raise ValueError('the integer d=%s must be nonnegative'%d)
if not isinstance(pt, (list, tuple, \
SchemeMorphism_point_projective_ring)):
raise TypeError('the argument pt=%s must be a list, tuple, or '
'point on a projective space'%pt)
pt, R = prepare(pt, None)
n = self.dimension_relative()
if not len(pt) == n+1:
raise TypeError('the sequence pt=%s must have %s '
'components'%(pt, n + 1))
if not R.has_coerce_map_from(self.base_ring()):
raise TypeError('unable to find a common ring for all elements')
try:
i = pt.index(1)
except Exception:
raise TypeError('at least one component of pt=%s must be equal '
'to 1'%pt)
pt = pt[:i] + pt[i+1:]
if not isinstance(m, (int, Integer)):
raise TypeError('the argument m=%s must be an integer'%m)
if m < 0:
raise ValueError('the integer m=%s must be nonnegative'%m)
# the components of partials correspond to partial derivatives
# of order at most m-1 with respect to n variables
partials = IntegerVectors(m-1, n+1).list()
# the components of monoms correspond to monomials of degree
# at most d in n variables
monoms = IntegerVectors(d, n+1).list()
M = matrix(R,len(partials),len(monoms))
for row in range(M.nrows()):
e = partials[row][:i] + partials[row][i+1:]
for col in range(M.ncols()):
f = monoms[col][:i] + monoms[col][i+1:]
if min([f[j]-e[j] for j in range(n)]) >= 0:
M[row,col] = prod([ binomial(f[j],e[j]) * pt[j]**(f[j]-e[j])
for j in (k for k in range(n) if f[k] > e[k]) ])
return M
def _morphism(self, *args, **kwds):
"""
Construct a morphism.
For internal use only. See :mod:`morphism` for details.
TESTS::
sage: P2.<x,y,z> = ProjectiveSpace(2, GF(3))
sage: P2._morphism(P2.Hom(P2), [x,y,z])
Scheme endomorphism of Projective Space of dimension 2 over Finite Field of size 3
Defn: Defined on coordinates by sending (x : y : z) to
(x : y : z)
"""
return SchemeMorphism_polynomial_projective_space(*args, **kwds)
def _point_homset(self, *args, **kwds):
"""
Construct a point Hom-set.
For internal use only. See :mod:`morphism` for details.
TESTS::
sage: P2.<x,y,z> = ProjectiveSpace(2, GF(3))
sage: P2._point_homset(Spec(GF(3)), P2)
Set of rational points of Projective Space of dimension 2 over Finite Field of size 3
"""
return SchemeHomset_points_projective_ring(*args, **kwds)
def _point(self, *args, **kwds):
"""
Construct a point.
For internal use only. See :mod:`morphism` for details.
TESTS::
sage: P2.<x,y,z> = ProjectiveSpace(2, GF(3))
sage: point_homset = P2._point_homset(Spec(GF(3)), P2)
sage: P2._point(point_homset, [1,2,3])
(2 : 1 : 0)
"""
return SchemeMorphism_point_projective_ring(*args, **kwds)
def _repr_(self):
"""
Return a string representation of this projective space.
EXAMPLES::
sage: ProjectiveSpace(1, ZZ, 'x')
Projective Space of dimension 1 over Integer Ring
TESTS::
sage: ProjectiveSpace(3, Zp(5), 'y')._repr_()
'Projective Space of dimension 3 over 5-adic Ring with capped relative precision 20'
"""
return "Projective Space of dimension %s over %s"%(self.dimension_relative(), self.base_ring())
def _repr_generic_point(self, v=None):
"""
Return a string representation of the generic point
corresponding to the list of polys ``v`` on this projective space.
If ``v`` is None, the representation of the generic point of
the projective space is returned.
EXAMPLES::
sage: P.<x, y, z> = ProjectiveSpace(2, ZZ)
sage: P._repr_generic_point([z*y-x^2])
'(-x^2 + y*z)'
sage: P._repr_generic_point()
'(x : y : z)'
"""
if v is None:
v = self.gens()
return '(%s)'%(" : ".join([repr(f) for f in v]))
def _latex_generic_point(self, v=None):
"""
Return a LaTeX representation of the generic point
corresponding to the list of polys ``v`` on this projective space.
If ``v`` is None, the representation of the generic point of
the projective space is returned.
EXAMPLES::
sage: P.<x, y, z> = ProjectiveSpace(2, ZZ)
sage: P._latex_generic_point([z*y-x^2])
'\\left(- x^{2} + y z\\right)'
sage: P._latex_generic_point()
'\\left(x : y : z\\right)'
"""
if v is None:
v = self.gens()
return '\\left(%s\\right)'%(" : ".join([str(latex(f)) for f in v]))
def change_ring(self, R):
r"""
Return a projective space over ring ``R``.
INPUT:
- ``R`` -- commutative ring or morphism.
OUTPUT:
- projective space over ``R``.
.. NOTE::
There is no need to have any relation between ``R`` and the base ring
of this space, if you want to have such a relation, use
``self.base_extend(R)`` instead.
EXAMPLES::
sage: P.<x, y, z> = ProjectiveSpace(2, ZZ)
sage: PQ = P.change_ring(QQ); PQ
Projective Space of dimension 2 over Rational Field
sage: PQ.change_ring(GF(5))
Projective Space of dimension 2 over Finite Field of size 5
::
sage: K.<w> = QuadraticField(2)
sage: P = ProjectiveSpace(K,2,'t')
sage: P.change_ring(K.embeddings(QQbar)[0])
Projective Space of dimension 2 over Algebraic Field
"""
if isinstance(R, Map):
return ProjectiveSpace(self.dimension_relative(), R.codomain(),
self.variable_names())
else:
return ProjectiveSpace(self.dimension_relative(), R,
self.variable_names())
def is_projective(self):
"""
Return that this ambient space is projective `n`-space.
EXAMPLES::
sage: ProjectiveSpace(3,QQ).is_projective()
True
"""
return True
def subscheme(self, X):
"""
Return the closed subscheme defined by ``X``.
INPUT:
- ``X`` - a list or tuple of equations.
EXAMPLES::
sage: A.<x,y,z> = ProjectiveSpace(2, QQ)
sage: X = A.subscheme([x*z^2, y^2*z, x*y^2]); X
Closed subscheme of Projective Space of dimension 2 over Rational Field defined by:
x*z^2,
y^2*z,
x*y^2
sage: X.defining_polynomials ()
(x*z^2, y^2*z, x*y^2)
sage: I = X.defining_ideal(); I
Ideal (x*z^2, y^2*z, x*y^2) of Multivariate Polynomial Ring in x, y, z over Rational Field
sage: I.groebner_basis()
[x*y^2, y^2*z, x*z^2]
sage: X.dimension()
0
sage: X.base_ring()
Rational Field
sage: X.base_scheme()
Spectrum of Rational Field
sage: X.structure_morphism()
Scheme morphism:
From: Closed subscheme of Projective Space of dimension 2 over Rational Field defined by:
x*z^2,
y^2*z,
x*y^2
To: Spectrum of Rational Field
Defn: Structure map
sage: TestSuite(X).run(skip=["_test_an_element", "_test_elements",\
"_test_elements_eq", "_test_some_elements", "_test_elements_eq_reflexive",\
"_test_elements_eq_symmetric", "_test_elements_eq_transitive",\
"_test_elements_neq"])
"""
from sage.schemes.generic.algebraic_scheme import AlgebraicScheme_subscheme_projective
return AlgebraicScheme_subscheme_projective(self, X)
def affine_patch(self, i, AA=None):
r"""
Return the `i^{th}` affine patch of this projective space.
This is an ambient affine space `\mathbb{A}^n_R,` where
`R` is the base ring of self, whose "projective embedding"
map is `1` in the `i^{th}` factor.
INPUT:
- ``i`` -- integer between 0 and dimension of self, inclusive.
- ``AA`` -- (default: None) ambient affine space, this is constructed
if it is not given.
OUTPUT:
- An ambient affine space with fixed projective_embedding map.
EXAMPLES::
sage: PP = ProjectiveSpace(5) / QQ
sage: AA = PP.affine_patch(2)
sage: AA
Affine Space of dimension 5 over Rational Field
sage: AA.projective_embedding()
Scheme morphism:
From: Affine Space of dimension 5 over Rational Field
To: Projective Space of dimension 5 over Rational Field
Defn: Defined on coordinates by sending (x0, x1, x2, x3, x4) to
(x0 : x1 : 1 : x2 : x3 : x4)
sage: AA.projective_embedding(0)
Scheme morphism:
From: Affine Space of dimension 5 over Rational Field
To: Projective Space of dimension 5 over Rational Field
Defn: Defined on coordinates by sending (x0, x1, x2, x3, x4) to
(1 : x0 : x1 : x2 : x3 : x4)
::
sage: P.<x,y> = ProjectiveSpace(QQ,1)
sage: P.affine_patch(0).projective_embedding(0).codomain() == P
True
"""
i = int(i) # implicit type checking
n = self.dimension_relative()
if i < 0 or i > n:
raise ValueError("argument i (= %s) must be between 0 and %s"%(i, n))
try:
A = self.__affine_patches[i]
#assume that if you've passed in a new affine space you want to override
#the existing patch
if AA is None or A == AA:
return(A)
except AttributeError:
self.__affine_patches = {}
except KeyError:
pass
#if no ith patch exists, we may still be here with AA==None
if AA == None:
from sage.schemes.affine.affine_space import AffineSpace
AA = AffineSpace(n, self.base_ring(), names = 'x')
elif AA.dimension_relative() != n:
raise ValueError("affine space must be of the dimension %s"%(n))
AA._default_embedding_index = i
phi = AA.projective_embedding(i, self)
self.__affine_patches[i] = AA
return AA
def _an_element_(self):
r"""
Returns a (preferably typical) element of this space.
This is used both for illustration and testing purposes.
OUTPUT: a point in this projective space.
EXAMPLES::
sage: ProjectiveSpace(ZZ, 3, 'x').an_element()
(7 : 6 : 5 : 1)
sage: ProjectiveSpace(PolynomialRing(ZZ,'y'), 3, 'x').an_element()
(7*y : 6*y : 5*y : 1)
"""
n = self.dimension_relative()
R = self.base_ring()
return self([(7 - i) * R.an_element() for i in range(n)] + [R.one()])
def Lattes_map(self, E, m):
r"""
Given an elliptic curve ``E`` and an integer ``m`` return
the Lattes map associated to multiplication by `m`.
In other words, the rational map on the quotient
`E/\{\pm 1\} \cong \mathbb{P}^1` associated to `[m]:E \to E`.
INPUT:
- ``E`` -- an elliptic curve.
- ``m`` -- an integer.
OUTPUT: an endomorphism of this projective space.
Examples::
sage: P.<x,y> = ProjectiveSpace(QQ,1)
sage: E = EllipticCurve(QQ,[-1, 0])
sage: P.Lattes_map(E, 2)
Scheme endomorphism of Projective Space of dimension 1 over Rational Field
Defn: Defined on coordinates by sending (x : y) to
(x^4 + 2*x^2*y^2 + y^4 : 4*x^3*y - 4*x*y^3)
"""
if self.dimension_relative() != 1:
raise TypeError("must be dimension 1")
L = E.multiplication_by_m(m, x_only = True)
F = [L.numerator(), L.denominator()]
R = self.coordinate_ring()
x, y = R.gens()
phi = F[0].parent().hom([x],R)
F = [phi(F[0]).homogenize(y), phi(F[1]).homogenize(y)*y]
H = Hom(self,self)
return(H(F))
def cartesian_product(self, other):
r"""
Return the Cartesian product of this projective space and
``other``.
INPUT:
- ``other`` - A projective space with the same base ring as this space.
OUTPUT:
- A Cartesian product of projective spaces.
EXAMPLES::
sage: P1 = ProjectiveSpace(QQ, 1, 'x')
sage: P2 = ProjectiveSpace(QQ, 2, 'y')
sage: PP = P1.cartesian_product(P2); PP
Product of projective spaces P^1 x P^2 over Rational Field
sage: PP.gens()
(x0, x1, y0, y1, y2)
"""
from sage.schemes.product_projective.space import ProductProjectiveSpaces
return ProductProjectiveSpaces([self, other])
def chebyshev_polynomial(self, n, kind='first'):
"""
Generates an endomorphism of this projective line by a Chebyshev polynomial.
Chebyshev polynomials are a sequence of recursively defined orthogonal
polynomials. Chebyshev of the first kind are defined as `T_0(x) = 1`,
`T_1(x) = x`, and `T_{n+1}(x) = 2xT_n(x) - T_{n-1}(x)`. Chebyshev of
the second kind are defined as `U_0(x) = 1`,
`U_1(x) = 2x`, and `U_{n+1}(x) = 2xU_n(x) - U_{n-1}(x)`.
INPUT:
- ``n`` -- a non-negative integer.
- ``kind`` -- ``first`` or ``second`` specifying which kind of chebyshev the user would like
to generate. Defaults to ``first``.
OUTPUT: :class:`SchemeMorphism_polynomial_projective_space`
EXAMPLES::
sage: P.<x,y> = ProjectiveSpace(QQ, 1)
sage: P.chebyshev_polynomial(5, 'first')
Scheme endomorphism of Projective Space of dimension 1 over Rational Field
Defn: Defined on coordinates by sending (x : y) to
(16*x^5 - 20*x^3*y^2 + 5*x*y^4 : y^5)
::
sage: P.<x,y> = ProjectiveSpace(QQ, 1)
sage: P.chebyshev_polynomial(3, 'second')
Scheme endomorphism of Projective Space of dimension 1 over Rational Field
Defn: Defined on coordinates by sending (x : y) to
(8*x^3 - 4*x*y^2 : y^3)
::
sage: P.<x,y> = ProjectiveSpace(QQ, 1)
sage: P.chebyshev_polynomial(3, 2)
Traceback (most recent call last):
...
ValueError: keyword 'kind' must have a value of either 'first' or 'second'
::
sage: P.<x,y> = ProjectiveSpace(QQ, 1)
sage: P.chebyshev_polynomial(-4, 'second')
Traceback (most recent call last):
...
ValueError: first parameter 'n' must be a non-negative integer
::
sage: P = ProjectiveSpace(QQ, 2, 'x')
sage: P.chebyshev_polynomial(2)
Traceback (most recent call last):
...
TypeError: projective space must be of dimension 1
"""
if self.dimension_relative() != 1:
raise TypeError("projective space must be of dimension 1")
n = ZZ(n)
if (n < 0):
raise ValueError("first parameter 'n' must be a non-negative integer")
#use the affine version and then homogenize.
A = self.affine_patch(1)
f = A.chebyshev_polynomial(n, kind)
return f.homogenize(1)
class ProjectiveSpace_field(ProjectiveSpace_ring):
def _point_homset(self, *args, **kwds):
"""
Construct a point Hom-set.
For internal use only. See :mod:`morphism` for details.
TESTS::
sage: P2.<x,y,z> = ProjectiveSpace(2, GF(3))
sage: P2._point_homset(Spec(GF(3)), P2)
Set of rational points of Projective Space of dimension 2 over Finite Field of size 3
"""
return SchemeHomset_points_projective_field(*args, **kwds)
def _point(self, *args, **kwds):
"""
Construct a point.