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_morphism.py
3015 lines (2408 loc) · 107 KB
/
projective_morphism.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"""
Morphisms on projective varieties
A morphism of schemes determined by rational functions that define
what the morphism does on points in the ambient projective space.
AUTHORS:
- David Kohel, William Stein
- William Stein (2006-02-11): fixed bug where P(0,0,0) was allowed as
a projective point.
- Volker Braun (2011-08-08): Renamed classes, more documentation, misc
cleanups.
- Ben Hutz (2013-03) iteration functionality and new directory structure
for affine/projective, height functionality
- Brian Stout, Ben Hutz (Nov 2013) - added minimal model functionality
- Dillon Rose (2014-01): Speed enhancements
"""
# Historical note: in trac #11599, V.B. renamed
# * _point_morphism_class -> _morphism
# * _homset_class -> _point_homset
#*****************************************************************************
# Copyright (C) 2011 Volker Braun <vbraun.name@gmail.com>
# Copyright (C) 2006 David Kohel <kohel@maths.usyd.edu.au>
# Copyright (C) 2006 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/
#*****************************************************************************
from sage.categories.homset import Hom
from sage.functions.all import sqrt
from sage.libs.pari.gen import PariError
from sage.matrix.constructor import matrix, identity_matrix
from sage.misc.cachefunc import cached_method
from sage.misc.misc import subsets
from sage.misc.mrange import xmrange
from sage.modules.free_module_element import vector
from sage.rings.all import Integer, moebius
from sage.rings.arith import gcd, lcm, next_prime, binomial, primes
from sage.rings.complex_field import ComplexField
from sage.rings.finite_rings.constructor import GF, is_PrimeFiniteField
from sage.rings.finite_rings.integer_mod_ring import Zmod
from sage.rings.fraction_field import FractionField
from sage.rings.integer_ring import ZZ
from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing
from sage.rings.quotient_ring import QuotientRing_generic
from sage.rings.rational_field import QQ
from sage.rings.real_mpfr import RealField
from sage.schemes.generic.morphism import SchemeMorphism_polynomial
from sage.symbolic.constants import e
from copy import copy
from sage.parallel.ncpus import ncpus
from sage.parallel.use_fork import p_iter_fork
from sage.ext.fast_callable import fast_callable
from sage.misc.lazy_attribute import lazy_attribute
from sage.schemes.projective.projective_morphism_helper import _fast_possible_periods
import sys
class SchemeMorphism_polynomial_projective_space(SchemeMorphism_polynomial):
"""
A morphism of schemes determined by rational functions that define
what the morphism does on points in the ambient projective space.
EXAMPLES::
sage: R.<x,y> = QQ[]
sage: P1 = ProjectiveSpace(R)
sage: H = P1.Hom(P1)
sage: H([y,2*x])
Scheme endomorphism of Projective Space of dimension 1 over Rational Field
Defn: Defined on coordinates by sending (x : y) to
(y : 2*x)
An example of a morphism between projective plane curves (see :trac:`10297`)::
sage: P2.<x,y,z> = ProjectiveSpace(QQ,2)
sage: f = x^3+y^3+60*z^3
sage: g = y^2*z-( x^3 - 6400*z^3/3)
sage: C = Curve(f)
sage: E = Curve(g)
sage: xbar,ybar,zbar = C.coordinate_ring().gens()
sage: H = C.Hom(E)
sage: H([zbar,xbar-ybar,-(xbar+ybar)/80])
Scheme morphism:
From: Projective Curve over Rational Field defined by x^3 + y^3 + 60*z^3
To: Projective Curve over Rational Field defined by -x^3 + y^2*z + 6400/3*z^3
Defn: Defined on coordinates by sending (x : y : z) to
(z : x - y : -1/80*x - 1/80*y)
A more complicated example::
sage: P2.<x,y,z> = ProjectiveSpace(2,QQ)
sage: P1 = P2.subscheme(x-y)
sage: H12 = P1.Hom(P2)
sage: H12([x^2,x*z, z^2])
Scheme morphism:
From: Closed subscheme of Projective Space of dimension 2 over Rational Field defined by:
x - y
To: Projective Space of dimension 2 over Rational Field
Defn: Defined on coordinates by sending (x : y : z) to
(y^2 : y*z : z^2)
We illustrate some error checking::
sage: R.<x,y> = QQ[]
sage: P1 = ProjectiveSpace(R)
sage: H = P1.Hom(P1)
sage: f = H([x-y, x*y])
Traceback (most recent call last):
...
ValueError: polys (=[x - y, x*y]) must be of the same degree
sage: H([x-1, x*y+x])
Traceback (most recent call last):
...
ValueError: polys (=[x - 1, x*y + x]) must be homogeneous
sage: H([exp(x),exp(y)])
Traceback (most recent call last):
...
TypeError: polys (=[e^x, e^y]) must be elements of
Multivariate Polynomial Ring in x, y over Rational Field
"""
def __init__(self, parent, polys, check=True):
"""
The Python constructor.
See :class:`SchemeMorphism_polynomial` for details.
EXAMPLES::
sage: P1.<x,y> = ProjectiveSpace(QQ,1)
sage: H = P1.Hom(P1)
sage: H([y,2*x])
Scheme endomorphism of Projective Space of dimension 1 over Rational Field
Defn: Defined on coordinates by sending (x : y) to
(y : 2*x)
"""
SchemeMorphism_polynomial.__init__(self, parent, polys, check)
if check:
# morphisms from projective space are always given by
# homogeneous polynomials of the same degree
try:
d = polys[0].degree()
except AttributeError:
polys = [f.lift() for f in polys]
if not all([f.is_homogeneous() for f in polys]):
raise ValueError("polys (=%s) must be homogeneous" % polys)
degs = [f.degree() for f in polys]
if not all([d == degs[0] for d in degs[1:]]):
raise ValueError("polys (=%s) must be of the same degree" % polys)
self._is_prime_finite_field = is_PrimeFiniteField(polys[0].base_ring())
def __call__(self, x, check=True):
"""
Evaluate projective morphism at point described by ``x``.
EXAMPLES::
sage: P.<x,y,z>=ProjectiveSpace(QQ,2)
sage: H=Hom(P,P)
sage: f=H([x^2+y^2,y^2,z^2 + y*z])
sage: f(P([1,1,1]))
(1 : 1/2 : 1)
"""
from sage.schemes.projective.projective_point import SchemeMorphism_point_projective_ring
if check:
if not isinstance(x, SchemeMorphism_point_projective_ring):
try:
x = self.domain()(x)
except (TypeError, NotImplementedError):
raise TypeError, "%s fails to convert into the map's domain %s, but a `pushforward` method is not properly implemented"%(x, self.domain())
elif self.domain()!=x.codomain():
raise TypeError, "%s fails to convert into the map's domain %s, but a `pushforward` method is not properly implemented"%(x, self.domain())
# Passes the array of args to _fast_eval
P = self._fast_eval(x._coords)
return self.codomain().point(P, check)
@lazy_attribute
def _fastpolys(self):
"""
Lazy attribute for fast_callable polynomials for ``self``.
EXAMPLES::
sage: P.<x,y>=ProjectiveSpace(QQ,1)
sage: H = Hom(P,P)
sage: f = H([x^2+y^2,y^2])
sage: [g.op_list() for g in f._fastpolys]
[[('load_const', 0), ('load_const', 1), ('load_arg', 1), ('ipow', 2), 'mul', 'add', ('load_const', 1), ('load_arg', 0), ('ipow', 2), 'mul', 'add', 'return'], [('load_const', 0), ('load_const', 1), ('load_arg', 1), ('ipow', 2), 'mul', 'add', 'return']]
"""
polys = self._polys
fastpolys = []
for poly in polys:
# These tests are in place because the float and integer domain evaluate
# faster than using the base_ring
if self._is_prime_finite_field:
prime = polys[0].base_ring().characteristic()
degree = polys[0].degree()
coefficients = poly.coefficients()
height = max(abs(c.lift()) for c in coefficients)
num_terms = len(coefficients)
largest_value = num_terms * height * (prime - 1) ** degree
# If the calculations will not overflow the float data type use domain float
# Else use domain integer
if largest_value < (2 ** sys.float_info.mant_dig):
fastpolys.append(fast_callable(poly, domain=float))
else:
fastpolys.append(fast_callable(poly, domain=ZZ))
else:
fastpolys.append(fast_callable(poly, domain=poly.base_ring()))
return fastpolys
def _fast_eval(self, x):
"""
Evaluate projective morphism at point described by ``x``.
EXAMPLES::
sage: P.<x,y,z>=ProjectiveSpace(QQ,2)
sage: H=Hom(P,P)
sage: f=H([x^2+y^2,y^2,z^2 + y*z])
sage: f._fast_eval([1,1,1])
[2, 1, 2]
::
sage: T.<z> = LaurentSeriesRing(ZZ)
sage: P.<x,y> = ProjectiveSpace(T,1)
sage: H = End(P)
sage: f = H([x^2+x*y,y^2])
sage: Q = P(z,1)
sage: f._fast_eval(list(Q))
[z + z^2, 1]
::
sage: T.<z>=PolynomialRing(CC)
sage: I=T.ideal(z^3)
sage: P.<x,y>=ProjectiveSpace(T.quotient_ring(I),1)
sage: H=End(P)
sage: f=H([x^2+x*y,y^2])
sage: Q=P(z^2,1)
sage: f._fast_eval(list(Q))
[zbar^2, 1.00000000000000]
::
sage: T.<z>=LaurentSeriesRing(CC)
sage: R.<t>=PolynomialRing(T)
sage: P.<x,y>=ProjectiveSpace(R,1)
sage: H=End(P)
sage: f=H([x^2+x*y,y^2])
sage: F=f.dehomogenize(1)
sage: Q=P(t^2,z)
sage: f._fast_eval(list(Q))
[t^4 + z*t^2, z^2]
"""
P = [f(*x) for f in self._fastpolys]
return P
def __eq__(self, right):
"""
Tests the equality of two projective spaces.
INPUT:
- ``right`` - a map on projective space
OUTPUT:
- Boolean - True if ``self`` and ``right`` define the same projective map. False otherwise.
EXAMPLES::
sage: P1.<x,y> = ProjectiveSpace(RR,1)
sage: P2.<x,y> = ProjectiveSpace(QQ,1)
sage: P1==P2
False
::
sage: R.<x,y> = QQ[]
sage: P1 = ProjectiveSpace(R)
sage: P2.<x,y> = ProjectiveSpace(QQ,1)
sage: P1==P2
True
"""
if not isinstance(right, SchemeMorphism_polynomial):
return False
else:
n = len(self._polys)
for i in range(0, n):
for j in range(i + 1, n):
if self._polys[i] * right._polys[j] != self._polys[j] * right._polys[i]:
return False
return True
def __ne__(self, right):
"""
Tests the inequality of two projective spaces.
INPUT:
- ``right`` -- a map on projective space
OUTPUT:
- Boolean -- True if ``self`` and ``right`` define different projective maps. False otherwise.
EXAMPLES::
sage: P1.<x,y> = ProjectiveSpace(RR,1)
sage: P2.<x,y> = ProjectiveSpace(QQ,1)
sage: P1!=P2
True
::
sage: R.<x,y> = QQ[]
sage: P1 = ProjectiveSpace(R)
sage: P2.<x,y> = ProjectiveSpace(QQ,1)
sage: P1!=P2
False
"""
if not isinstance(right, SchemeMorphism_polynomial):
return True
else:
n = len(self._polys)
for i in range(0, n):
for j in range(i + 1, n):
if self._polys[i] * right._polys[j] != self._polys[j] * right._polys[i]:
return True
return False
def scale_by(self, t):
"""
Scales each coordinates by a factor of `t`.
A ``TypeError`` occurs if the point is not in the coordinate_ring
of the parent after scaling.
INPUT:
- ``t`` -- a ring element
OUTPUT:
- None.
EXAMPLES::
sage: A.<x,y> = ProjectiveSpace(QQ,1)
sage: H = Hom(A,A)
sage: f = H([x^3-2*x*y^2,x^2*y])
sage: f.scale_by(1/x)
sage: f
Scheme endomorphism of Projective Space of dimension 1 over Rational
Field
Defn: Defined on coordinates by sending (x : y) to
(x^2 - 2*y^2 : x*y)
::
sage: R.<t> = PolynomialRing(QQ)
sage: P.<x,y> = ProjectiveSpace(R,1)
sage: H = Hom(P,P)
sage: f = H([3/5*x^2,6*y^2])
sage: f.scale_by(5/3*t); f
Scheme endomorphism of Projective Space of dimension 1 over Univariate
Polynomial Ring in t over Rational Field
Defn: Defined on coordinates by sending (x : y) to
(t*x^2 : 10*t*y^2)
::
sage: P.<x,y,z> = ProjectiveSpace(GF(7),2)
sage: X = P.subscheme(x^2-y^2)
sage: H = Hom(X,X)
sage: f = H([x^2,y^2,z^2])
sage: f.scale_by(x-y);f
Scheme endomorphism of Closed subscheme of Projective Space of dimension
2 over Finite Field of size 7 defined by:
x^2 - y^2
Defn: Defined on coordinates by sending (x : y : z) to
(x*y^2 - y^3 : x*y^2 - y^3 : x*z^2 - y*z^2)
"""
if t == 0:
raise ValueError("Cannot scale by 0")
R = self.domain().coordinate_ring()
if isinstance(R, QuotientRing_generic):
phi = R._internal_coerce_map_from(self.domain().ambient_space().coordinate_ring())
for i in range(self.codomain().ambient_space().dimension_relative() + 1):
self._polys[i] = phi(self._polys[i] * t).lift()
else:
for i in range(self.codomain().ambient_space().dimension_relative() + 1):
self._polys[i] = R(self._polys[i] * t)
def normalize_coordinates(self):
"""
Scales by 1/gcd of the coordinate functions. Also, scales to clear any denominators from the coefficients.
This is done in place.
OUTPUT:
- None.
EXAMPLES::
sage: P.<x,y> = ProjectiveSpace(QQ,1)
sage: H = Hom(P,P)
sage: f = H([5/4*x^3,5*x*y^2])
sage: f.normalize_coordinates(); f
Scheme endomorphism of Projective Space of dimension 1 over Rational
Field
Defn: Defined on coordinates by sending (x : y) to
(x^2 : 4*y^2)
::
sage: P.<x,y,z> = ProjectiveSpace(GF(7),2)
sage: X = P.subscheme(x^2-y^2)
sage: H = Hom(X,X)
sage: f = H([x^3+x*y^2,x*y^2,x*z^2])
sage: f.normalize_coordinates(); f
Scheme endomorphism of Closed subscheme of Projective Space of dimension
2 over Finite Field of size 7 defined by:
x^2 - y^2
Defn: Defined on coordinates by sending (x : y : z) to
(2*y^2 : y^2 : z^2)
.. NOTE:: gcd raises an error if the base_ring does not support gcds.
"""
GCD = gcd(self[0], self[1])
index = 2
if self[0].lc() > 0 or self[1].lc() > 0:
neg = 0
else:
neg = 1
N = self.codomain().ambient_space().dimension_relative() + 1
while GCD != 1 and index < N:
if self[index].lc() > 0:
neg = 0
GCD = gcd(GCD, self[index])
index += +1
if GCD != 1:
R = self.domain().base_ring()
if neg == 1:
self.scale_by(R(-1) / GCD)
else:
self.scale_by(R(1) / GCD)
else:
if neg == 1:
self.scale_by(-1)
#clears any denominators from the coefficients
LCM = lcm([self[i].denominator() for i in range(N)])
self.scale_by(LCM)
#scales by 1/gcd of the coefficients.
GCD = gcd([self[i].content() for i in range(N)])
if GCD != 1:
self.scale_by(1 / GCD)
def dynatomic_polynomial(self, period):
r"""
For a map `f:\mathbb{P}^1 \to \mathbb{P}^1` this function computes the dynatomic polynomial.
The dynatomic polynomial is the analog of the cyclotomic
polynomial and its roots are the points of formal period `period`.
ALGORITHM:
For a positive integer `n`, let `[F_n,G_n]` be the coordinates of the `nth` iterate of `f`.
Then construct
.. MATH::
\Phi^{\ast}_n(f)(x,y) = \sum_{d \mid n} (yF_d(x,y) - xG_d(x,y))^{\mu(n/d)}
where `\mu` is the Moebius function.
For a pair `[m,n]`, let `f^m = [F_m,G_m]`. Compute
.. MATH::
\Phi^{\ast}_{m,n}(f)(x,y) = \Phi^{\ast}_n(f)(F_m,G_m)/\Phi^{\ast}_n(f)(F_{m-1},G_{m-1})
REFERENCES:
.. [Hutz] B. Hutz. Efficient determination of rational preperiodic
points for endomorphisms of projective space.
:arxiv:`1210.6246`, 2012.
.. [MoPa] P. Morton and P. Patel. The Galois theory of periodic points
of polynomial maps. Proc. London Math. Soc., 68 (1994), 225-263.
INPUT:
- ``period`` -- a positive integer or a list/tuple `[m,n]` where `m` is the preperiod and `n` is the period
OUTPUT:
- If possible, a two variable polynomial in the coordinate ring of ``self``.
Otherwise a fraction field element of the coordinate ring of ``self``
.. TODO::
Do the division when the base ring is p-adic or a function field
so that the output is a polynomial.
EXAMPLES::
sage: P.<x,y> = ProjectiveSpace(QQ,1)
sage: H = Hom(P,P)
sage: f = H([x^2+y^2,y^2])
sage: f.dynatomic_polynomial(2)
x^2 + x*y + 2*y^2
::
sage: P.<x,y> = ProjectiveSpace(ZZ,1)
sage: H = Hom(P,P)
sage: f = H([x^2+y^2,x*y])
sage: f.dynatomic_polynomial(4)
2*x^12 + 18*x^10*y^2 + 57*x^8*y^4 + 79*x^6*y^6 + 48*x^4*y^8 + 12*x^2*y^10 + y^12
::
sage: P.<x,y> = ProjectiveSpace(CC,1)
sage: H = Hom(P,P)
sage: f = H([x^2+y^2,3*x*y])
sage: f.dynatomic_polynomial(3)
13.0000000000000*x^6 + 117.000000000000*x^4*y^2 +
78.0000000000000*x^2*y^4 + y^6
::
sage: P.<x,y> = ProjectiveSpace(QQ,1)
sage: H = Hom(P,P)
sage: f = H([x^2-10/9*y^2,y^2])
sage: f.dynatomic_polynomial([2,1])
x^4*y^2 - 11/9*x^2*y^4 - 80/81*y^6
::
sage: P.<x,y> = ProjectiveSpace(QQ,1)
sage: H = Hom(P,P)
sage: f = H([x^2-29/16*y^2,y^2])
sage: f.dynatomic_polynomial([2,3])
x^12 - 95/8*x^10*y^2 + 13799/256*x^8*y^4 - 119953/1024*x^6*y^6 +
8198847/65536*x^4*y^8 - 31492431/524288*x^2*y^10 +
172692729/16777216*y^12
::
sage: P.<x,y> = ProjectiveSpace(ZZ,1)
sage: H = Hom(P,P)
sage: f = H([x^2-y^2,y^2])
sage: f.dynatomic_polynomial([1,2])
x^2 - x*y
::
sage: P.<x,y> = ProjectiveSpace(QQ,1)
sage: H = Hom(P,P)
sage: f = H([x^3-y^3,3*x*y^2])
sage: f.dynatomic_polynomial([0,4])==f.dynatomic_polynomial(4)
True
::
sage: P.<x,y,z> = ProjectiveSpace(QQ,2)
sage: H = Hom(P,P)
sage: f = H([x^2+y^2,x*y,z^2])
sage: f.dynatomic_polynomial(2)
Traceback (most recent call last):
...
TypeError: Does not make sense in dimension >1
::
sage: P.<x,y> = ProjectiveSpace(Qp(5),1)
sage: H = Hom(P,P)
sage: f = H([x^2+y^2,y^2])
sage: f.dynatomic_polynomial(2)
(x^4*y + (2 + O(5^20))*x^2*y^3 - x*y^4 + (2 + O(5^20))*y^5)/(x^2*y -
x*y^2 + y^3)
.. TODO:: It would be nice to get this to actually be a polynomial.
::
sage: L.<t> = PolynomialRing(QQ)
sage: P.<x,y> = ProjectiveSpace(L,1)
sage: H = Hom(P,P)
sage: f = H([x^2+t*y^2,y^2])
sage: f.dynatomic_polynomial(2)
x^2 + x*y + (t + 1)*y^2
::
sage: K.<c> = PolynomialRing(ZZ)
sage: P.<x,y> = ProjectiveSpace(K,1)
sage: H = Hom(P,P)
sage: f = H([x^2+ c*y^2,y^2])
sage: f.dynatomic_polynomial([1,2])
x^2 - x*y + (c + 1)*y^2
::
sage: P.<x,y> = ProjectiveSpace(QQ,1)
sage: H = Hom(P,P)
sage: f = H([x^2+y^2,y^2])
sage: f.dynatomic_polynomial(2)
x^2 + x*y + 2*y^2
sage: R.<X> = PolynomialRing(QQ)
sage: K.<c> = NumberField(X^2 + X + 2)
sage: PP = P.change_ring(K)
sage: ff = f.change_ring(K)
sage: p = PP((c,1))
sage: ff(ff(p)) == p
True
::
sage: P.<x,y> = ProjectiveSpace(QQ,1)
sage: H = Hom(P,P)
sage: f = H([x^2+y^2,x*y])
sage: f.dynatomic_polynomial([2,2])
x^4 + 4*x^2*y^2 + y^4
sage: R.<X> = PolynomialRing(QQ)
sage: K.<c> = NumberField(X^4 + 4*X^2 + 1)
sage: PP = P.change_ring(K)
sage: ff = f.change_ring(K)
sage: p = PP((c,1))
sage: ff.nth_iterate(p,4) == ff.nth_iterate(p,2)
True
"""
if self.domain() != self.codomain():
raise TypeError("Must have same domain and codomain to iterate")
from sage.schemes.projective.projective_space import is_ProjectiveSpace
if is_ProjectiveSpace(self.domain()) is False:
raise NotImplementedError("Not implemented for subschemes")
if self.domain().dimension_relative() > 1:
raise TypeError("Does not make sense in dimension >1")
if (isinstance(period, (list, tuple)) is False):
period = [0, period]
try:
period[0] = ZZ(period[0])
period[1] = ZZ(period[1])
except TypeError:
raise TypeError("Period and preperiod must be integers")
if period[1] <= 0:
raise AttributeError("Period must be at least 1")
if period[0] != 0:
m = period[0]
fm = self.nth_iterate_map(m)
fm1 = self.nth_iterate_map(m - 1)
n = period[1]
PHI = 1;
x = self.domain().gen(0)
y = self.domain().gen(1)
F = self._polys
f = F
for d in range(1, n + 1):
if n % d == 0:
PHI = PHI * ((y * F[0] - x * F[1]) ** moebius(n / d))
if d != n: #avoid extra iteration
F = [f[0](F[0], F[1]), f[1](F[0], F[1])]
if m != 0:
PHI = PHI(fm._polys) / PHI(fm1._polys)
else:
PHI = 1;
x = self.domain().gen(0)
y = self.domain().gen(1)
F = self._polys
f = F
for d in range(1, period[1] + 1):
if period[1] % d == 0:
PHI = PHI * ((y * F[0] - x * F[1]) ** moebius(period[1] / d))
if d != period[1]: #avoid extra iteration
F = [f[0](F[0], F[1]), f[1](F[0], F[1])]
from sage.rings.polynomial.polynomial_ring import PolynomialRing_general
from sage.rings.polynomial.multi_polynomial_ring_generic import MPolynomialRing_generic
if (self.domain().base_ring() == RealField()
or self.domain().base_ring() == ComplexField()):
PHI = PHI.numerator()._maxima_().divide(PHI.denominator())[0].sage()
elif isinstance(self.domain().base_ring(), (PolynomialRing_general, MPolynomialRing_generic)):
from sage.rings.padics.generic_nodes import is_pAdicField, is_pAdicRing
from sage.rings.function_field.function_field import is_FunctionField
BR = self.domain().base_ring().base_ring()
if is_pAdicField(BR) or is_pAdicRing(BR) or is_FunctionField(BR):
raise NotImplementedError("Not implemented")
PHI = PHI.numerator()._maxima_().divide(PHI.denominator())[0].sage()
#do it again to divide out by denominators of coefficients
PHI = PHI.numerator()._maxima_().divide(PHI.denominator())[0].sage()
if PHI.denominator() == 1:
PHI = self.coordinate_ring()(PHI)
return(PHI)
def nth_iterate_map(self, n):
r"""
For a map ``self`` this function returns the nth iterate of ``self`` as a
function on ``self.domain()``
ALGORITHM:
Uses a form of successive squaring to reducing computations.
.. TODO:: This could be improved.
INPUT:
- ``n`` -- a positive integer.
OUTPUT:
- A map between projective spaces
EXAMPLES::
sage: P.<x,y> = ProjectiveSpace(QQ,1)
sage: H = Hom(P,P)
sage: f = H([x^2+y^2,y^2])
sage: f.nth_iterate_map(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 + 2*y^4 : y^4)
::
sage: P.<x,y> = ProjectiveSpace(CC,1)
sage: H = Hom(P,P)
sage: f = H([x^2-y^2,x*y])
sage: f.nth_iterate_map(3)
Scheme endomorphism of Projective Space of dimension 1 over Complex
Field with 53 bits of precision
Defn: Defined on coordinates by sending (x : y) to
(x^8 + (-7.00000000000000)*x^6*y^2 + 13.0000000000000*x^4*y^4 +
(-7.00000000000000)*x^2*y^6 + y^8 : x^7*y + (-4.00000000000000)*x^5*y^3
+ 4.00000000000000*x^3*y^5 - x*y^7)
::
sage: P.<x,y,z> = ProjectiveSpace(ZZ,2)
sage: H = Hom(P,P)
sage: f = H([x^2-y^2,x*y,z^2+x^2])
sage: f.nth_iterate_map(2)
Scheme endomorphism of Projective Space of dimension 2 over Integer Ring
Defn: Defined on coordinates by sending (x : y : z) to
(x^4 - 3*x^2*y^2 + y^4 : x^3*y - x*y^3 : 2*x^4 - 2*x^2*y^2 + y^4
+ 2*x^2*z^2 + z^4)
::
sage: P.<x,y,z> = ProjectiveSpace(QQ,2)
sage: X = P.subscheme(x*z-y^2)
sage: H = Hom(X,X)
sage: f = H([x^2,x*z,z^2])
sage: f.nth_iterate_map(2)
Scheme endomorphism of Closed subscheme of Projective Space of dimension
2 over Rational Field defined by:
-y^2 + x*z
Defn: Defined on coordinates by sending (x : y : z) to
(x^4 : x^2*z^2 : z^4)
"""
if self.domain() != self.codomain():
raise TypeError("Domain and Codomain of function not equal")
if n < 0:
raise TypeError("Iterate number must be a positive integer")
N = self.codomain().ambient_space().dimension_relative() + 1
F = list(self._polys)
D = Integer(n).digits(2) #need base 2
Coord_ring = self.codomain().coordinate_ring()
if isinstance(Coord_ring, QuotientRing_generic):
PHI = [Coord_ring.gen(i).lift() for i in range(N)]
else:
PHI = [Coord_ring.gen(i) for i in range(N)]
for i in range(len(D)):
T = tuple([F[j] for j in range(N)])
for k in range(D[i]):
PHI = [PHI[j](T) for j in range(N)]
if i != len(D) - 1: #avoid extra iterate
F = [F[j](T) for j in range(N)] #'square'
H = Hom(self.domain(), self.codomain())
return(H(PHI))
def nth_iterate(self, P, n, normalize=False):
r"""
For a map ``self`` and a point `P` in ``self.domain()``
this function returns the nth iterate of `P` by ``self``.
If ``normalize`` is ``True``, then the coordinates are
automatically normalized.
.. TODO:: Is there a more efficient way to do this?
INPUT:
- ``P`` -- a point in ``self.domain()``
- ``n`` -- a positive integer.
- ``normalize`` - Boolean (optional Default: ``False``)
OUTPUT:
- A point in ``self.codomain()``
EXAMPLES::
sage: P.<x,y> = ProjectiveSpace(ZZ,1)
sage: H = Hom(P,P)
sage: f = H([x^2+y^2,2*y^2])
sage: Q = P(1,1)
sage: f.nth_iterate(Q,4)
(32768 : 32768)
::
sage: P.<x,y> = ProjectiveSpace(ZZ,1)
sage: H = Hom(P,P)
sage: f = H([x^2+y^2,2*y^2])
sage: Q = P(1,1)
sage: f.nth_iterate(Q,4,1)
(1 : 1)
Is this the right behavior? ::
sage: P.<x,y,z> = ProjectiveSpace(QQ,2)
sage: H = Hom(P,P)
sage: f = H([x^2,2*y^2,z^2-x^2])
sage: Q = P(2,7,1)
sage: f.nth_iterate(Q,2)
(-16/7 : -2744 : 1)
::
sage: R.<t> = PolynomialRing(QQ)
sage: P.<x,y,z> = ProjectiveSpace(R,2)
sage: H = Hom(P,P)
sage: f = H([x^2+t*y^2,(2-t)*y^2,z^2])
sage: Q = P(2+t,7,t)
sage: f.nth_iterate(Q,2)
(t^4 + 2507*t^3 - 6787*t^2 + 10028*t + 16 : -2401*t^3 + 14406*t^2 -
28812*t + 19208 : t^4)
::
sage: P.<x,y,z> = ProjectiveSpace(ZZ,2)
sage: X = P.subscheme(x^2-y^2)
sage: H = Hom(X,X)
sage: f = H([x^2,y^2,z^2])
sage: f.nth_iterate(X(2,2,3),3)
(256 : 256 : 6561)
::
sage: K.<c> = FunctionField(QQ)
sage: P.<x,y> = ProjectiveSpace(K,1)
sage: H = Hom(P,P)
sage: f = H([x^3-2*x*y^2 - c*y^3,x*y^2])
sage: f.nth_iterate(P(c,1),2)
((c^6 - 9*c^4 + 25*c^2 - c - 21)/(c^2 - 3) : 1)
"""
return(P.nth_iterate(self, n, normalize))
def degree(self):
r"""
This function returns the degree of ``self``.
The degree is defined as the degree of the homogeneous
polynomials that are the coordinates of ``self``.
OUTPUT:
- A positive integer
EXAMPLES::
sage: P.<x,y> = ProjectiveSpace(QQ,1)
sage: H = Hom(P,P)
sage: f = H([x^2+y^2,y^2])
sage: f.degree()
2
::
sage: P.<x,y,z> = ProjectiveSpace(CC,2)
sage: H = Hom(P,P)
sage: f = H([x^3+y^3,y^2*z,z*x*y])
sage: f.degree()
3
::
sage: R.<t> = PolynomialRing(QQ)
sage: P.<x,y,z> = ProjectiveSpace(R,2)
sage: H = Hom(P,P)
sage: f = H([x^2+t*y^2,(2-t)*y^2,z^2])
sage: f.degree()
2
::
sage: P.<x,y,z> = ProjectiveSpace(ZZ,2)
sage: X = P.subscheme(x^2-y^2)
sage: H = Hom(X,X)
sage: f = H([x^2,y^2,z^2])
sage: f.degree()
2
"""
return(self._polys[0].degree())
def dehomogenize(self, n):
r"""
Returns the standard dehomogenization at the ``n[0]`` coordinate for the domain
and the ``n[1]`` coordinate for the codomain.
Note that the new function is defined over the fraction field
of the base ring of ``self``.
INPUT:
- ``n`` -- a tuple of nonnegative integers. If ``n`` is an integer, then the two values of
the tuple are assumed to be the same.
OUTPUT:
- :class:`SchemeMorphism_polynomial_affine_space`
EXAMPLES::
sage: P.<x,y> = ProjectiveSpace(ZZ,1)
sage: H = Hom(P,P)
sage: f = H([x^2+y^2,y^2])
sage: f.dehomogenize(0)
Scheme endomorphism of Affine Space of dimension 1 over Integer Ring
Defn: Defined on coordinates by sending (x) to
(x^2/(x^2 + 1))
::
sage: P.<x,y> = ProjectiveSpace(QQ,1)
sage: H = Hom(P,P)
sage: f = H([x^2-y^2,y^2])
sage: f.dehomogenize((0,1))
Scheme morphism:
From: Affine Space of dimension 1 over Rational Field
To: Affine Space of dimension 1 over Rational Field
Defn: Defined on coordinates by sending (x) to
((-x^2 + 1)/x^2)
::
sage: P.<x,y,z> = ProjectiveSpace(QQ,2)
sage: H = Hom(P,P)
sage: f = H([x^2+y^2,y^2-z^2,2*z^2])
sage: f.dehomogenize(2)
Scheme endomorphism of Affine Space of dimension 2 over Rational Field
Defn: Defined on coordinates by sending (x0, x1) to
(1/2*x0^2 + 1/2*x1^2, 1/2*x1^2 - 1/2)
::
sage: R.<t> = PolynomialRing(QQ)
sage: P.<x,y,z> = ProjectiveSpace(FractionField(R),2)
sage: H = Hom(P,P)
sage: f = H([x^2+t*y^2,t*y^2-z^2,t*z^2])
sage: f.dehomogenize(2)
Scheme endomorphism of Affine Space of dimension 2 over Fraction Field
of Univariate Polynomial Ring in t over Rational Field
Defn: Defined on coordinates by sending (x0, x1) to
(1/t*x0^2 + x1^2, x1^2 - 1/t)
::
sage: P.<x,y,z> = ProjectiveSpace(ZZ,2)