Skip to content

Commit 9800231

Browse files
stored dynamical systems as pseudo-set, a list with no duplicates
1 parent dee6dea commit 9800231

File tree

1 file changed

+35
-11
lines changed

1 file changed

+35
-11
lines changed

src/sage/dynamics/arithmetic_dynamics/dynamical_semigroup.py

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ def __init__(self, systems):
301301
(x^2 : y^2)
302302
"""
303303

304-
self._dynamical_systems = systems
304+
self._dynamical_systems = _remove_duplicates_of_(systems)
305305
Parent.__init__(self, category=Semigroups().FinitelyGeneratedAsMagma())
306306

307307
def __call__(self, input):
@@ -313,35 +313,35 @@ def __call__(self, input):
313313
- ``input`` -- one value that can be evaluated
314314
with the generators of this dynamical semigroup.
315315
316-
OUTPUT: A tuple of the resulting values after applying all of this dynamical semigroup's generators to ``input``.
316+
OUTPUT: A set of the resulting values after applying all of this dynamical semigroup's generators to ``input``.
317317
318318
EXAMPLES::
319319
320320
sage: P.<x,y> = ProjectiveSpace(QQ, 1)
321321
sage: f = DynamicalSemigroup(([x, y], [x^2, y^2]))
322322
sage: f(2)
323-
((2 : 1), (4 : 1))
323+
{(2 : 1), (4 : 1)}
324324
325325
::
326326
327327
sage: P.<x,y> = ProjectiveSpace(QQ, 1)
328328
sage: f = DynamicalSemigroup(([x, y], [x^2, y^2]))
329329
sage: f([2, 1])
330-
((2 : 1), (4 : 1))
330+
{(2 : 1), (4 : 1)}
331331
332-
::
332+
TESTS::
333333
334334
sage: P.<x,y> = ProjectiveSpace(QQ, 1)
335335
sage: f = DynamicalSemigroup(([x, y], [x^2, y^2]))
336336
sage: f(f(2))
337337
Traceback (most recent call last):
338338
...
339-
TypeError: unable to convert (2 : 1) to an element of Rational Field
339+
TypeError: unable to convert {(4 : 1), (2 : 1)} to an element of Rational Field
340340
"""
341341
result = []
342342
for ds in self.defining_systems():
343343
result.append(ds(self.domain()(input)))
344-
return tuple(result)
344+
return set(result)
345345

346346
def base_ring(self):
347347
r"""
@@ -423,21 +423,21 @@ def codomain(self):
423423

424424
def defining_polynomials(self):
425425
r"""
426-
Return the tuple of polynomials that define the generators of this dynamical semigroup.
426+
Return the set of polynomials that define the generators of this dynamical semigroup.
427427
428-
OUTPUT: A tuple of polynomials.
428+
OUTPUT: A set of polynomials.
429429
430430
EXAMPLES::
431431
432432
sage: P.<x,y> = ProjectiveSpace(QQ, 1)
433433
sage: f = DynamicalSemigroup(([x, y], [x^2, y^2]))
434434
sage: f.defining_polynomials()
435-
((x, y), (x^2, y^2))
435+
{(x, y), (x^2, y^2)}
436436
"""
437437
result = []
438438
for ds in self.defining_systems():
439439
result.append(ds.defining_polynomials())
440-
return tuple(result)
440+
return set(result)
441441

442442
def defining_systems(self):
443443
r"""
@@ -677,6 +677,30 @@ class DynamicalSemigroup_affine_field(DynamicalSemigroup_affine):
677677
class DynamicalSemigroup_affine_finite_field(DynamicalSemigroup_affine_field):
678678
pass
679679

680+
def _remove_duplicates_of_(list):
681+
r"""
682+
Removes duplicate elements from a list.
683+
684+
INPUT:
685+
686+
- ``list`` -- any list
687+
688+
OUTPUT: the original list without duplicate elements
689+
690+
EXAMPLES::
691+
692+
sage: numbers = [1, 1, 2, 3, 3, 2, 1, 5, 4, 3]
693+
sage: sage.dynamics.arithmetic_dynamics.dynamical_semigroup._remove_duplicates_of_(numbers)
694+
[1, 2, 3, 5, 4]
695+
"""
696+
seen = []
697+
698+
for item in list:
699+
if item not in seen:
700+
seen.append(item)
701+
702+
return seen
703+
680704
def _standardize_domains_of_(systems):
681705
r"""
682706
Coerces dynamical systems to the same domain and have the same generators.

0 commit comments

Comments
 (0)