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
/
affine_morphism.py
689 lines (545 loc) · 23.2 KB
/
affine_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
r"""
Morphisms on affine varieties
A morphism of schemes determined by rational functions that define
what the morphism does on points in the ambient affine space.
AUTHORS:
- David Kohel, William Stein
- Volker Braun (2011-08-08): Renamed classes, more documentation, misc
cleanups.
- Ben Hutz (2013-03) iteration functionality and new directory structure
for affine/projective
"""
# 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.homset import Hom
from sage.misc.misc import prod
from sage.rings.all import Integer, moebius
from sage.rings.arith import lcm, gcd
from sage.rings.complex_field import ComplexField
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.real_mpfr import RealField
from sage.schemes.generic.morphism import SchemeMorphism_polynomial
class SchemeMorphism_polynomial_affine_space(SchemeMorphism_polynomial):
"""
A morphism of schemes determined by rational functions that define
what the morphism does on points in the ambient affine space.
EXAMPLES::
sage: RA.<x,y> = QQ[]
sage: A2 = AffineSpace(RA)
sage: RP.<u,v,w> = QQ[]
sage: P2 = ProjectiveSpace(RP)
sage: H = A2.Hom(P2)
sage: f = H([x, y, 1])
sage: f
Scheme morphism:
From: Affine Space of dimension 2 over Rational Field
To: Projective Space of dimension 2 over Rational Field
Defn: Defined on coordinates by sending (x, y) to
(x : y : 1)
"""
def __init__(self, parent, polys, check=True):
r"""
The Python constructor.
See :class:`SchemeMorphism_polynomial` for details.
INPUT:
- ``parent`` -- Hom
- ``polys`` -- list or tuple of polynomial or rational functions
- ``check`` -- Boolean
OUTPUT:
- :class:`SchemeMorphism_polynomial_affine_space`
EXAMPLES::
sage: A.<x,y>=AffineSpace(ZZ,2)
sage: H=Hom(A,A)
sage: H([3/5*x^2,y^2/(2*x^2)])
Traceback (most recent call last):
...
TypeError: polys (=[3/5*x^2, y^2/(2*x^2)]) must be rational functions in
Multivariate Polynomial Ring in x, y over Integer Ring
::
sage: A.<x,y>=AffineSpace(ZZ,2)
sage: H=Hom(A,A)
sage: H([3*x^2/(5*y),y^2/(2*x^2)])
Scheme endomorphism of Affine Space of dimension 2 over Integer Ring
Defn: Defined on coordinates by sending (x, y) to
(3*x^2/(5*y), y^2/(2*x^2))
sage: A.<x,y>=AffineSpace(QQ,2)
sage: H=Hom(A,A)
sage: H([3/2*x^2,y^2])
Scheme endomorphism of Affine Space of dimension 2 over Rational Field
Defn: Defined on coordinates by sending (x, y) to
(3/2*x^2, y^2)
sage: A.<x,y>=AffineSpace(QQ,2)
sage: X=A.subscheme([x-y^2])
sage: H=Hom(X,X)
sage: H([9/4*x^2,3/2*y])
Scheme endomorphism of Closed subscheme of Affine Space of dimension 2
over Rational Field defined by:
-y^2 + x
Defn: Defined on coordinates by sending (x, y) to
(9/4*x^2, 3/2*y)
sage: P.<x,y,z>=ProjectiveSpace(ZZ,2)
sage: H=Hom(P,P)
sage: f=H([5*x^3 + 3*x*y^2-y^3,3*z^3 + y*x^2, x^3-z^3])
sage: f.dehomogenize(2)
Scheme endomorphism of Affine Space of dimension 2 over Integer Ring
Defn: Defined on coordinates by sending (x0, x1) to
((5*x0^3 + 3*x0*x1^2 - x1^3)/(x0^3 - 1), (x0^2*x1 + 3)/(x0^3 - 1))
"""
if check:
if not isinstance(polys, (list, tuple)):
raise TypeError("polys (=%s) must be a list or tuple"%polys)
source_ring =parent.domain().ambient_space().coordinate_ring()
target = parent.codomain().ambient_space()
if len(polys) != target.ngens():
raise ValueError("there must be %s polynomials"%target.ngens())
try:
polys = [source_ring(poly) for poly in polys]
except TypeError:
if all(p.base_ring()==source_ring.base_ring() for p in polys)==False:
raise TypeError("polys (=%s) must be rational functions in %s"%(polys,source_ring))
try:
polys = [source_ring(poly.numerator())/source_ring(poly.denominator()) for poly in polys]
except TypeError:
raise TypeError("polys (=%s) must be rational functions in %s"%(polys,source_ring))
if isinstance(source_ring, QuotientRing_generic):
polys = [f.lift() for f in polys]
SchemeMorphism_polynomial.__init__(self, parent,polys, False)
def homogenize(self,n):
r"""
Return the homogenization of ``self``. If ``self.domain()`` is a subscheme, the domain of
the homogenized map is the projective embedding of ``self.domain()``. The domain and codomain
can be homogenized at different coordinates: ``n[0]`` for the domain and ``n[1]`` for the codomain.
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:`SchemMorphism_polynomial_projective_space`
EXAMPLES::
sage: A.<x,y> = AffineSpace(ZZ,2)
sage: H = Hom(A,A)
sage: f = H([(x^2-2)/x^5,y^2])
sage: f.homogenize(2)
Scheme endomorphism of Projective Space of dimension 2 over Integer Ring
Defn: Defined on coordinates by sending (x0 : x1 : x2) to
(x0^2*x2^5 - 2*x2^7 : x0^5*x1^2 : x0^5*x2^2)
::
sage: A.<x,y> = AffineSpace(CC,2)
sage: H = Hom(A,A)
sage: f = H([(x^2-2)/(x*y),y^2-x])
sage: f.homogenize((2,0))
Scheme morphism:
From: Projective Space of dimension 2 over Complex Field with 53 bits of precision
To: Projective Space of dimension 2 over Complex Field with 53 bits of precision
Defn: Defined on coordinates by sending (x0 : x1 : x2) to
(x0*x1*x2^2 : x0^2*x2^2 + (-2.00000000000000)*x2^4 : x0*x1^3 - x0^2*x1*x2)
::
sage: A.<x,y> = AffineSpace(ZZ,2)
sage: X = A.subscheme([x-y^2])
sage: H = Hom(X,X)
sage: f = H([9*y^2,3*y])
sage: f.homogenize(2)
Scheme endomorphism of Closed subscheme of Projective Space of dimension 2 over Integer Ring defined by:
-x1^2 + x0*x2
Defn: Defined on coordinates by sending (x0 : x1 : x2) to
(9*x0*x2 : 3*x1*x2 : x2^2)
::
sage: R.<t> = PolynomialRing(ZZ)
sage: A.<x,y> = AffineSpace(R,2)
sage: H = Hom(A,A)
sage: f = H([(x^2-2)/y,y^2-x])
sage: f.homogenize((2,0))
Scheme morphism:
From: Projective Space of dimension 2 over Univariate Polynomial Ring in t over Integer Ring
To: Projective Space of dimension 2 over Univariate Polynomial Ring in t over Integer Ring
Defn: Defined on coordinates by sending (x0 : x1 : x2) to
(x1*x2^2 : x0^2*x2 + (-2)*x2^3 : x1^3 - x0*x1*x2)
::
sage: A.<x> = AffineSpace(QQ,1)
sage: H = End(A)
sage: f = H([x^2-1])
sage: f.homogenize((1,0))
Scheme morphism:
From: Projective Space of dimension 1 over Rational Field
To: Projective Space of dimension 1 over Rational Field
Defn: Defined on coordinates by sending (x0 : x1) to
(x1^2 : x0^2 - x1^2)
::
R.<a> = PolynomialRing(QQbar)
A.<x,y> = AffineSpace(R,2)
H = End(A)
f = H([QQbar(sqrt(2))*x*y,a*x^2])
f.homogenize(2)
Scheme endomorphism of Projective Space of dimension 2 over Univariate
Polynomial Ring in a over Algebraic Field
Defn: Defined on coordinates by sending (x0 : x1 : x2) to
(1.414213562373095?*x0*x1 : a*x0^2 : x2^2)
"""
#it is possible to homogenize the domain and codomain at different coordinates
if isinstance(n,(tuple,list)):
ind = tuple(n)
else:
ind = (n,n)
#homogenize the domain and codomain
A = self.domain().projective_embedding(ind[0]).codomain()
B = self.codomain().projective_embedding(ind[1]).codomain()
H = Hom(A,B)
newvar = A.ambient_space().coordinate_ring().gen(ind[0])
N = A.ambient_space().dimension_relative()
M = B.ambient_space().dimension_relative()
#create dictionary for mapping of coordinate rings
R = self.domain().ambient_space().coordinate_ring()
S = A.ambient_space().coordinate_ring()
Rvars = R.gens()
vars = list(S.gens())
vars.remove(S.gen(ind[0]))
D = dict([[Rvars[i],vars[i]] for i in range(N)])
#clear the denominators if a rational function
L= [self[i].denominator() for i in range(M)]
l = [prod(L[:j] + L[j+1:M]) for j in range(M)]
F = [S(R(self[i].numerator()*l[i]).subs(D)) for i in range(M)]
#homogenize
DR = B.ambient_space().coordinate_ring()
F.insert(ind[1], S(prod(L).subs(D))) #coerce in case l is a constant
try:
#remove possible gcd of the polynomials
g=gcd(F)
F=[DR(f/g) for f in F]
#remove possible gcd of coefficients
gc = gcd([f.content() for f in F])
F=[DR(f/gc) for f in F]
except AttributeError: #no gcd
pass
d = max([F[i].degree() for i in range(M+1)])
F = [F[i].homogenize(str(newvar))*newvar**(d-F[i].degree()) for i in range(M+1)]
return(H(F))
def dynatomic_polynomial(self,period):
r"""
For a map `f:\mathbb{A}^1 \to \mathbb{A}^1` this function computes the (affine) dynatomic polynomial.
The dynatomic polynomial is the analog of the cyclotomic polynomial and its roots are the points
of formal period `n`.
ALGORITHM:
Homogenize to a map `f:\mathbb{P}^1 \to \mathbb{P}^1` and compute the dynatomic polynomial there.
Then, dehomogenize.
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 single variable polynomial in the coordinate ring of ``self``.
Otherwise a fraction field element of the coordinate ring of ``self``
EXAMPLES::
sage: A.<x,y>=AffineSpace(QQ,2)
sage: H=Hom(A,A)
sage: f=H([x^2+y^2,y^2])
sage: f.dynatomic_polynomial(2)
Traceback (most recent call last):
...
TypeError: Does not make sense in dimension >1
::
sage: A.<x>=AffineSpace(ZZ,1)
sage: H=Hom(A,A)
sage: f=H([(x^2+1)/x])
sage: f.dynatomic_polynomial(4)
2*x^12 + 18*x^10 + 57*x^8 + 79*x^6 + 48*x^4 + 12*x^2 + 1
::
sage: A.<x>=AffineSpace(CC,1)
sage: H=Hom(A,A)
sage: f=H([(x^2+1)/(3*x)])
sage: f.dynatomic_polynomial(3)
13.0000000000000*x^6 + 117.000000000000*x^4 + 78.0000000000000*x^2 +
1.00000000000000
::
sage: A.<x>=AffineSpace(QQ,1)
sage: H=Hom(A,A)
sage: f=H([x^2-10/9])
sage: f.dynatomic_polynomial([2,1])
531441*x^4 - 649539*x^2 - 524880
"""
if self.domain() != self.codomain():
raise TypeError("Must have same domain and codomain to iterate")
from sage.schemes.affine.affine_space import is_AffineSpace
if is_AffineSpace(self.domain())==False:
raise NotImplementedError("Not implemented for subschemes")
if self.domain().dimension_relative()>1:
raise TypeError("Does not make sense in dimension >1")
F=self.homogenize(1).dynatomic_polynomial(period)
if F.denominator()==1:
R=F.parent()
S=self.coordinate_ring()
phi=R.hom([S.gen(0),1],S)
return(phi(F))
else:
R=F.numerator().parent()
S=self.coordinate_ring()
phi=R.hom([S.gen(0),1],S)
return(phi(F.numerator())/phi(F.denominator()))
def nth_iterate_map(self,n):
r"""
This function returns the nth iterate of ``self``
ALGORITHM:
Uses a form of successive squaring to reducing computations.
.. TODO:: This could be improved.
INPUT:
- ``n`` - a positive integer.
OUTPUT:
- A map between Affine spaces
EXAMPLES::
sage: A.<x,y>=AffineSpace(ZZ,2)
sage: H=Hom(A,A)
sage: f=H([(x^2-2)/(2*y),y^2-3*x])
sage: f.nth_iterate_map(2)
Scheme endomorphism of Affine Space of dimension 2 over Integer Ring
Defn: Defined on coordinates by sending (x, y) to
((x^4 - 4*x^2 - 8*y^2 + 4)/(8*y^4 - 24*x*y^2), (2*y^5 - 12*x*y^3
+ 18*x^2*y - 3*x^2 + 6)/(2*y))
::
sage: A.<x>=AffineSpace(QQ,1)
sage: H=Hom(A,A)
sage: f=H([(3*x^2-2)/(x)])
sage: f.nth_iterate_map(3)
Scheme endomorphism of Affine Space of dimension 1 over Rational Field
Defn: Defined on coordinates by sending (x) to
((2187*x^8 - 6174*x^6 + 6300*x^4 - 2744*x^2 + 432)/(81*x^7 -
168*x^5 + 112*x^3 - 24*x))
::
sage: A.<x,y>=AffineSpace(ZZ,2)
sage: X=A.subscheme([x-y^2])
sage: H=Hom(X,X)
sage: f=H([9*x^2,3*y])
sage: f.nth_iterate_map(2)
Scheme endomorphism of Closed subscheme of Affine Space of dimension 2
over Integer Ring defined by:
-y^2 + x
Defn: Defined on coordinates by sending (x, y) to
(729*x^4, 9*y)
"""
if self.domain() != self.codomain():
raise TypeError("Domain and Codomain of function not equal")
N=self.codomain().ambient_space().dimension_relative()
F=list(self._polys)
R=F[0].parent()
Coord_ring=self.codomain().coordinate_ring()
D=Integer(n).digits(2)
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=[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=[R(F[j](T)) for j in range(N)] #'square'
H=Hom(self.domain(),self.codomain())
return(H(PHI))
def nth_iterate(self,P,n):
r"""
Returns the point `self^n(P)`
INPUT:
- ``P`` -- a point in ``self.domain()``
- ``n`` -- a positive integer.
OUTPUT:
- a point in ``self.codomain()``
EXAMPLES::
sage: A.<x,y>=AffineSpace(QQ,2)
sage: H=Hom(A,A)
sage: f=H([(x-2*y^2)/x,3*x*y])
sage: f.nth_iterate(A(9,3),3)
(-104975/13123, -9566667)
::
sage: A.<x,y>=AffineSpace(ZZ,2)
sage: X=A.subscheme([x-y^2])
sage: H=Hom(X,X)
sage: f=H([9*y^2,3*y])
sage: f.nth_iterate(X(9,3),4)
(59049, 243)
::
sage: R.<t>=PolynomialRing(QQ)
sage: A.<x,y>=AffineSpace(FractionField(R),2)
sage: H=Hom(A,A)
sage: f=H([(x-t*y^2)/x,t*x*y])
sage: f.nth_iterate(A(1,t),3)
((-t^16 + 3*t^13 - 3*t^10 + t^7 + t^5 + t^3 - 1)/(t^5 + t^3 - 1), -t^9 - t^7 + t^4)
"""
return(P.nth_iterate(self,n))
def orbit(self,P,n):
r"""
Returns the orbit of `P` by ``self``. If `n` is an integer it returns `[P,self(P),\ldots,self^n(P)]`.
If `n` is a list or tuple `n=[m,k]` it returns `[self^m(P),\ldots,self^k(P)]`
INPUT:
- ``P`` -- a point in ``self.domain()``
- ``n`` -- a non-negative integer or list or tuple of two non-negative integers
OUTPUT:
- a list of points in ``self.codomain()``
EXAMPLES::
sage: A.<x,y>=AffineSpace(QQ,2)
sage: H=Hom(A,A)
sage: f=H([(x-2*y^2)/x,3*x*y])
sage: f.orbit(A(9,3),3)
[(9, 3), (-1, 81), (13123, -243), (-104975/13123, -9566667)]
::
sage: A.<x>=AffineSpace(QQ,1)
sage: H=Hom(A,A)
sage: f=H([(x-2)/x])
sage: f.orbit(A(1/2),[1,3])
[(-3), (5/3), (-1/5)]
::
sage: A.<x,y>=AffineSpace(ZZ,2)
sage: X=A.subscheme([x-y^2])
sage: H=Hom(X,X)
sage: f=H([9*y^2,3*y])
sage: f.orbit(X(9,3),(0,4))
[(9, 3), (81, 9), (729, 27), (6561, 81), (59049, 243)]
::
sage: R.<t>=PolynomialRing(QQ)
sage: A.<x,y>=AffineSpace(FractionField(R),2)
sage: H=Hom(A,A)
sage: f=H([(x-t*y^2)/x,t*x*y])
sage: f.orbit(A(1,t),3)
[(1, t), (-t^3 + 1, t^2), ((-t^5 - t^3 + 1)/(-t^3 + 1), -t^6 + t^3),
((-t^16 + 3*t^13 - 3*t^10 + t^7 + t^5 + t^3 - 1)/(t^5 + t^3 - 1), -t^9 -
t^7 + t^4)]
"""
return(P.orbit(self,n))
def global_height(self,prec=None):
r"""
Returns the maximum of the heights of the coefficients in any of the coordinate functions of ``self``.
INPUT:
- ``prec`` -- desired floating point precision (default:
default RealField precision).
OUTPUT:
- a real number
EXAMPLES::
sage: A.<x>=AffineSpace(QQ,1)
sage: H=Hom(A,A)
sage: f=H([1/1331*x^2+4000]);
sage: f.global_height()
8.29404964010203
::
sage: R.<x>=PolynomialRing(QQ)
sage: k.<w>=NumberField(x^2+5)
sage: A.<x,y>=AffineSpace(k,2)
sage: H=Hom(A,A)
sage: f=H([13*w*x^2+4*y, 1/w*y^2]);
sage: f.global_height(prec=100)
3.3696683136785869233538671082
.. TODO::
add heights to integer.pyx and remove special case
"""
if self.domain().base_ring() == ZZ:
if prec is None:
R = RealField()
else:
R = RealField(prec)
H=R(0)
for i in range(self.domain().ambient_space().dimension_relative()):
C=self[i].coefficients()
h=max([c.abs() for c in C])
H=max(H,R(h).log())
return(H)
H=0
for i in range(self.domain().ambient_space().dimension_relative()):
C=self[i].coefficients()
if C==[]: #to deal with the case self[i]=0
h=0
else:
h=max([c.global_height(prec) for c in C])
H=max(H,h)
return(H)
def jacobian (self):
r"""
Returns the Jacobian matrix of partial derivitive of ``self`` in which the
``(i,j)`` entry of the Jacobian matrix is the partial derivative ``diff(functions[i], variables[j]``.
OUTPUT:
- matrix with coordinates in the coordinate ring of ``self``
EXAMPLES::
sage: A.<z> = AffineSpace(QQ,1)
sage: H = End(A)
sage: f = H([z^2-3/4])
sage: f.jacobian()
[2*z]
::
sage: A.<x,y> = AffineSpace(QQ,2)
sage: H = End(A)
sage: f = H([x^3 - 25*x + 12*y,5*y^2*x - 53*y + 24])
sage: f.jacobian()
[ 3*x^2 - 25 12]
[ 5*y^2 10*x*y - 53]
::
sage: A.<x,y> = AffineSpace(ZZ,2)
sage: H = End(A)
sage: f = H([(x^2 - x*y)/(1+y),(5+y)/(2+x)])
sage: f.jacobian()
[ (2*x - y)/(y + 1) (-x^2 - x)/(y^2 + 2*y + 1)]
[ (-y - 5)/(x^2 + 4*x + 4) 1/(x + 2)]
"""
try:
return self.__jacobian
except AttributeError:
pass
self.__jacobian = jacobian(list(self),self.domain().gens())
return self.__jacobian
class SchemeMorphism_polynomial_affine_space_field(SchemeMorphism_polynomial_affine_space):
pass
class SchemeMorphism_polynomial_affine_space_finite_field(SchemeMorphism_polynomial_affine_space_field):
def cyclegraph(self):
r"""
returns Digraph of all orbits of self mod `p`. For subschemes, only points on the subscheme whose
image are also on the subscheme are in the digraph.
OUTPUT:
- a digraph
EXAMPLES::
sage: P.<x,y>=AffineSpace(GF(5),2)
sage: H=Hom(P,P)
sage: f=H([x^2-y,x*y+1])
sage: f.cyclegraph()
Looped digraph on 25 vertices
::
sage: P.<x>=AffineSpace(GF(3^3,'t'),1)
sage: H=Hom(P,P)
sage: f=H([x^2-1])
sage: f.cyclegraph()
Looped digraph on 27 vertices
::
sage: P.<x,y>=AffineSpace(GF(7),2)
sage: X=P.subscheme(x-y)
sage: H=Hom(X,X)
sage: f=H([x^2,y^2])
sage: f.cyclegraph()
Looped digraph on 7 vertices
"""
if self.domain() != self.codomain():
raise NotImplementedError("Domain and Codomain must be equal")
V=[]
E=[]
from sage.schemes.affine.affine_space import is_AffineSpace
if is_AffineSpace(self.domain())==True:
for P in self.domain():
V.append(str(P))
Q=self(P)
E.append([str(Q)])
else:
X=self.domain()
for P in X.ambient_space():
try:
XP=X.point(P)
V.append(str(XP))
Q=self(XP)
E.append([str(Q)])
except TypeError: # not on the scheme
pass
from sage.graphs.digraph import DiGraph
g=DiGraph(dict(zip(V,E)), loops=True)
return g