Path: blob/master/sage/categories/examples/crystals.py
4072 views
r"""1Example of a crystal2"""3#*****************************************************************************4# Copyright (C) 2010 Anne Schilling <anne at math.ucdavis.edu>5#6# Distributed under the terms of the GNU General Public License (GPL)7# http://www.gnu.org/licenses/8#******************************************************************************910from sage.structure.parent import Parent11from sage.structure.element_wrapper import ElementWrapper12from sage.structure.unique_representation import UniqueRepresentation13from sage.categories.classical_crystals import ClassicalCrystals14from sage.graphs.all import DiGraph15from sage.categories.enumerated_sets import EnumeratedSets16from sage.combinat.root_system.cartan_type import CartanType1718class HighestWeightCrystalOfTypeA(UniqueRepresentation, Parent):19r"""20An example of a crystal: the highest weight crystal of type `A_n`21of highest weight `\omega_1`.2223The purpose of this class is to provide a minimal template for24implementing crystals. See25:class:`~sage.combinat.crystals.letters.CrystalOfLetters` for a26full featured and optimized implementation.2728EXAMPLES::2930sage: C = Crystals().example()31sage: C32Highest weight crystal of type A_3 of highest weight omega_133sage: C.category()34Category of classical crystals3536The elements of this crystal are in the set `\{1,\ldots,n+1\}`::3738sage: C.list()39[1, 2, 3, 4]40sage: C.module_generators[0]4114243The crystal operators themselves correspond to the elementary44transpositions::4546sage: b = C.module_generators[0]47sage: b.f(1)48249sage: b.f(1).e(1) == b50True5152TESTS::5354sage: C = Crystals().example()55sage: TestSuite(C).run(verbose = True)56running ._test_an_element() . . . pass57running ._test_category() . . . pass58running ._test_elements() . . .59Running the test suite of self.an_element()60running ._test_category() . . . pass61running ._test_eq() . . . pass62running ._test_not_implemented_methods() . . . pass63running ._test_pickling() . . . pass64running ._test_stembridge_local_axioms() . . . pass65pass66running ._test_elements_eq() . . . pass67running ._test_enumerated_set_contains() . . . pass68running ._test_enumerated_set_iter_cardinality() . . . pass69running ._test_enumerated_set_iter_list() . . . pass70running ._test_eq() . . . pass71running ._test_fast_iter() . . . pass72running ._test_not_implemented_methods() . . . pass73running ._test_pickling() . . . pass74running ._test_some_elements() . . . pass75running ._test_stembridge_local_axioms() . . . pass7677Only the following basic operations are implemented:78- :meth:`~sage.categories.crystals.Crystals.cartan_type` or an attribute _cartan_type79- an attribute module_generators80- :meth:`.Element.e`81- :meth:`.Element.f`8283All the other usual crystal operations are inherited from the84categories; for example::8586sage: C.cardinality()87488"""8990def __init__(self, n = 3):91"""92EXAMPLES::9394sage: C = sage.categories.examples.crystals.HighestWeightCrystalOfTypeA(n=4)95sage: C == Crystals().example(n=4)96True97"""98Parent.__init__(self, category = ClassicalCrystals())99self.n = n100self._cartan_type = CartanType(['A',n])101self.module_generators = [ self(1) ]102103def _repr_(self):104"""105EXAMPLES::106107sage: Crystals().example()108Highest weight crystal of type A_3 of highest weight omega_1109"""110return "Highest weight crystal of type A_%s of highest weight omega_1"%(self.n)111112# temporary woraround while an_element is overriden by Parent113_an_element_ = EnumeratedSets.ParentMethods._an_element_114115class Element(ElementWrapper):116117def e(self, i):118r"""119Returns the action of `e_i` on ``self``.120121EXAMPLES::122123sage: C = Crystals().example(4)124sage: [[c,i,c.e(i)] for i in C.index_set() for c in C if c.e(i) is not None]125[[2, 1, 1], [3, 2, 2], [4, 3, 3], [5, 4, 4]]126"""127assert i in self.index_set()128if self.value == i+1:129return self.parent()(self.value-1)130else:131return None132133def f(self, i):134r"""135Returns the action of `f_i` on ``self``.136137EXAMPLES::138139sage: C = Crystals().example(4)140sage: [[c,i,c.f(i)] for i in C.index_set() for c in C if c.f(i) is not None]141[[1, 1, 2], [2, 2, 3], [3, 3, 4], [4, 4, 5]]142"""143assert i in self.index_set()144if self.value == i:145return self.parent()(self.value+1)146else:147return None148149150class NaiveCrystal(UniqueRepresentation, Parent):151r"""152This is an example of a "crystal" which does not come from any kind of153representation, designed primarily to test the Stembridge local rules with.154The crystal has vertices labeled 0 through 5, with 0 the highest weight.155156The code here could also possibly be generalized to create a class that157automatically builds a crystal from an edge-colored digraph, if someone158feels adventurous.159160Currently, only the methods :meth:`highest_weight_vector`, :meth:`e`, and :meth:`f` are161guaranteed to work.162163EXAMPLES::164165sage: C = Crystals().example(choice='naive')166sage: C.highest_weight_vector()1670168"""169def __init__(self):170"""171EXAMPLES::172173sage: C = sage.categories.examples.crystals.NaiveCrystal()174sage: C == Crystals().example(choice='naive')175True176"""177Parent.__init__(self, category = ClassicalCrystals())178self.n = 2179self._cartan_type = CartanType(['A',2])180self.G = DiGraph(5)181self.G.add_edges([ [0,1,1], [1,2,1], [2,3,1], [3,5,1], [0,4,2], [4,5,2] ])182self.module_generators = [ self(0) ]183184def __repr__(self):185"""186EXAMPLES::187188sage: Crystals().example(choice='naive')189A broken crystal, defined by digraph, of dimension five.190"""191return "A broken crystal, defined by digraph, of dimension five."192193class Element(ElementWrapper):194def e(self, i):195r"""196Returns the action of `e_i` on ``self``.197198EXAMPLES::199200sage: C = Crystals().example(choice='naive')201sage: [[c,i,c.e(i)] for i in C.index_set() for c in [C(j) for j in [0..5]] if c.e(i) is not None]202[[1, 1, 0], [2, 1, 1], [3, 1, 2], [5, 1, 3], [4, 2, 0], [5, 2, 4]]203"""204assert i in self.index_set()205for edge in self.parent().G.edges():206if edge[1]==int(str(self)) and edge[2]==i:207return self.parent()(edge[0])208return None209210def f(self, i):211r"""212Returns the action of `f_i` on ``self``.213214EXAMPLES::215216sage: C = Crystals().example(choice='naive')217sage: [[c,i,c.f(i)] for i in C.index_set() for c in [C(j) for j in [0..5]] if c.f(i) is not None]218[[0, 1, 1], [1, 1, 2], [2, 1, 3], [3, 1, 5], [0, 2, 4], [4, 2, 5]]219"""220assert i in self.index_set()221for edge in self.parent().G.edges_incident(int(str(self))):222if edge[2] == i:223return self.parent()(edge[1])224return None225226227228229