21
21
22
22
from collections .abc import Collection
23
23
from sage .categories .fields import Fields
24
- from sage .categories .homset import Hom
25
24
from sage .categories .number_fields import NumberFields
26
25
from sage .categories .semigroups import Semigroups
27
26
from sage .dynamics .arithmetic_dynamics .affine_ds import DynamicalSystem_affine
30
29
from sage .misc .classcall_metaclass import typecall
31
30
from sage .misc .inherit_comparison import InheritComparisonClasscallMetaclass
32
31
from sage .rings .finite_rings .finite_field_base import FiniteField
33
- from sage .rings .integer import Integer
32
+ from sage .rings .integer_ring import ZZ
34
33
from sage .rings .rational_field import QQ
35
34
from sage .structure .parent import Parent
36
35
@@ -363,7 +362,10 @@ def __init__(self, systems):
363
362
(x^2 : y^2)
364
363
"""
365
364
366
- self ._dynamical_systems = _remove_duplicates_of_ (systems )
365
+ self ._dynamical_systems = []
366
+ for ds in systems :
367
+ if ds not in self ._dynamical_systems :
368
+ self ._dynamical_systems .append (ds )
367
369
Parent .__init__ (self , category = Semigroups ().FinitelyGeneratedAsMagma ())
368
370
369
371
def __call__ (self , input ):
@@ -582,7 +584,7 @@ def nth_iterate(self, p, n):
582
584
sage: f.nth_iterate(2, 3.5)
583
585
Traceback (most recent call last):
584
586
...
585
- TypeError: 3.50000000000000 must be an integer
587
+ TypeError: Attempt to coerce non-integral RealNumber to Integer
586
588
587
589
::
588
590
@@ -599,9 +601,17 @@ def nth_iterate(self, p, n):
599
601
sage: f = DynamicalSemigroup(([x + y, x - y], [x^2, y^2]))
600
602
sage: f.nth_iterate(3, 2) == (f * f)(3)
601
603
True
604
+
605
+ ::
606
+
607
+ sage: P.<x,y> = ProjectiveSpace(QQ, 1)
608
+ sage: f = DynamicalSemigroup(([x + y, x - y], [x^2, y^2]))
609
+ sage: one = QQ(1)
610
+ sage: f.nth_iterate(2, one)
611
+ {(3 : 1), (4 : 1)}
612
+
602
613
"""
603
- if not isinstance (n , Integer ) and not isinstance (n , int ):
604
- raise TypeError (str (n ) + " must be an integer" )
614
+ n = ZZ (n )
605
615
if n < 0 :
606
616
raise ValueError (str (n ) + " must be a nonnegative integer" )
607
617
result = {self .domain ()(p )}
@@ -900,6 +910,8 @@ def __mul__(self, other_dynamical_semigroup):
900
910
...
901
911
TypeError: can only multiply dynamical semigroups with other dynamical semigroups of the same type
902
912
913
+ ::
914
+
903
915
sage: P.<x,y> = ProjectiveSpace(QQ, 1)
904
916
sage: A.<z> = AffineSpace(QQ, 1)
905
917
sage: f1 = DynamicalSystem_projective([x, y], P)
@@ -1053,7 +1065,7 @@ def __pow__(self, n):
1053
1065
sage: d^1.5
1054
1066
Traceback (most recent call last):
1055
1067
...
1056
- TypeError: 1.50000000000000 must be an integer
1068
+ TypeError: Attempt to coerce non-integral RealNumber to Integer
1057
1069
1058
1070
::
1059
1071
@@ -1065,9 +1077,20 @@ def __pow__(self, n):
1065
1077
Traceback (most recent call last):
1066
1078
...
1067
1079
ValueError: -1 must be a nonnegative integer
1080
+
1081
+ ::
1082
+
1083
+ sage: A.<x> = AffineSpace(QQ, 1)
1084
+ sage: f = DynamicalSystem(x^2, A)
1085
+ sage: d = DynamicalSemigroup(f)
1086
+ sage: two = RR(2)
1087
+ sage: d^two
1088
+ Dynamical semigroup over Affine Space of dimension 1 over Rational Field defined by 1 dynamical system:
1089
+ Dynamical System of Affine Space of dimension 1 over Rational Field
1090
+ Defn: Defined on coordinates by sending (x) to
1091
+ (x^4)
1068
1092
"""
1069
- if not isinstance (n , Integer ) and not isinstance (n , int ):
1070
- raise TypeError (str (n ) + " must be an integer" )
1093
+ n = ZZ (n )
1071
1094
if n < 0 :
1072
1095
raise ValueError (str (n ) + " must be a nonnegative integer" )
1073
1096
if n == 0 :
@@ -1162,12 +1185,12 @@ def __eq__(self, other):
1162
1185
sage: f == g
1163
1186
Traceback (most recent call last):
1164
1187
...
1165
- ValueError : cannot compare dynamical semigroups with at least one generator of degree 1
1188
+ NotImplementedError : cannot compare dynamical semigroups with at least one generator of degree 1
1166
1189
"""
1167
1190
if isinstance (other , DynamicalSemigroup ):
1168
1191
if any (ds .degree () == 1 for ds in self .defining_systems ()) or \
1169
1192
any (ds .degree () == 1 for ds in other .defining_systems ()):
1170
- raise ValueError ("cannot compare dynamical semigroups with at least one generator of degree 1" )
1193
+ raise NotImplementedError ("cannot compare dynamical semigroups with at least one generator of degree 1" )
1171
1194
return all (ds in other .defining_systems () for ds in self .defining_systems ()) and \
1172
1195
all (ds in self .defining_systems () for ds in other .defining_systems ())
1173
1196
return False
@@ -1255,6 +1278,21 @@ def dehomogenize(self, n):
1255
1278
Defn: Defined on coordinates by sending (y) to
1256
1279
(y^2)
1257
1280
1281
+ ::
1282
+
1283
+ sage: P.<x,y> = ProjectiveSpace(QQ, 1)
1284
+ sage: f = DynamicalSystem([x, y], P)
1285
+ sage: g = DynamicalSystem([x^2, y^2], P)
1286
+ sage: d = DynamicalSemigroup((f, g))
1287
+ sage: d.dehomogenize(1)
1288
+ Dynamical semigroup over Affine Space of dimension 1 over Rational Field defined by 2 dynamical systems:
1289
+ Dynamical System of Affine Space of dimension 1 over Rational Field
1290
+ Defn: Defined on coordinates by sending (x) to
1291
+ (x)
1292
+ Dynamical System of Affine Space of dimension 1 over Rational Field
1293
+ Defn: Defined on coordinates by sending (x) to
1294
+ (x^2)
1295
+
1258
1296
TESTS::
1259
1297
1260
1298
sage: P.<x,y> = ProjectiveSpace(QQ, 1)
@@ -1264,15 +1302,17 @@ def dehomogenize(self, n):
1264
1302
sage: d.dehomogenize((1, 0))
1265
1303
Traceback (most recent call last):
1266
1304
...
1267
- ValueError: Dynamical System of Projective Space of dimension 1 over Rational Field
1268
- Defn: Defined on coordinates by sending (x : y) to
1269
- (x : y) dehomogenized at (1, 0) is not a `DynamicalSystem_affine` object
1305
+ ValueError: Scheme morphism:
1306
+ From: Affine Space of dimension 1 over Rational Field
1307
+ To: Affine Space of dimension 1 over Rational Field
1308
+ Defn: Defined on coordinates by sending (x) to
1309
+ (1/x) is not a `DynamicalSystem_affine` object
1270
1310
"""
1271
1311
new_systems = []
1272
1312
for ds in self .defining_systems ():
1273
1313
new_system = ds .dehomogenize (n )
1274
1314
if not isinstance (new_system , DynamicalSystem_affine ):
1275
- raise ValueError (str (ds ) + " dehomogenized at " + str ( n ) + " is not a `DynamicalSystem_affine` object" )
1315
+ raise ValueError (str (new_system ) + " is not a `DynamicalSystem_affine` object" )
1276
1316
new_systems .append (new_system )
1277
1317
return DynamicalSemigroup_affine (new_systems )
1278
1318
@@ -1381,10 +1421,7 @@ def homogenize(self, n):
1381
1421
"""
1382
1422
new_systems = []
1383
1423
for ds in self .defining_systems ():
1384
- new_system = ds .homogenize (n )
1385
- if not isinstance (new_system , DynamicalSystem_projective ):
1386
- raise ValueError (str (ds ) + " homogenized at " + str (n ) + " is not a `DynamicalSystem_projective` object" )
1387
- new_systems .append (new_system )
1424
+ new_systems .append (ds .homogenize (n ))
1388
1425
return DynamicalSemigroup_projective (new_systems )
1389
1426
1390
1427
class DynamicalSemigroup_affine_field (DynamicalSemigroup_affine ):
@@ -1393,30 +1430,6 @@ class DynamicalSemigroup_affine_field(DynamicalSemigroup_affine):
1393
1430
class DynamicalSemigroup_affine_finite_field (DynamicalSemigroup_affine_field ):
1394
1431
pass
1395
1432
1396
- def _remove_duplicates_of_ (list ):
1397
- r"""
1398
- Removes duplicate elements from a list.
1399
-
1400
- INPUT:
1401
-
1402
- - ``list`` -- any list
1403
-
1404
- OUTPUT: the original list without duplicate elements
1405
-
1406
- EXAMPLES::
1407
-
1408
- sage: numbers = [1, 1, 2, 3, 3, 2, 1, 5, 4, 3]
1409
- sage: sage.dynamics.arithmetic_dynamics.dynamical_semigroup._remove_duplicates_of_(numbers)
1410
- [1, 2, 3, 5, 4]
1411
- """
1412
- seen = []
1413
-
1414
- for item in list :
1415
- if item not in seen :
1416
- seen .append (item )
1417
-
1418
- return seen
1419
-
1420
1433
def _standardize_domains_of_ (systems ):
1421
1434
r"""
1422
1435
Coerces dynamical systems to the same domain and have the same generators.
0 commit comments