Cluster algebras¶
This file constructs cluster algebras using the Parent-Element framework. The implementation mainly utilizes structural theorems from [FZ2007].
The key points being used here are these:
- cluster variables are parametrized by their g-vectors;
- g-vectors (together with c-vectors) provide a self-standing model for the combinatorics behind any cluster algebra;
- each cluster variable in any cluster algebra can be computed, by the separation of additions formula, from its g-vector and F-polynomial.
Accordingly this file provides three classes:
ClusterAlgebra
, constructed as a subobject of
sage.rings.polynomial.laurent_polynomial_ring.LaurentPolynomialRing_generic
,
is the frontend of this implementation. It provides all the algebraic
features (like ring morphisms), it computes cluster variables, it is
responsible for controlling the exploration of the exchange graph and
serves as the repository for all the data recursively computed so far.
In particular, all g-vectors and all F-polynomials of known cluster
variables as well as a mutation path by which they can be obtained
are recorded. In the optic of efficiency, this implementation does not
store directly the exchange graph nor the exchange relations. Both of
these could be added to ClusterAlgebra
with minimal effort.
ClusterAlgebraSeed
provides the combinatorial backbone
for ClusterAlgebra
. It is an auxiliary class and therefore its
instances should not be directly created by the user. Rather it
should be accessed via ClusterAlgebra.current_seed()
and ClusterAlgebra.initial_seed()
. The task of performing current
seed mutations is delegated to this class. Seeds are considered equal if
they have the same parent cluster algebra and they can be obtained from
each other by a permutation of their data (i.e. if they coincide as
unlabelled seeds). Cluster algebras whose initial seeds are equal in the
above sense are not considered equal but are endowed with coercion maps
to each other. More generally, a cluster algebra is endowed with coercion
maps from any cluster algebra which is obtained by freezing a collection
of initial cluster variables and/or permuting both cluster variables
and coefficients.
ClusterAlgebraElement
is a thin wrapper around
sage.rings.polynomial.laurent_polynomial.LaurentPolynomial
providing all the functions specific to cluster variables.
Elements of a cluster algebra with principal coefficients have special methods
and these are grouped in the subclass PrincipalClusterAlgebraElement
.
One more remark about this implementation. Instances of
ClusterAlgebra
are built by identifying the initial cluster variables
with the generators of ClusterAlgebra.ambient()
. In particular, this
forces a specific embedding into the ambient field of rational expressions. In
view of this, although cluster algebras themselves are independent of the
choice of initial seed, ClusterAlgebra.mutate_initial()
is forced to
return a different instance of ClusterAlgebra
. At the moment there
is no coercion implemented among the two instances but this could in
principle be added to ClusterAlgebra.mutate_initial()
.
REFERENCES:
AUTHORS:
- Dylan Rupel (2015-06-15): initial version
- Salvatore Stella (2015-06-15): initial version
EXAMPLES:
We begin by creating a simple cluster algebra and printing its initial exchange matrix:
sage: A = ClusterAlgebra(['A', 2]); A
A Cluster Algebra with cluster variables x0, x1 and no coefficients over Integer Ring
sage: A.b_matrix()
[ 0 1]
[-1 0]
A
is of finite type so we can explore all its exchange graph:
sage: A.explore_to_depth(infinity)
and get all its g-vectors, F-polynomials, and cluster variables:
sage: sorted(A.g_vectors_so_far())
[(-1, 0), (-1, 1), (0, -1), (0, 1), (1, 0)]
sage: sorted(A.F_polynomials_so_far(), key=str)
[1, 1, u0 + 1, u0*u1 + u0 + 1, u1 + 1]
sage: sorted(A.cluster_variables_so_far(), key=str)
[(x0 + 1)/x1, (x0 + x1 + 1)/(x0*x1), (x1 + 1)/x0, x0, x1]
Simple operations among cluster variables behave as expected:
sage: s = A.cluster_variable((0, -1)); s
(x0 + 1)/x1
sage: t = A.cluster_variable((-1, 1)); t
(x1 + 1)/x0
sage: t + s
(x0^2 + x1^2 + x0 + x1)/(x0*x1)
sage: _.parent() == A
True
sage: t - s
(-x0^2 + x1^2 - x0 + x1)/(x0*x1)
sage: _.parent() == A
True
sage: t*s
(x0*x1 + x0 + x1 + 1)/(x0*x1)
sage: _.parent() == A
True
sage: t/s
(x1^2 + x1)/(x0^2 + x0)
sage: _.parent() == A
False
Division is not guaranteed to yield an element of A
so it returns an
element of A.ambient().fraction_field()
instead:
sage: (t/s).parent() == A.ambient().fraction_field()
True
We can compute denominator vectors of any element of A
:
sage: (t*s).d_vector()
(1, 1)
Since we are in rank 2 and we do not have coefficients we can compute the greedy element associated to any denominator vector:
sage: A.rank() == 2 and A.coefficients() == ()
True
sage: A.greedy_element((1, 1))
(x0 + x1 + 1)/(x0*x1)
sage: _ == t*s
False
not surprising since there is no cluster in A
containing
both t
and s
:
sage: seeds = A.seeds(mutating_F=false)
sage: [ S for S in seeds if (0, -1) in S and (-1, 1) in S ]
[]
indeed:
sage: A.greedy_element((1, 1)) == A.cluster_variable((-1, 0))
True
Disabling F-polynomials in the computation just done was redundant because we already explored the whole exchange graph before. Though in different circumstances it could have saved us considerable time.
g-vectors and F-polynomials can be computed from elements of A
only if
A
has principal coefficients at the initial seed:
sage: (t*s).g_vector()
Traceback (most recent call last):
...
AttributeError: 'ClusterAlgebra_with_category.element_class' object has no attribute 'g_vector'
sage: A = ClusterAlgebra(['A', 2], principal_coefficients=True)
sage: A.explore_to_depth(infinity)
sage: s = A.cluster_variable((0, -1)); s
(x0*y1 + 1)/x1
sage: t = A.cluster_variable((-1, 1)); t
(x1 + y0)/x0
sage: (t*s).g_vector()
(-1, 0)
sage: (t*s).F_polynomial()
u0*u1 + u0 + u1 + 1
sage: (t*s).is_homogeneous()
True
sage: (t+s).is_homogeneous()
False
sage: (t+s).homogeneous_components()
{(-1, 1): (x1 + y0)/x0, (0, -1): (x0*y1 + 1)/x1}
Each cluster algebra is endowed with a reference to a current seed; it could be useful to assign a name to it:
sage: A = ClusterAlgebra(['F', 4])
sage: len(A.g_vectors_so_far())
4
sage: A.current_seed()
The initial seed of a Cluster Algebra with cluster variables x0, x1, x2, x3
and no coefficients over Integer Ring
sage: A.current_seed() == A.initial_seed()
True
sage: S = A.current_seed()
sage: S.b_matrix()
[ 0 1 0 0]
[-1 0 -1 0]
[ 0 2 0 1]
[ 0 0 -1 0]
sage: S.g_matrix()
[1 0 0 0]
[0 1 0 0]
[0 0 1 0]
[0 0 0 1]
sage: S.cluster_variables()
[x0, x1, x2, x3]
and use S
to walk around the exchange graph of A
:
sage: S.mutate(0); S
The seed of a Cluster Algebra with cluster variables x0, x1, x2, x3
and no coefficients over Integer Ring obtained from the initial
by mutating in direction 0
sage: S.b_matrix()
[ 0 -1 0 0]
[ 1 0 -1 0]
[ 0 2 0 1]
[ 0 0 -1 0]
sage: S.g_matrix()
[-1 0 0 0]
[ 1 1 0 0]
[ 0 0 1 0]
[ 0 0 0 1]
sage: S.cluster_variables()
[(x1 + 1)/x0, x1, x2, x3]
sage: S.mutate('sinks'); S
The seed of a Cluster Algebra with cluster variables x0, x1, x2, x3
and no coefficients over Integer Ring obtained from the initial
by mutating along the sequence [0, 2]
sage: S.mutate([2, 3, 2, 1, 0]); S
The seed of a Cluster Algebra with cluster variables x0, x1, x2, x3
and no coefficients over Integer Ring obtained from the initial
by mutating along the sequence [0, 3, 2, 1, 0]
sage: S.g_vectors()
[(0, 1, -2, 0), (-1, 2, -2, 0), (0, 1, -1, 0), (0, 0, 0, -1)]
sage: S.cluster_variable(3)
(x2 + 1)/x3
Walking around by mutating S
updates the informations stored in A
:
sage: len(A.g_vectors_so_far())
10
sage: A.current_seed().path_from_initial_seed()
[0, 3, 2, 1, 0]
sage: A.current_seed() == S
True
Starting from A.initial_seed()
still records data in A
but does not
update A.current_seed()
:
sage: S1 = A.initial_seed()
sage: S1.mutate([2, 1, 3])
sage: len(A.g_vectors_so_far())
11
sage: S1 == A.current_seed()
False
Since ClusterAlgebra
inherits from UniqueRepresentation
,
computed data is shared across instances:
sage: A1 = ClusterAlgebra(['F', 4])
sage: A1 is A
True
sage: len(A1.g_vectors_so_far())
11
It can be useful, at times to forget all computed data. Because of
UniqueRepresentation
this cannot be achieved by simply creating a
new instance; instead it has to be manually triggered by:
sage: A.clear_computed_data()
sage: len(A.g_vectors_so_far())
4
Given a cluster algebra A
we may be looking for a specific cluster
variable:
sage: A = ClusterAlgebra(['E', 8, 1])
sage: v = (-1, 1, -1, 1, -1, 1, 0, 0, 1)
sage: A.find_g_vector(v, depth=2)
sage: seq = A.find_g_vector(v); seq # random
[0, 1, 2, 4, 3]
sage: v in A.initial_seed().mutate(seq, inplace=False).g_vectors()
True
This also performs mutations of F-polynomials:
sage: A.F_polynomial((-1, 1, -1, 1, -1, 1, 0, 0, 1))
u0*u1*u2*u3*u4 + u0*u1*u2*u4 + u0*u2*u3*u4 + u0*u1*u2 + u0*u2*u4
+ u2*u3*u4 + u0*u2 + u0*u4 + u2*u4 + u0 + u2 + u4 + 1
which might not be a good idea in algebras that are too big. One workaround is to first disable F-polynomials and then recompute only the desired mutations:
sage: A.reset_exploring_iterator(mutating_F=False) # long time
sage: v = (-1, 1, -2, 2, -1, 1, -1, 1, 1) # long time
sage: seq = A.find_g_vector(v); seq # long time random
[1, 0, 2, 6, 5, 4, 3, 8, 1]
sage: S = A.initial_seed().mutate(seq, inplace=False) # long time
sage: v in S.g_vectors() # long time
True
sage: A.current_seed().mutate(seq) # long time
sage: A.F_polynomial((-1, 1, -2, 2, -1, 1, -1, 1, 1)) # long time
u0*u1^2*u2^2*u3*u4*u5*u6*u8 +
...
2*u2 + u4 + u6 + 1
We can manually freeze cluster variables and get coercions in between the two algebras:
sage: A = ClusterAlgebra(['F', 4]); A
A Cluster Algebra with cluster variables x0, x1, x2, x3 and no coefficients
over Integer Ring
sage: A1 = ClusterAlgebra(A.b_matrix().matrix_from_columns([0, 1, 2]), coefficient_prefix='x'); A1
A Cluster Algebra with cluster variables x0, x1, x2 and coefficient x3
over Integer Ring
sage: A.has_coerce_map_from(A1)
True
and we also have an immersion of A.base()
into A
and of A
into A.ambient()
:
sage: A.has_coerce_map_from(A.base())
True
sage: A.ambient().has_coerce_map_from(A)
True
but there is currently no coercion in between algebras obtained by mutating at the initial seed:
sage: A1 = A.mutate_initial(0); A1
A Cluster Algebra with cluster variables x0, x1, x2, x3 and no coefficients
over Integer Ring
sage: A.b_matrix() == A1.b_matrix()
False
sage: [X.has_coerce_map_from(Y) for X, Y in [(A, A1), (A1, A)]]
[False, False]
-
sage.algebras.cluster_algebra.
ClusterAlgebra
¶ A Cluster Algebra.
INPUT:
data
– some data defining a cluster algebra; it can be anything that can be parsed byClusterQuiver
scalars
– a ring (default \(\ZZ\)); the scalars over which the cluster algebra is definedcluster_variable_prefix
– string (default'x'
); it needs to be a valid variable namecluster_variable_names
– a list of strings; each element needs to be a valid variable name; supersedescluster_variable_prefix
coefficient_prefix
– string (default'y'
); it needs to be a valid variable name.coefficient_names
– a list of strings; each element needs to be a valid variable name; supersedescluster_variable_prefix
principal_coefficients
– bool (defaultFalse
); supersedes any coefficient defined bydata
ALGORITHM:
The implementation is mainly based on [FZ2007] and [NZ2012].
EXAMPLES:
sage: B = matrix([(0, 1, 0, 0), (-1, 0, -1, 0), (0, 1, 0, 1), (0, 0, -2, 0), (-1, 0, 0, 0), (0, -1, 0, 0)]) sage: A = ClusterAlgebra(B); A A Cluster Algebra with cluster variables x0, x1, x2, x3 and coefficients y0, y1 over Integer Ring sage: A.gens() (x0, x1, x2, x3, y0, y1) sage: A = ClusterAlgebra(['A', 2]); A A Cluster Algebra with cluster variables x0, x1 and no coefficients over Integer Ring sage: A = ClusterAlgebra(['A', 2], principal_coefficients=True); A.gens() (x0, x1, y0, y1) sage: A = ClusterAlgebra(['A', 2], principal_coefficients=True, coefficient_prefix='x'); A.gens() (x0, x1, x2, x3) sage: A = ClusterAlgebra(['A', 3], principal_coefficients=True, cluster_variable_names=['a', 'b', 'c']); A.gens() (a, b, c, y0, y1, y2) sage: A = ClusterAlgebra(['A', 3], principal_coefficients=True, cluster_variable_names=['a', 'b']) Traceback (most recent call last): ... ValueError: cluster_variable_names should be a list of 3 valid variable names sage: A = ClusterAlgebra(['A', 3], principal_coefficients=True, coefficient_names=['a', 'b', 'c']); A.gens() (x0, x1, x2, a, b, c) sage: A = ClusterAlgebra(['A', 3], principal_coefficients=True, coefficient_names=['a', 'b']) Traceback (most recent call last): ... ValueError: coefficient_names should be a list of 3 valid variable names
-
class
sage.algebras.cluster_algebra.
ClusterAlgebraElement
¶ Bases:
sage.structure.element_wrapper.ElementWrapper
An element of a cluster algebra.
-
d_vector
()¶ Return the denominator vector of
self
as a tuple of integers.EXAMPLES:
sage: A = ClusterAlgebra(['F', 4], principal_coefficients=True) sage: A.current_seed().mutate([0, 2, 1]) sage: x = A.cluster_variable((-1, 2, -2, 2)) * A.cluster_variable((0, 0, 0, 1))**2 sage: x.d_vector() (1, 1, 2, -2)
-
-
class
sage.algebras.cluster_algebra.
ClusterAlgebraSeed
(B, C, G, parent, **kwargs)¶ Bases:
sage.structure.sage_object.SageObject
A seed in a Cluster Algebra.
INPUT:
B
– a skew-symmetrizable integer matrixC
– the matrix of c-vectors ofself
G
– the matrix of g-vectors ofself
parent
–ClusterAlgebra
; the algebra to which the seed belongspath
– list (default[]
); the mutation sequence from the initial seed ofparent
toself
Warning
Seeds should not be created manually: no test is performed to assert that they are built from consistent data nor that they really are seeds of
parent
. If you create seeds with inconsistent data all sort of things can go wrong, even__eq__()
is no longer guaranteed to give correct answers. Use at your own risk.-
F_polynomial
(j)¶ Return the
j
-th F-polynomial ofself
.INPUT:
j
– an integer inrange(self.parent().rank())
; the index of the F-polynomial to return
EXAMPLES:
sage: A = ClusterAlgebra(['A', 3]) sage: S = A.initial_seed() sage: S.F_polynomial(0) 1
-
F_polynomials
()¶ Return all the F-polynomials of
self
.EXAMPLES:
sage: A = ClusterAlgebra(['A', 3]) sage: S = A.initial_seed() sage: S.F_polynomials() [1, 1, 1]
-
b_matrix
()¶ Return the exchange matrix of
self
.EXAMPLES:
sage: A = ClusterAlgebra(['A', 3]) sage: S = A.initial_seed() sage: S.b_matrix() [ 0 1 0] [-1 0 -1] [ 0 1 0]
-
c_matrix
()¶ Return the matrix whose columns are the c-vectors of
self
.EXAMPLES:
sage: A = ClusterAlgebra(['A', 3]) sage: S = A.initial_seed() sage: S.c_matrix() [1 0 0] [0 1 0] [0 0 1]
-
c_vector
(j)¶ Return the
j
-th c-vector ofself
.INPUT:
j
– an integer inrange(self.parent().rank())
; the index of the c-vector to return
EXAMPLES:
sage: A = ClusterAlgebra(['A', 3]) sage: S = A.initial_seed() sage: S.c_vector(0) (1, 0, 0) sage: S.mutate(0) sage: S.c_vector(0) (-1, 0, 0) sage: S.c_vector(1) (1, 1, 0)
-
c_vectors
()¶ Return all the c-vectors of
self
.EXAMPLES:
sage: A = ClusterAlgebra(['A', 3]) sage: S = A.initial_seed() sage: S.c_vectors() [(1, 0, 0), (0, 1, 0), (0, 0, 1)]
-
cluster_variable
(j)¶ Return the
j
-th cluster variable ofself
.INPUT:
j
– an integer inrange(self.parent().rank())
; the index of the cluster variable to return
EXAMPLES:
sage: A = ClusterAlgebra(['A', 3]) sage: S = A.initial_seed() sage: S.cluster_variable(0) x0 sage: S.mutate(0) sage: S.cluster_variable(0) (x1 + 1)/x0
-
cluster_variables
()¶ Return all the cluster variables of
self
.EXAMPLES:
sage: A = ClusterAlgebra(['A', 3]) sage: S = A.initial_seed() sage: S.cluster_variables() [x0, x1, x2]
-
depth
()¶ - Return the length of a mutation sequence from the initial seed
- of
parent()
toself
.
Warning
This is the length of the mutation sequence returned by
path_from_initial_seed()
, which need not be the shortest possible.EXAMPLES:
sage: A = ClusterAlgebra(['A', 2]) sage: S1 = A.initial_seed() sage: S1.mutate([0, 1, 0, 1]) sage: S1.depth() 4 sage: S2 = A.initial_seed() sage: S2.mutate(1) sage: S2.depth() 1 sage: S1 == S2 True
-
g_matrix
()¶ Return the matrix whose columns are the g-vectors of
self
.EXAMPLES:
sage: A = ClusterAlgebra(['A', 3]) sage: S = A.initial_seed() sage: S.g_matrix() [1 0 0] [0 1 0] [0 0 1]
-
g_vector
(j)¶ Return the
j
-th g-vector ofself
.INPUT:
j
– an integer inrange(self.parent().rank())
; the index of the g-vector to return
EXAMPLES:
sage: A = ClusterAlgebra(['A', 3]) sage: S = A.initial_seed() sage: S.g_vector(0) (1, 0, 0)
-
g_vectors
()¶ Return all the g-vectors of
self
.EXAMPLES:
sage: A = ClusterAlgebra(['A', 3]) sage: S = A.initial_seed() sage: S.g_vectors() [(1, 0, 0), (0, 1, 0), (0, 0, 1)]
-
mutate
(direction, **kwargs)¶ Mutate
self
.INPUT:
direction
– in which direction(s) to mutate, it can be:- an integer in
range(self.rank())
to mutate in one direction only - an iterable of such integers to mutate along a sequence
- a string “sinks” or “sources” to mutate at all sinks or sources simultaneously
- an integer in
inplace
– bool (defaultTrue
); whether to mutate in place or to return a new objectmutating_F
– bool (defaultTrue
); whether to compute F-polynomials while mutating
Note
While knowing F-polynomials is essential to computing cluster variables, the process of mutating them is quite slow. If you care only about combinatorial data like g-vectors and c-vectors, setting
mutating_F=False
yields significant benefits in terms of speed.EXAMPLES:
sage: A = ClusterAlgebra(['A', 2]) sage: S = A.initial_seed() sage: S.mutate(0); S The seed of a Cluster Algebra with cluster variables x0, x1 and no coefficients over Integer Ring obtained from the initial by mutating in direction 0 sage: S.mutate(5) Traceback (most recent call last): ... ValueError: cannot mutate in direction 5
-
parent
()¶ Return the parent of
self
.EXAMPLES:
sage: A = ClusterAlgebra(['B', 3]) sage: A.current_seed().parent() == A True
-
path_from_initial_seed
()¶ Return a mutation sequence from the initial seed of
parent()
toself
.Warning
This is the path used to compute
self
and it does not have to be the shortest possible.EXAMPLES:
sage: A = ClusterAlgebra(['A', 2]) sage: S1 = A.initial_seed() sage: S1.mutate([0, 1, 0, 1]) sage: S1.path_from_initial_seed() [0, 1, 0, 1] sage: S2 = A.initial_seed() sage: S2.mutate(1) sage: S2.path_from_initial_seed() [1] sage: S1 == S2 True
-
class
sage.algebras.cluster_algebra.
PrincipalClusterAlgebraElement
¶ Bases:
sage.algebras.cluster_algebra.ClusterAlgebraElement
An element in a cluster algebra with principle coefficients.
-
F_polynomial
()¶ Return the F-polynomial of
self
.EXAMPLES:
sage: A = ClusterAlgebra(['B', 2], principal_coefficients=True) sage: S = A.initial_seed() sage: S.mutate([0, 1, 0]) sage: S.cluster_variable(0).F_polynomial() == S.F_polynomial(0) True sage: sum(A.initial_cluster_variables()).F_polynomial() Traceback (most recent call last): ... ValueError: this element is not homogeneous
-
g_vector
()¶ Return the g-vector of
self
.EXAMPLES:
sage: A = ClusterAlgebra(['B', 2], principal_coefficients=True) sage: A.cluster_variable((1, 0)).g_vector() == (1, 0) True sage: sum(A.initial_cluster_variables()).g_vector() Traceback (most recent call last): ... ValueError: this element is not homogeneous
-
homogeneous_components
()¶ Return a dictionary of the homogeneous components of
self
.OUTPUT:
A dictionary whose keys are homogeneous degrees and whose values are the summands of
self
of the given degree.EXAMPLES:
sage: A = ClusterAlgebra(['B', 2], principal_coefficients=True) sage: x = A.cluster_variable((1, 0)) + A.cluster_variable((0, 1)) sage: x.homogeneous_components() {(0, 1): x1, (1, 0): x0}
-
is_homogeneous
()¶ Return
True
ifself
is a homogeneous element ofself.parent()
.EXAMPLES:
sage: A = ClusterAlgebra(['B', 2], principal_coefficients=True) sage: A.cluster_variable((1, 0)).is_homogeneous() True sage: x = A.cluster_variable((1, 0)) + A.cluster_variable((0, 1)) sage: x.is_homogeneous() False
-