Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
First attempt at using UniqueRepresentation, mutate_initial should no…
Browse files Browse the repository at this point in the history
…w be broken
  • Loading branch information
Salvatore Stella committed Feb 14, 2017
1 parent 40deffe commit 6c2d7a2
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions src/sage/algebras/cluster_algebra.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,7 @@
from sage.structure.parent import Parent
from sage.structure.sage_object import SageObject
from six.moves import range as range
from sage.structure.unique_representation import UniqueRepresentation

##############################################################################
# Helper functions
Expand Down Expand Up @@ -1175,7 +1176,7 @@ def _mutated_F(self, k, old_g_vector):
# Cluster algebras
##############################################################################

class ClusterAlgebra(Parent):
class ClusterAlgebra(Parent, UniqueRepresentation):
r"""
A Cluster Algebra.
Expand Down Expand Up @@ -1234,7 +1235,16 @@ class ClusterAlgebra(Parent):
...
ValueError: coefficient_names should be a list of 3 valid variable names
"""
def __init__(self, data, **kwargs):

@staticmethod
def __classcall__(self, data, **kwargs):
Q = ClusterQuiver(data)
for key in kwargs:
if isinstance(kwargs[key],list):
kwargs[key] = tuple(kwargs[key])
return super(ClusterAlgebra, self).__classcall__(self, Q, **kwargs)

def __init__(self, Q, **kwargs):
"""
Initialize ``self``.
Expand All @@ -1245,7 +1255,7 @@ def __init__(self, data, **kwargs):
sage: TestSuite(A).run()
sage: A = ClusterAlgebra(['A', 2])
sage: TestSuite(A).run()
sage: A = ClusterAlgebra(['A', 2], principal_coefficients=True)
sage: A = ClusterAlgebra(['A', 3], principal_coefficients=True)
sage: TestSuite(A).run()
sage: A = ClusterAlgebra(['A', 2], principal_coefficients=True, coefficient_prefix='x')
sage: TestSuite(A).run()
Expand All @@ -1255,7 +1265,6 @@ def __init__(self, data, **kwargs):
sage: TestSuite(A).run()
"""
# Temporary variables
Q = ClusterQuiver(data)
n = Q.n()
I = identity_matrix(n)
if kwargs.get('principal_coefficients', False):
Expand Down Expand Up @@ -1433,7 +1442,7 @@ def _an_element_(self):
sage: A.an_element()
x0
"""
return self.current_seed().cluster_variable(0)
return self.initial_cluster_variable(0)

def _coerce_map_from_(self, other):
r"""
Expand Down Expand Up @@ -1575,6 +1584,7 @@ def reset_current_seed(self):
EXAMPLES::
sage: A = ClusterAlgebra(['A', 2])
sage: A.reset_current_seed()
sage: A.current_seed().mutate([1, 0])
sage: A.current_seed() == A.initial_seed()
False
Expand Down Expand Up @@ -1784,7 +1794,7 @@ def F_polynomial(self, g_vector):
EXAMPLES::
sage: A = ClusterAlgebra(['A', 2])
sage: A = ClusterAlgebra(['C', 2])
sage: A.F_polynomial((-1, 1))
Traceback (most recent call last):
...
Expand Down Expand Up @@ -2144,11 +2154,11 @@ def reset_exploring_iterator(self, mutating_F=True):
EXAMPLES::
sage: A = ClusterAlgebra(['A', 4])
sage: A = ClusterAlgebra(['C', 4])
sage: A.reset_exploring_iterator(mutating_F=False)
sage: A.explore_to_depth(infinity)
sage: len(A.g_vectors_so_far())
14
20
sage: len(A.F_polynomials_so_far())
4
"""
Expand Down Expand Up @@ -2252,7 +2262,7 @@ def mutate_initial(self, k):
cv_names = self.initial_cluster_variable_names()
coeff_names = self.coefficient_names()
scalars = self.scalars()
self.__init__(B0, cluster_variable_names=cv_names,
self.__init__(ClusterQuiver(B0), cluster_variable_names=cv_names,
coefficient_names=coeff_names, scalars=scalars)

# substitution data to compute new F-polynomials
Expand Down

0 comments on commit 6c2d7a2

Please sign in to comment.