Skip to content

Commit c51f504

Browse files
Merge branch 'dsg_ticket2' into dsg_ticket3
2 parents 707bc44 + 5f66f5e commit c51f504

File tree

1 file changed

+56
-43
lines changed

1 file changed

+56
-43
lines changed

src/sage/dynamics/arithmetic_dynamics/dynamical_semigroup.py

Lines changed: 56 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121

2222
from collections.abc import Collection
2323
from sage.categories.fields import Fields
24-
from sage.categories.homset import Hom
2524
from sage.categories.number_fields import NumberFields
2625
from sage.categories.semigroups import Semigroups
2726
from sage.dynamics.arithmetic_dynamics.affine_ds import DynamicalSystem_affine
@@ -30,7 +29,7 @@
3029
from sage.misc.classcall_metaclass import typecall
3130
from sage.misc.inherit_comparison import InheritComparisonClasscallMetaclass
3231
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
3433
from sage.rings.rational_field import QQ
3534
from sage.structure.parent import Parent
3635

@@ -363,7 +362,10 @@ def __init__(self, systems):
363362
(x^2 : y^2)
364363
"""
365364

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)
367369
Parent.__init__(self, category=Semigroups().FinitelyGeneratedAsMagma())
368370

369371
def __call__(self, input):
@@ -582,7 +584,7 @@ def nth_iterate(self, p, n):
582584
sage: f.nth_iterate(2, 3.5)
583585
Traceback (most recent call last):
584586
...
585-
TypeError: 3.50000000000000 must be an integer
587+
TypeError: Attempt to coerce non-integral RealNumber to Integer
586588
587589
::
588590
@@ -599,9 +601,17 @@ def nth_iterate(self, p, n):
599601
sage: f = DynamicalSemigroup(([x + y, x - y], [x^2, y^2]))
600602
sage: f.nth_iterate(3, 2) == (f * f)(3)
601603
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+
602613
"""
603-
if not isinstance(n, Integer) and not isinstance(n, int):
604-
raise TypeError(str(n) + " must be an integer")
614+
n = ZZ(n)
605615
if n < 0:
606616
raise ValueError(str(n) + " must be a nonnegative integer")
607617
result = {self.domain()(p)}
@@ -900,6 +910,8 @@ def __mul__(self, other_dynamical_semigroup):
900910
...
901911
TypeError: can only multiply dynamical semigroups with other dynamical semigroups of the same type
902912
913+
::
914+
903915
sage: P.<x,y> = ProjectiveSpace(QQ, 1)
904916
sage: A.<z> = AffineSpace(QQ, 1)
905917
sage: f1 = DynamicalSystem_projective([x, y], P)
@@ -1053,7 +1065,7 @@ def __pow__(self, n):
10531065
sage: d^1.5
10541066
Traceback (most recent call last):
10551067
...
1056-
TypeError: 1.50000000000000 must be an integer
1068+
TypeError: Attempt to coerce non-integral RealNumber to Integer
10571069
10581070
::
10591071
@@ -1065,9 +1077,20 @@ def __pow__(self, n):
10651077
Traceback (most recent call last):
10661078
...
10671079
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)
10681092
"""
1069-
if not isinstance(n, Integer) and not isinstance(n, int):
1070-
raise TypeError(str(n) + " must be an integer")
1093+
n = ZZ(n)
10711094
if n < 0:
10721095
raise ValueError(str(n) + " must be a nonnegative integer")
10731096
if n == 0:
@@ -1162,12 +1185,12 @@ def __eq__(self, other):
11621185
sage: f == g
11631186
Traceback (most recent call last):
11641187
...
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
11661189
"""
11671190
if isinstance(other, DynamicalSemigroup):
11681191
if any(ds.degree() == 1 for ds in self.defining_systems()) or \
11691192
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")
11711194
return all(ds in other.defining_systems() for ds in self.defining_systems()) and \
11721195
all(ds in self.defining_systems() for ds in other.defining_systems())
11731196
return False
@@ -1255,6 +1278,21 @@ def dehomogenize(self, n):
12551278
Defn: Defined on coordinates by sending (y) to
12561279
(y^2)
12571280
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+
12581296
TESTS::
12591297
12601298
sage: P.<x,y> = ProjectiveSpace(QQ, 1)
@@ -1264,15 +1302,17 @@ def dehomogenize(self, n):
12641302
sage: d.dehomogenize((1, 0))
12651303
Traceback (most recent call last):
12661304
...
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
12701310
"""
12711311
new_systems = []
12721312
for ds in self.defining_systems():
12731313
new_system = ds.dehomogenize(n)
12741314
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")
12761316
new_systems.append(new_system)
12771317
return DynamicalSemigroup_affine(new_systems)
12781318

@@ -1381,10 +1421,7 @@ def homogenize(self, n):
13811421
"""
13821422
new_systems = []
13831423
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))
13881425
return DynamicalSemigroup_projective(new_systems)
13891426

13901427
class DynamicalSemigroup_affine_field(DynamicalSemigroup_affine):
@@ -1393,30 +1430,6 @@ class DynamicalSemigroup_affine_field(DynamicalSemigroup_affine):
13931430
class DynamicalSemigroup_affine_finite_field(DynamicalSemigroup_affine_field):
13941431
pass
13951432

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-
14201433
def _standardize_domains_of_(systems):
14211434
r"""
14221435
Coerces dynamical systems to the same domain and have the same generators.

0 commit comments

Comments
 (0)