Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
r""" 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:
- :class:`ClusterAlgebra`
- :class:`ClusterAlgebraSeed`
- :class:`ClusterAlgebraElement`
:class:`ClusterAlgebra`, constructed as a subobject of :class:`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 :class:`ClusterAlgebra` with minimal effort.
:class:`ClusterAlgebraSeed` provides the combinatorial backbone for :class:`ClusterAlgebra`. It is an auxiliary class and therefore its instances should **not** be directly created by the user. Rather it should be accessed via :meth:`ClusterAlgebra.current_seed` and :meth:`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.
:class:`ClusterAlgebraElement` is a thin wrapper around :class:`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 :class:`PrincipalClusterAlgebraElement`.
One more remark about this implementation. Instances of :class:`ClusterAlgebra` are built by identifying the initial cluster variables with the generators of :meth:`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, :meth:`ClusterAlgebra.mutate_initial` is forced to return a different instance of :class:`ClusterAlgebra`. At the moment there is no coercion implemented among the two instances but this could in principle be added to :meth:`ClusterAlgebra.mutate_initial`.
REFERENCES:
- [FZ2007]_ - [LLZ2014]_ - [NZ2012]_
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: A.g_vectors_so_far() [(0, 1), (0, -1), (1, 0), (-1, 1), (-1, 0)] sage: A.F_polynomials_so_far() [1, u1 + 1, 1, u0 + 1, u0*u1 + u0 + 1] sage: A.cluster_variables_so_far() [x1, (x0 + 1)/x1, x0, (x1 + 1)/x0, (x0 + x1 + 1)/(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 :class:`ClusterAlgebra` inherits from :class:`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 :class:`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: A.find_g_vector((-1, 1, -1, 1, -1, 1, 0, 0, 1), depth=2) sage: A.find_g_vector((-1, 1, -1, 1, -1, 1, 0, 0, 1)) [0, 1, 2, 4, 3]
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: A.find_g_vector((-1, 1, -2, 2, -1, 1, -1, 1, 1)) # long time [1, 0, 2, 6, 5, 4, 3, 8, 1] sage: A.current_seed().mutate(_) # 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] """
# **************************************************************************** # Copyright (C) 2015 Dylan Rupel and Salvatore Stella # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 2 of the License, or # (at your option) any later version. # http://www.gnu.org/licenses/ # ****************************************************************************
LaurentPolynomialRing)
############################################################################## # Elements of a cluster algebra ##############################################################################
""" An element of a cluster algebra. """ # AdditiveMagmas.Subobjects currently does not implements _add_ r""" Return the sum of ``self`` and ``other``.
INPUT:
- ``other`` -- an element of ``self.parent()``
EXAMPLES::
sage: A = ClusterAlgebra(['F', 4]) sage: A.an_element() + A.an_element() 2*x0 """
r""" Return the negative of ``self``.
EXAMPLES::
sage: A = ClusterAlgebra(['F', 4]) sage: -A.an_element() -x0 """
r""" Return the quotient of ``self`` and ``other``.
.. WARNING::
The result of a division is not guaranteed to be inside :meth:`parent` therefore this method does not return an instance of :class:`ClusterAlgebraElement`.
EXAMPLES::
sage: A = ClusterAlgebra(['F', 4]) sage: x = A.an_element() sage: x/x 1 sage: _.parent() Multivariate Laurent Polynomial Ring in x0, x1, x2, x3 over Integer Ring sage: A.retract(x/x) 1 sage: _.parent() A Cluster Algebra with cluster variables x0, x1, x2, x3 and no coefficients over Integer Ring """
r""" 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) """
r""" Return the string representation of ``self``.
EXAMPLES::
sage: A = ClusterAlgebra(['F', 4], principal_coefficients=True) sage: A.current_seed().mutate([0, 2, 1]) sage: A.cluster_variable((-1, 2, -2, 2)) (x0*x2^2*y0*y1*y2^2 + x1^3*x3^2 + x1^2*x3^2*y0 + 2*x1^2*x3*y2 + 2*x1*x3*y0*y2 + x1*y2^2 + y0*y2^2)/(x0*x1*x2^2) """
""" An element in a cluster algebra with principle coefficients. """ r""" 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 """
r""" 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 """
r""" Return ``True`` if ``self`` is a homogeneous element of ``self.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 """
r""" 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} """ -self.parent().b_matrix()]]) else:
############################################################################## # Seeds ##############################################################################
""" A seed in a Cluster Algebra.
INPUT:
- ``B`` -- a skew-symmetrizable integer matrix - ``C`` -- the matrix of c-vectors of ``self`` - ``G`` -- the matrix of g-vectors of ``self`` - ``parent`` -- :class:`ClusterAlgebra`; the algebra to which the seed belongs - ``path`` -- list (default ``[]``); the mutation sequence from the initial seed of ``parent`` to ``self``
.. 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 :meth:`__eq__` is no longer guaranteed to give correct answers. Use at your own risk. """ r""" Initialize ``self``.
EXAMPLES::
sage: A = ClusterAlgebra(['F', 4]) sage: from sage.algebras.cluster_algebra import ClusterAlgebraSeed sage: ClusterAlgebraSeed(A.b_matrix(), identity_matrix(4), identity_matrix(4), A, path=[1, 2, 3]) 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 [1, 2, 3] """
r""" Return a copy of ``self``.
EXAMPLES::
sage: A = ClusterAlgebra(['A', 3]) sage: S = copy(A.current_seed()) sage: S == A.current_seed() True sage: S is not A.current_seed() True """
r""" Test equality of two seeds.
INPUT:
- ``other`` -- a :class:`ClusterAlgebraSeed`
ALGORITHM:
``self`` and ``other`` are deemed to be equal if they have the same parent and their set of g-vectors coincide, i.e. this tests equality of unlabelled seeds.
EXAMPLES::
sage: A = ClusterAlgebra(['A', 3]) sage: A.clear_computed_data() sage: S = copy(A.current_seed()) sage: S.mutate([0, 2, 0]) sage: S == A.current_seed() False sage: S.mutate(2) sage: S == A.current_seed() True
sage: A = ClusterAlgebra(['B', 2], principal_coefficients=True) sage: S = A.current_seed() sage: S.mutate(0) sage: S == A.current_seed() True """ self.parent() == other.parent() and frozenset(self.g_vectors()) == frozenset(other.g_vectors()))
r""" Test whether ``element`` belong to ``self``.
INPUT:
- ``element`` -- either a g-vector or an element of :meth:`parent`
EXAMPLES::
sage: A = ClusterAlgebra(['A', 3]) sage: S = A.initial_seed() sage: (1, 0, 0) in S True sage: (1, 1, 0) in S False sage: A.cluster_variable((1, 0, 0)) in S True """ else:
r""" Return the hash of ``self``.
ALGORITHM:
For speed purposes the hash is computed on :meth:`self.g_vectors`. In particular it is guaranteed to be unique only within a given instance of :class:`ClusterAlgebra`. Moreover unlabelled seeds that have the same set of g-vectors have the same hash.
EXAMPLES::
sage: A = ClusterAlgebra(['A', 3]) sage: S = A.initial_seed() sage: hash(S) 6108559638409052534 # 64-bit 1755906422 # 32-bit """
r""" Return the string representation of ``self``.
EXAMPLES::
sage: A = ClusterAlgebra(['A', 3]) sage: A.clear_computed_data() sage: S = A.current_seed(); S The initial seed of a Cluster Algebra with cluster variables x0, x1, x2 and no coefficients over Integer Ring sage: S.mutate(0); S The seed of a Cluster Algebra with cluster variables x0, x1, x2 and no coefficients over Integer Ring obtained from the initial by mutating in direction 0 sage: S.mutate(1); S The seed of a Cluster Algebra with cluster variables x0, x1, x2 and no coefficients over Integer Ring obtained from the initial by mutating along the sequence [0, 1] """ else:
r""" Return the parent of ``self``.
EXAMPLES::
sage: A = ClusterAlgebra(['B', 3]) sage: A.current_seed().parent() == A True """
r""" Return the length of a mutation sequence from the initial seed of :meth:`parent` to ``self``.
.. WARNING::
This is the length of the mutation sequence returned by :meth:`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 """
r""" Return a mutation sequence from the initial seed of :meth:`parent` to ``self``.
.. 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 """
r""" 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] """
r""" 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] """
r""" Return the ``j``-th c-vector of ``self``.
INPUT:
- ``j`` -- an integer in ``range(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) """
r""" 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)] """
r""" 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] """
r""" Return the ``j``-th g-vector of ``self``.
INPUT:
- ``j`` -- an integer in ``range(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) """
r""" 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)] """
r""" Return the ``j``-th F-polynomial of ``self``.
INPUT:
- ``j`` -- an integer in ``range(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 """
r""" 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] """
r""" Return the ``j``-th cluster variable of ``self``.
INPUT:
- ``j`` -- an integer in ``range(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 """
r""" 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] """
r""" 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
- ``inplace`` -- bool (default ``True``); whether to mutate in place or to return a new object
- ``mutating_F`` -- bool (default ``True``); 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 """
# do we want to change self? else:
# construct mutation sequence # if you change this be considerate and change also :class:`ClusterAlgebra`.mutate_initial B = self.b_matrix() seq = [i for i in range(n) if all(x >= 0 for x in B.column(i))] else:
# are we mutating F-polynomials?
# store new mutation path else:
# find sign of k-th c-vector else:
# store the g-vector to be mutated in case we are mutating F-polynomials also
# compute new G-matrix
# path to new g-vector (we store the shortest encountered so far)
# compute F-polynomials
# compute new C-matrix
# compute new B-matrix
# return if we need to
r""" Compute new F-polynomial obtained by mutating in direction ``k``.
INPUT:
- ``k`` -- an integer in ``range(self.parent().rank())``; the direction in which we are mutating
- ``old_g_vector`` -- tuple; the k-th g-vector of ``self`` before mutating
.. NOTE::
This function is the bottleneck of :meth:`mutate`. The problem is that operations on polynomials are slow. One can get a significant speed boost by disabling this method calling :meth:`mutate` with ``mutating_F=False``.
EXAMPLES::
sage: A = ClusterAlgebra(['A', 2]) sage: S = A.initial_seed() sage: S.mutate(0) sage: S._mutated_F(0, (1, 0)) u0 + 1 """ else:
############################################################################## # Cluster algebras ##############################################################################
r""" A Cluster Algebra.
INPUT:
- ``data`` -- some data defining a cluster algebra; it can be anything that can be parsed by :class:`ClusterQuiver`
- ``scalars`` -- a ring (default `\ZZ`); the scalars over which the cluster algebra is defined
- ``cluster_variable_prefix`` -- string (default ``'x'``); it needs to be a valid variable name
- ``cluster_variable_names`` -- a list of strings; each element needs to be a valid variable name; supersedes ``cluster_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; supersedes ``cluster_variable_prefix``
- ``principal_coefficients`` -- bool (default ``False``); supersedes any coefficient defined by ``data``
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 """
def __classcall__(self, data, **kwargs): r""" Preparse input to make it hashable.
EXAMPLES::
sage: A = ClusterAlgebra(['A', 2]); A # indirect doctest A Cluster Algebra with cluster variables x0, x1 and no coefficients over Integer Ring """
""" Initialize ``self``.
TESTS::
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) sage: A.clear_computed_data() sage: TestSuite(A).run() sage: A = ClusterAlgebra(['A', 2]) sage: A.clear_computed_data() sage: TestSuite(A).run() sage: A = ClusterAlgebra(['A', 3], principal_coefficients=True) sage: A.clear_computed_data() sage: TestSuite(A).run() sage: A = ClusterAlgebra(['A', 2], principal_coefficients=True, coefficient_prefix='x') sage: A.clear_computed_data() sage: TestSuite(A).run() sage: A = ClusterAlgebra(['A', 3], principal_coefficients=True, cluster_variable_names=['a','b','c']) sage: A.clear_computed_data() sage: TestSuite(A).run() sage: A = ClusterAlgebra(['A', 3], principal_coefficients=True, coefficient_names=['a','b','c']) sage: A.clear_computed_data() sage: TestSuite(A).run() """ # Parse input else:
# Ambient space for F-polynomials # NOTE: for speed purposes we need to have QQ here instead of the more # natural ZZ. The reason is that _mutated_F is faster if we do not cast # the result to polynomials but then we get "rational" coefficients
# Setup infrastructure to store computed data
# Determine the names of the initial cluster variables
# Determine scalars
# Determine coefficients and base else: else:
# Have we got principal coefficients? else:
# Setup Parent and ambient names=variables + coefficients)
# Data to compute cluster variables using separation of additions # NOTE: storing both _B0 as rectangular matrix and _yhat is redundant. # We keep both around for speed purposes. for j in range(self._n)} for i in range(self._n + m)) for j in range(self._n)}
# Register embedding into self.ambient()
r""" Return the string representation of ``self``.
EXAMPLES::
sage: A = ClusterAlgebra(matrix(1), principal_coefficients=True); A A Cluster Algebra with cluster variable x0 and coefficient y0 over Integer Ring sage: A = ClusterAlgebra(['A', 2], principal_coefficients=True); A A Cluster Algebra with cluster variables x0, x1 and coefficients y0, y1 over Integer Ring """
r""" Return an element of ``self``.
EXAMPLES::
sage: A = ClusterAlgebra(['A', 2]) sage: A.an_element() x0 """
r""" Test whether there is a coercion from ``other`` to ``self``.
ALGORITHM:
If ``other`` is an instance of :class:`ClusterAlgebra` then allow coercion if ``other.ambient()`` can be coerced into ``self.ambient()`` and ``other`` can be obtained from ``self`` by permuting variables and coefficients and/or freezing some initial cluster variables.
Otherwise allow anything that coerces into ``self.base()`` to coerce into ``self``.
EXAMPLES::
sage: B1 = 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: B2 = B1.matrix_from_columns([0, 1, 2]) sage: A1 = ClusterAlgebra(B1, coefficient_prefix='x') sage: A2 = ClusterAlgebra(B2, coefficient_prefix='x') sage: A1.has_coerce_map_from(A2) True sage: A2.has_coerce_map_from(A1) False sage: f = A1.coerce_map_from(A2) sage: A2.find_g_vector((-1, 1, -1)) [0, 2, 1] sage: S = A1.initial_seed(); S.mutate([0, 2, 1]) sage: S.cluster_variable(1) == f(A2.cluster_variable((-1, 1, -1))) True sage: B3 = B1.matrix_from_columns([1, 2, 3]); B3 [ 1 0 0] [ 0 -1 0] [ 1 0 1] [ 0 -2 0] [ 0 0 0] [-1 0 0] sage: G = PermutationGroup(['(1, 2, 3, 4)']) sage: B3.permute_rows(G.gen(0)); B3 [ 0 -1 0] [ 1 0 1] [ 0 -2 0] [ 1 0 0] [ 0 0 0] [-1 0 0] sage: A3 = ClusterAlgebra(B3, cluster_variable_names=['x1', 'x2', 'x3'], coefficient_names=['x0', 'x4', 'x5']) sage: A1.has_coerce_map_from(A3) True sage: g = A1.coerce_map_from(A3) sage: A3.find_g_vector((1, -2, 2)) [1, 2, 1, 0] sage: [G.gen(0)(x + 1) - 1 for x in [1, 2, 1, 0]] [2, 3, 2, 1] sage: S = A1.initial_seed(); S.mutate([2, 3, 2, 1]) sage: S.cluster_variable(1) == g(A3.cluster_variable((1, -2, 2))) True
Check that :trac:`23654` is fixed::
sage: A = ClusterAlgebra(['A',2]) sage: AA = ClusterAlgebra(['A',3]) sage: A.has_coerce_map_from(AA) False """
# everything that is in the base can be coerced to self
r""" Return the rank of ``self``, i.e. the number of cluster variables in any seed.
EXAMPLES::
sage: A = ClusterAlgebra(['A', 2], principal_coefficients=True); A A Cluster Algebra with cluster variables x0, x1 and coefficients y0, y1 over Integer Ring sage: A.rank() 2 """
r""" Return the current seed of ``self``.
EXAMPLES::
sage: A = ClusterAlgebra(['A', 2]) sage: A.clear_computed_data() sage: A.current_seed() The initial seed of a Cluster Algebra with cluster variables x0, x1 and no coefficients over Integer Ring """
r""" Set the value reported by :meth:`current_seed` to ``seed``, if it makes sense.
INPUT:
- ``seed`` -- a :class:`ClusterAlgebraSeed`
EXAMPLES::
sage: A = ClusterAlgebra(['A', 2]) sage: A.clear_computed_data() sage: S = copy(A.current_seed()) sage: S.mutate([0, 1, 0]) sage: A.current_seed() == S False sage: A.set_current_seed(S) sage: A.current_seed() == S True sage: A1 = ClusterAlgebra(['B', 2]) sage: A.set_current_seed(A1.initial_seed()) Traceback (most recent call last): ... ValueError: This is not a seed in this cluster algebra """ else:
r""" Reset the value reported by :meth:`current_seed` to :meth:`initial_seed`.
EXAMPLES::
sage: A = ClusterAlgebra(['A', 2]) sage: A.clear_computed_data() sage: A.current_seed().mutate([1, 0]) sage: A.current_seed() == A.initial_seed() False sage: A.reset_current_seed() sage: A.current_seed() == A.initial_seed() True """
r""" Clear the cache of computed g-vectors and F-polynomials and reset both the current seed and the exploring iterator.
EXAMPLES::
sage: A = ClusterAlgebra(['A', 2]) sage: A.clear_computed_data() sage: A.g_vectors_so_far() [(0, 1), (1, 0)] sage: A.current_seed().mutate([1, 0]) sage: A.g_vectors_so_far() [(0, 1), (0, -1), (1, 0), (-1, 0)] sage: A.clear_computed_data() sage: A.g_vectors_so_far() [(0, 1), (1, 0)] """
r""" Test if ``seed`` is a seed of ``self``.
INPUT:
- ``seed`` -- a :class:`ClusterAlgebraSeed`
EXAMPLES::
sage: A = ClusterAlgebra(['A', 2], principal_coefficients=True); A A Cluster Algebra with cluster variables x0, x1 and coefficients y0, y1 over Integer Ring sage: S = copy(A.current_seed()) sage: A.contains_seed(S) True """
r""" Return the initial seed of ``self``.
EXAMPLES::
sage: A = ClusterAlgebra(['A', 2]) sage: A.initial_seed() The initial seed of a Cluster Algebra with cluster variables x0, x1 and no coefficients over Integer Ring """
r""" Return the initial exchange matrix of ``self``.
EXAMPLES::
sage: A = ClusterAlgebra(['A', 2]) sage: A.b_matrix() [ 0 1] [-1 0] """
r""" Return an iterator producing all the g-vectors of ``self``.
INPUT:
- ``mutating_F`` -- bool (default ``True``); whether to compute F-polynomials; disable this for speed considerations
ALGORITHM:
This method does not use the caching framework provided by ``self``, but recomputes all the g-vectors from scratch. On the other hand it stores the results so that other methods like :meth:`g_vectors_so_far` can access them afterwards.
EXAMPLES::
sage: A = ClusterAlgebra(['A', 3]) sage: len(list(A.g_vectors())) 9 """
r""" Return an iterator producing all the cluster variables of ``self``.
ALGORITHM:
This method does not use the caching framework provided by ``self``, but recomputes all the cluster variables from scratch. On the other hand it stores the results so that other methods like :meth:`cluster_variables_so_far` can access them afterwards.
EXAMPLES::
sage: A = ClusterAlgebra(['A', 3]) sage: len(list(A.cluster_variables())) 9 """
r""" Return an iterator producing all the F_polynomials of ``self``.
ALGORITHM:
This method does not use the caching framework provided by ``self``, but recomputes all the F-polynomials from scratch. On the other hand it stores the results so that other methods like :meth:`F_polynomials_so_far` can access them afterwards.
EXAMPLES::
sage: A = ClusterAlgebra(['A', 3]) sage: len(list(A.F_polynomials())) 9 """
r""" Return a list of the g-vectors of cluster variables encountered so far.
EXAMPLES::
sage: A = ClusterAlgebra(['A', 2]) sage: A.clear_computed_data() sage: A.current_seed().mutate(0) sage: A.g_vectors_so_far() [(0, 1), (1, 0), (-1, 1)] """
r""" Return a list of the cluster variables encountered so far.
EXAMPLES::
sage: A = ClusterAlgebra(['A', 2]) sage: A.clear_computed_data() sage: A.current_seed().mutate(0) sage: A.cluster_variables_so_far() [x1, x0, (x1 + 1)/x0] """
r""" Return a list of the F-polynomials encountered so far.
EXAMPLES::
sage: A = ClusterAlgebra(['A', 2]) sage: A.clear_computed_data() sage: A.current_seed().mutate(0) sage: A.F_polynomials_so_far() [1, 1, u0 + 1] """
def cluster_variable(self, g_vector): r""" Return the cluster variable with g-vector ``g_vector`` if it has been found.
INPUT:
- ``g_vector`` -- tuple; the g-vector of the cluster variable to return
ALGORITHM:
This function computes cluster variables from their g-vectors and F-polynomials using the "separation of additions" formula of Theorem 3.7 in [FZ2007]_.
EXAMPLES::
sage: A = ClusterAlgebra(['A', 2]) sage: A.initial_seed().mutate(0) sage: A.cluster_variable((-1, 1)) (x1 + 1)/x0 """
r""" Return the F-polynomial with g-vector ``g_vector`` if it has been found.
INPUT:
- ``g_vector`` -- tuple; the g-vector of the F-polynomial to return
EXAMPLES::
sage: A = ClusterAlgebra(['A', 2]) sage: A.clear_computed_data() sage: A.F_polynomial((-1, 1)) Traceback (most recent call last): ... KeyError: 'the g-vector (-1, 1) has not been found yet' sage: A.initial_seed().mutate(0, mutating_F=False) sage: A.F_polynomial((-1, 1)) Traceback (most recent call last): ... KeyError: 'the F-polynomial with g-vector (-1, 1) has not been computed yet; you can compute it by mutating from the initial seed along the sequence [0]' sage: A.initial_seed().mutate(0) sage: A.F_polynomial((-1, 1)) u0 + 1 """ else:
r""" Return a mutation sequence to obtain a seed containing the g-vector ``g_vector`` from the initial seed.
INPUT:
- ``g_vector`` -- a tuple: the g-vector to find - ``depth`` -- a positive integer or infinity (default ``infinity``); the maximum distance from ``self.current_seed`` to reach
OUTPUT:
This function returns a list of integers if it can find ``g_vector``, otherwise it returns ``None``. If the exploring iterator stops, it means that the algebra is of finite type and ``g_vector`` is not the g-vector of any cluster variable. In this case the function resets the iterator and raises an error.
EXAMPLES::
sage: A = ClusterAlgebra(['G', 2], principal_coefficients=True) sage: A.clear_computed_data() sage: A.find_g_vector((-2, 3), depth=2) sage: A.find_g_vector((-2, 3), depth=3) [0, 1, 0] sage: A.find_g_vector((1, 1), depth=3) sage: A.find_g_vector((1, 1), depth=4) Traceback (most recent call last): ... ValueError: (1, 1) is not the g-vector of any cluster variable of a Cluster Algebra with cluster variables x0, x1 and coefficients y0, y1 over Integer Ring """ else: # We got an exception because self._sd_iter caught a KeyboardInterrupt, let's raise it again raise seed # Unless self._sd_iter has been manually altered, we checked # all the seeds of self and did not find g_vector. # Do some house cleaning before failing
r""" Return the Laurent polynomial ring containing ``self``.
EXAMPLES::
sage: A = ClusterAlgebra(['A', 2], principal_coefficients=True) sage: A.ambient() Multivariate Laurent Polynomial Ring in x0, x1, y0, y1 over Integer Ring """
r""" Return the ring of scalars over which ``self`` is defined.
EXAMPLES::
sage: A = ClusterAlgebra(['A', 2]) sage: A.scalars() Integer Ring """
r""" Return ``x`` as an element of :meth:`ambient`.
EXAMPLES::
sage: A = ClusterAlgebra(['A', 2], principal_coefficients=True) sage: x = A.cluster_variable((1, 0)) sage: A.lift(x).parent() Multivariate Laurent Polynomial Ring in x0, x1, y0, y1 over Integer Ring """
r""" Return ``x`` as an element of ``self``.
EXAMPLES::
sage: A = ClusterAlgebra(['A', 2], principal_coefficients=True) sage: L = A.ambient() sage: x = L.gen(0) sage: A.retract(x).parent() A Cluster Algebra with cluster variables x0, x1 and coefficients y0, y1 over Integer Ring """
def gens(self): r""" Return the list of initial cluster variables and coefficients of ``self``.
EXAMPLES::
sage: A = ClusterAlgebra(['A', 2], principal_coefficients=True) sage: A.gens() (x0, x1, y0, y1) sage: A = ClusterAlgebra(['A', 2], principal_coefficients=True, coefficient_prefix='x') sage: A.gens() (x0, x1, x2, x3) """
r""" Return the ``j``-th coefficient of ``self``.
INPUT:
- ``j`` -- an integer in ``range(self.parent().rank())``; the index of the coefficient to return
EXAMPLES::
sage: A = ClusterAlgebra(['A', 2], principal_coefficients=True) sage: A.coefficient(0) y0 """ raise ValueError("generator not defined")
def coefficients(self): r""" Return the list of coefficients of ``self``.
EXAMPLES::
sage: A = ClusterAlgebra(['A', 2], principal_coefficients=True) sage: A.coefficients() (y0, y1) sage: A1 = ClusterAlgebra(['B', 2]) sage: A1.coefficients() () """ else:
r""" Return the list of coefficient names.
EXAMPLES::
sage: A = ClusterAlgebra(['A', 3]) sage: A.coefficient_names() () sage: A1 = ClusterAlgebra(['B', 2], principal_coefficients=True) sage: A1.coefficient_names() ('y0', 'y1') sage: A2 = ClusterAlgebra(['C', 3], principal_coefficients=True, coefficient_prefix='x') sage: A2.coefficient_names() ('x3', 'x4', 'x5') """
r""" Return the ``j``-th initial cluster variable of ``self``.
INPUT:
- ``j`` -- an integer in ``range(self.parent().rank())``; the index of the cluster variable to return
EXAMPLES::
sage: A = ClusterAlgebra(['A', 2], principal_coefficients=True) sage: A.initial_cluster_variable(0) x0 """
def initial_cluster_variables(self): r""" Return the list of initial cluster variables of ``self``.
EXAMPLES::
sage: A = ClusterAlgebra(['A', 2], principal_coefficients=True) sage: A.initial_cluster_variables() (x0, x1) """
r""" Return the list of initial cluster variable names.
EXAMPLES::
sage: A = ClusterAlgebra(['A', 2], principal_coefficients=True) sage: A.initial_cluster_variable_names() ('x0', 'x1') sage: A1 = ClusterAlgebra(['B', 2], cluster_variable_prefix='a') sage: A1.initial_cluster_variable_names() ('a0', 'a1') """
r""" Return an iterator running over seeds of ``self``.
INPUT:
- ``from_current_seed`` -- bool (default ``False``); whether to start the iterator from :meth:`current_seed` or :meth:`initial_seed`
- ``mutating_F`` -- bool (default ``True``); whether to compute F-polynomials also; disable this for speed considerations
- ``allowed_directions`` -- iterable of integers (default ``range(self.rank())``); the directions in which to mutate
- ``depth`` -- a positive integer or infinity (default ``infinity``); the maximum depth at which to stop searching
- ``catch_KeyboardInterrupt`` -- bool (default ``False``); whether to catch ``KeyboardInterrupt`` and return it rather then raising an exception -- this allows the iterator returned by this method to be resumed after being interrupted
ALGORITHM:
This function traverses the exchange graph in a breadth-first search.
EXAMPLES::
sage: A = ClusterAlgebra(['A', 4]) sage: A.clear_computed_data() sage: seeds = A.seeds(allowed_directions=[3, 0, 1]) sage: _ = list(seeds) sage: A.g_vectors_so_far() [(-1, 0, 0, 0), (1, 0, 0, 0), (0, 0, 0, 1), (0, -1, 0, 0), (0, 0, 1, 0), (0, 1, 0, 0), (-1, 1, 0, 0), (0, 0, 0, -1)] """ # should we begin from the current seed? seed = copy(self.current_seed()) else:
# yield first seed
# keep track of depth
# do we mutate F-polynomials?
# which directions are we allowed to mutate into
# setup seeds storage
# ready, set, go! # remember if we got a new seed
# we can mutate in some direction # we already had new_sd, make sure it does not mutate to sd during next round else: # we got a new seed # next round do not mutate back to sd and make sure we only walk three sides of squares except KeyboardInterrupt as e: if kwargs.get('catch_KeyboardInterrupt', False): print("caught a KeyboardInterrupt; cleaning up before returning") # mutation in direction i was not completed; put it back in for next round directions.append(i) yield e continue else: raise e # we went one step deeper
r""" Reset the iterator used to explore ``self``.
INPUT:
- ``mutating_F`` -- bool (default ``True``); whether to also compute F-polynomials; disable this for speed considerations
EXAMPLES::
sage: A = ClusterAlgebra(['A', 4]) sage: A.clear_computed_data() sage: A.reset_exploring_iterator(mutating_F=False) sage: A.explore_to_depth(infinity) sage: len(A.g_vectors_so_far()) 14 sage: len(A.F_polynomials_so_far()) 4 """
r""" Explore the exchange graph of ``self`` up to distance ``depth`` from the initial seed.
INPUT:
- ``depth`` -- a positive integer or infinity; the maximum depth at which to stop searching
EXAMPLES::
sage: A = ClusterAlgebra(['A', 4]) sage: A.explore_to_depth(infinity) sage: len(A.g_vectors_so_far()) 14 """ else: # We got an exception because self._sd_iter caught a KeyboardInterrupt, let's raise it again raise seed
r""" Return the cluster fan (the fan of g-vectors) of ``self``.
INPUT:
- ``depth`` -- a positive integer or infinity (default ``infinity``); the maximum depth at which to compute
EXAMPLES::
sage: A = ClusterAlgebra(['A', 2]) sage: A.cluster_fan() Rational polyhedral fan in 2-d lattice N """
r""" Return the cluster algebra obtained by mutating ``self`` at the initial seed.
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
ALGORITHM:
This function computes data for the new algebra from known data for the old algebra using Equation (4.2) from [NZ2012]_ for g-vectors, and Equation (6.21) from [FZ2007]_ for F-polynomials. The exponent `h` in the formula for F-polynomials is ``-min(0, old_g_vect[k])`` due to [NZ2012]_ Proposition 4.2.
EXAMPLES::
sage: A = ClusterAlgebra(['F', 4]) sage: A.explore_to_depth(infinity) sage: B = A.b_matrix() sage: B.mutate(0) sage: A1 = ClusterAlgebra(B) sage: A1.explore_to_depth(infinity) sage: A2 = A1.mutate_initial(0) sage: A2._F_poly_dict == A._F_poly_dict True
Check that we did not mess up the original algebra because of :class:`UniqueRepresentation`::
sage: A = ClusterAlgebra(['A',2]) sage: A.mutate_initial(0) is A False """
# construct mutation sequence # if you change this be considerate and change also :class:`ClusterAlgebraSeed`.mutate B = self.b_matrix() seq = [i for i in range(n) if all(x <= 0 for x in B.column(i))] B = self.b_matrix() seq = [i for i in range(n) if all(x >= 0 for x in B.column(i))] else:
# setup
# go raise ValueError('cannot mutate in direction ' + str(k))
# clear storage
# mutate B-matrix
# here we have \mp B0 rather then \pm B0 because we want the k-th row of the old B0
# compute new g-vector # here we have -eps*B0 rather than eps*B0 because we want the k-th column of the old B0
# compute new path
# compute new F-polynomial
# update storage
# create new algebra coefficient_names=coeff_names, scalars=scalars)
# store computed data
# reset self.current_seed() to the previous location
r""" Return the greedy element with denominator vector ``d_vector``.
INPUT:
- ``d_vector`` -- tuple of 2 integers; the denominator vector of the element to compute
ALGORITHM:
This implements greedy elements of a rank 2 cluster algebra using Equation (1.5) from [LLZ2014]_.
EXAMPLES::
sage: A = ClusterAlgebra(['A', [1, 1], 1]) sage: A.greedy_element((1, 1)) (x0^2 + x1^2 + 1)/(x0*x1) """ raise ValueError('greedy elements are only defined in rank 2')
raise NotImplementedError('can only compute greedy elements in the coefficient-free case')
# Here we use the generators of self.ambient() because cluster variables # do not have an inverse. if a2 < 0: return self.retract(x1 ** (-a1) * x2 ** (-a2)) else: return self.retract(x1 ** (-a1) * ((1 + x2 ** c) / x1) ** a2) return self.retract(((1 + x1 ** b) / x2) ** a1 * x2 ** (-a2))
r""" Return the coefficient of the monomial ``x1 ** (b * p) * x2 ** (c * q)`` in the numerator of the greedy element with denominator vector ``d_vector``.
EXAMPLES::
sage: A = ClusterAlgebra(['A', [1, 1], 1]) sage: A.greedy_element((1, 1)) (x0^2 + x1^2 + 1)/(x0*x1) sage: A._greedy_coefficient((1, 1), 0, 0) 1 sage: A._greedy_coefficient((1, 1), 1, 0) 1 """
# DESIDERATA # Some of these are probably unrealistic r""" Return the upper cluster algebra associated to ``self``.
EXAMPLES::
sage: A = ClusterAlgebra(['F', 4]) sage: A.upper_cluster_algebra() Traceback (most recent call last): ... NotImplementedError: not implemented yet """
r""" Return the upper bound associated to ``self``.
EXAMPLES::
sage: A = ClusterAlgebra(['F', 4]) sage: A.upper_bound() Traceback (most recent call last): ... NotImplementedError: not implemented yet """
r""" Return the lower bound associated to ``self``.
EXAMPLES::
sage: A = ClusterAlgebra(['F', 4]) sage: A.lower_bound() Traceback (most recent call last): ... NotImplementedError: not implemented yet """
r""" Return the element of the theta basis with g-vector ``g_vector``.
EXAMPLES::
sage: A = ClusterAlgebra(['F', 4]) sage: A.theta_basis_element((1, 0, 0, 0)) Traceback (most recent call last): ... NotImplementedError: not implemented yet """ |