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
4338 lines (3484 loc) · 158 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
- Ben Hutz (2015-11): iteration of subschemes
"""
# 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.calculus.functions import jacobian
from sage.categories.number_fields import NumberFields
from sage.categories.homset import Hom, End
from sage.combinat.sf.sf import SymmetricFunctions
from sage.functions.all import sqrt
from sage.libs.pari.all import PariError
from sage.matrix.constructor import matrix, identity_matrix
from sage.misc.all import prod
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, CIF
from sage.rings.arith import gcd, lcm, next_prime, binomial, primes
from sage.rings.complex_field import ComplexField_class,ComplexField
from sage.rings.complex_interval_field import ComplexIntervalField_class
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.fraction_field_element import is_FractionFieldElement, FractionFieldElement
from sage.rings.integer_ring import ZZ
from sage.rings.number_field.order import is_NumberFieldOrder
from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing
from sage.rings.qqbar import QQbar, number_field_elements_from_algebraics
from sage.rings.quotient_ring import QuotientRing_generic
from sage.rings.qqbar import QQbar
from sage.rings.rational_field import QQ
from sage.rings.real_mpfr import RealField_class,RealField
from sage.rings.real_mpfi import RealIntervalField_class
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
from sage.categories.number_fields import NumberFields
_NumberFields = NumberFields()
class SchemeMorphism_polynomial_projective_space(SchemeMorphism_polynomial):
r"""
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
We can also compute the forward image of subschemes through
elimination. In particular, let `X = V(h_1,\ldots, h_t)` and define the ideal
`I = (h_1,\ldots,h_t,y_0-f_0(\bar{x}), \ldots, y_n-f_n(\bar{x}))`.
Then the elimination ideal `I_{n+1} = I \cap K[y_0,\ldots,y_n]` is a homogeneous
ideal and `f(X) = V(I_{n+1})`::
sage: P.<x,y,z> = ProjectiveSpace(QQ, 2)
sage: H = End(P)
sage: f = H([(x-2*y)^2, (x-2*z)^2, x^2])
sage: X = P.subscheme(y-z)
sage: f(f(f(X)))
Closed subscheme of Projective Space of dimension 2 over Rational Field
defined by:
y - z
::
sage: P.<x,y,z,w> = ProjectiveSpace(QQ, 3)
sage: H = End(P)
sage: f = H([(x-2*y)^2, (x-2*z)^2, (x-2*w)^2, x^2])
sage: f(P.subscheme([x,y,z]))
Closed subscheme of Projective Space of dimension 3 over Rational Field
defined by:
w,
y,
x
"""
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):
"""
Compute the forward image of the point or subscheme ``x`` by the map ``self``.
For subschemes, the forward image is computed through elimination.
In particular, let $X = V(h_1,\ldots, h_t)$ and define the ideal
$I = (h_1,\ldots,h_t,y_0-f_0(\bar{x}), \ldots, y_n-f_n(\bar{x}))$.
Then the elimination ideal $I_{n+1} = I \cap K[y_0,\ldots,y_n]$ is a homogeneous
ideal and $self(X) = V(I_{n+1})$.
The input boolean ``check`` can be set to false when fast iteration of
points is desired. It bypasses all input checking and passes ``x`` straight
to the fast evaluation of points function.
INPUT:
- ``x`` - a point or subscheme in domain of ``self``
- ``check`` - Boolean - if `False` assume that ``x`` is a point
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)
::
sage: PS.<x,y,z,w>=ProjectiveSpace(QQ,3)
sage: H=End(PS)
sage: f=H([y^2,x^2,w^2,z^2])
sage: X=PS.subscheme([z^2+y*w])
sage: f(X)
Closed subscheme of Projective Space of dimension 3 over Rational Field
defined by:
x*z - w^2
"""
from sage.schemes.projective.projective_point import SchemeMorphism_point_projective_ring
if check:
from sage.schemes.generic.algebraic_scheme import AlgebraicScheme_subscheme_projective
if isinstance(x, SchemeMorphism_point_projective_ring):
if self.domain() != x.codomain():
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()))
#else pass it onto the eval below
elif isinstance(x, AlgebraicScheme_subscheme_projective):
if self.domain() != x.ambient_space():
try:
x = self.domain().subscheme(x.defining_polynomials())
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()))
return x.forward_image(self) #call subscheme eval
else: #not a projective point or subscheme
try:
x = self.domain()(x)
except (TypeError, NotImplementedError):
try:
x = self.domain().subscheme(x)
return x.forward_image(self) #call subscheme eval
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()))
# 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 morphisms.
INPUT:
- ``right`` - a map on projective space
OUTPUT:
- Boolean - True if ``self`` and ``right`` define the same projective map. False otherwise.
EXAMPLES::
sage: P.<x,y,z> = ProjectiveSpace(QQ, 2)
sage: H = Hom(P,P)
sage: f = H([x^2 - 2*x*y + z*x, z^2 -y^2 , 5*z*y])
sage: g = H([x^2, y^2, z^2])
sage: f == g
False
::
sage: P.<x,y> = ProjectiveSpace(QQ, 1)
sage: P2.<u,v> = ProjectiveSpace(CC, 1)
sage: H = End(P)
sage: H2 = End(P2)
sage: f = H([x^2 - 2*x*y, y^2])
sage: g = H2([u^2 - 2*u*v, v^2])
sage: f == g
False
::
sage: P.<x,y> = ProjectiveSpace(QQ, 1)
sage: H = End(P)
sage: f = H([x^2 - 2*x*y, y^2])
sage: g = H([x^2*y - 2*x*y^2, y^3])
sage: f == g
True
"""
if not isinstance(right, SchemeMorphism_polynomial):
return False
if self.parent() != right.parent():
return False
n = len(self._polys)
return all([self[i]*right[j] == self[j]*right[i] for i in range(0, n) for j in range(i+1, n)])
def __ne__(self, right):
"""
Tests the inequality of two projective morphisms.
INPUT:
- ``right`` -- a map on projective space
OUTPUT:
- Boolean -- True if ``self`` and ``right`` define different projective maps. False otherwise.
EXAMPLES::
sage: P.<x,y> = ProjectiveSpace(QQ, 1)
sage: H = Hom(P,P)
sage: f = H([x^3 - 2*x^2*y , 5*x*y^2])
sage: g = f.change_ring(GF(7))
sage: f != g
True
::
sage: P.<x,y,z> = ProjectiveSpace(QQ, 2)
sage: H = Hom(P, P)
sage: f = H([x^2 - 2*x*y + z*x, z^2 -y^2 , 5*z*y])
sage: f != f
False
"""
if not isinstance(right, SchemeMorphism_polynomial):
return True
if self.parent() != right.parent():
return True
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`. If possible the division is
done in the coordinate ring of ``self`` and a polynomial is returned. In rings where that is not possible,
a FractionField element will be returned. In certain cases, when the conversion back to a polynomial
fails, a SymbolRing element will be returned.
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``. Or,
a Symbolic Ring element.
.. TODO::
- Do the division when the base ring is p-adic so that the output is a polynomial.
- Convert back to a polynomial when the base ring is a function field (not over `\QQ` or `F_p`)
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)
::
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
::
sage: P.<x,y> = ProjectiveSpace(CC, 1)
sage: H = Hom(P,P)
sage: f = H([x^2-CC.0/3*y^2,y^2])
sage: f.dynatomic_polynomial(2)
0.666666666666667*x^2 + 0.333333333333333*y^2
::
sage: L.<t> = PolynomialRing (QuadraticField(2).maximal_order())
sage: P.<x, y> = ProjectiveSpace (L.fraction_field() , 1 )
sage: H = Hom (P, P )
sage: f = H ([x^2 + (t ^ 2 + 1) * y^2 , y^2 ])
sage: f.dynatomic_polynomial(2)
x^2 + x*y + (t^2 + 2)*y^2
TESTS:
We check that the dynatomic polynomial has the right parent (see :trac:`18409`)::
sage: P.<x,y> = ProjectiveSpace(QQbar,1)
sage: H = End(P)
sage: R = P.coordinate_ring()
sage: f = H([x^2-1/3*y^2,y^2])
sage: f.dynatomic_polynomial(2).parent()
Multivariate Polynomial Ring in x, y over Algebraic Field
::
sage: T.<v> = QuadraticField(33)
sage: S.<t> = PolynomialRing(T)
sage: P.<x,y> = ProjectiveSpace(FractionField(S),1)
sage: H = End(P)
sage: f = H([t*x^2-1/t*y^2,y^2])
sage: f.dynatomic_polynomial([1,2]).parent()
Multivariate Polynomial Ring in x, y over Fraction Field of Univariate Polynomial
Ring in t over Number Field in v with defining polynomial x^2 - 33
This one still does not work, some function fields still return Symoblic Ring elements::
sage: S.<t> = FunctionField(CC)
sage: P.<x,y> = ProjectiveSpace(S,1)
sage: H = End(P)
sage: R = P.coordinate_ring()
sage: f = H([t*x^2-1*y^2,t*y^2])
sage: f.dynatomic_polynomial([1,2]).parent()
Symbolic Ring
"""
if self.domain().ngens() > 2:
raise TypeError("Does not make sense in dimension >1")
if not isinstance(period, (list, tuple)):
period = [0, period]
x = self.domain().gen(0)
y = self.domain().gen(1)
f0, f1 = F0, F1 = self._polys
PHI = self.base_ring().one()
n = period[1]
if period[0] != 0:
m = period[0]
fm = self.nth_iterate_map(m)
fm1 = self.nth_iterate_map(m - 1)
for d in range(1, n):
if n % d == 0:
PHI = PHI * ((y*F0 - x*F1) ** moebius(n/d))
F0, F1 = f0(F0, F1), f1(F0, F1)
PHI = PHI * (y*F0 - x*F1)
if m != 0:
PHI = PHI(fm._polys)/ PHI(fm1._polys )
else:
for d in range(1, n):
if n % d == 0:
PHI = PHI * ((y*F0 - x*F1) ** moebius(n//d))
F0, F1 = f0(F0, F1), f1(F0, F1)
PHI = PHI * (y*F0 - x*F1)
try:
QR = PHI.numerator().quo_rem(PHI.denominator())
if not QR[1]:
return(QR[0])
except TypeError: # something Singular can't handle
pass
#even when the ring can be passed to singular in quo_rem,
#it can't always do the division, so we call Maxima
from sage.rings.padics.generic_nodes import is_pAdicField, is_pAdicRing
if period != [0,1]: #period==[0,1] we don't need to do any division
BR = self.domain().base_ring().base_ring()
if not (is_pAdicRing(BR) or is_pAdicField(BR)):
try:
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 not is_FractionFieldElement(PHI):
from sage.symbolic.expression_conversions import polynomial
PHI = polynomial(PHI, ring=self.coordinate_ring())
except (TypeError, NotImplementedError): #something Maxima, or the conversion, can't handle
pass
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)
"""
E = self.domain()
if E is not self.codomain():
raise TypeError("Domain and Codomain of function not equal")
D = int(n)
if D < 0:
raise TypeError("Iterate number must be a positive integer")
N = self.codomain().ambient_space().dimension_relative() + 1
F = list(self._polys)
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)]
while D:
if D&1:
PHI = [PHI[j](*F) for j in range(N)]
if D > 1: #avoid extra iterate
F = [F[j](*F) for j in range(N)] #'square'
D >>= 1
return End(E)(PHI)
def nth_iterate(self, P, n, **kwds):
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.
kwds:
- ``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,normalize = True)
(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)