Skip to content

Commit

Permalink
Trac #27057: speedup crystal weight and spin e/f
Browse files Browse the repository at this point in the history
URL: https://trac.sagemath.org/27057
Reported by: mantepse
Ticket author(s): Travis Scrimshaw
Reviewer(s): Travis Scrimshaw, Martin Rubey
  • Loading branch information
Release Manager authored and vbraun committed Jan 25, 2019
2 parents 478d69a + d2fe93d commit 62bdcc4
Show file tree
Hide file tree
Showing 6 changed files with 859 additions and 540 deletions.
1 change: 1 addition & 0 deletions src/sage/categories/crystals.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ def an_element(self):
"""
return self.first()

@cached_method
def weight_lattice_realization(self):
"""
Return the weight lattice realization used to express weights
Expand Down
78 changes: 78 additions & 0 deletions src/sage/combinat/crystals/letters.pxd
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
from sage.structure.element cimport Element

cdef class Letter(Element):
cdef readonly int value

cdef class EmptyLetter(Element):
cdef readonly str value
cpdef e(self, int i)
cpdef f(self, int i)
cpdef int epsilon(self, int i)
cpdef int phi(self, int i)

cdef class Crystal_of_letters_type_A_element(Letter):
cpdef Letter e(self, int i)
cpdef Letter f(self, int i)
cpdef int epsilon(self, int i)
cpdef int phi(self, int i)

cdef class Crystal_of_letters_type_B_element(Letter):
cpdef Letter e(self, int i)
cpdef Letter f(self, int i)
cpdef int epsilon(self, int i)
cpdef int phi(self, int i)

cdef class Crystal_of_letters_type_C_element(Letter):
cpdef Letter e(self, int i)
cpdef Letter f(self, int i)
cpdef int epsilon(self, int i)
cpdef int phi(self, int i)

cdef class Crystal_of_letters_type_D_element(Letter):
cpdef Letter e(self, int i)
cpdef Letter f(self, int i)
cpdef int epsilon(self, int i)
cpdef int phi(self, int i)

cdef class Crystal_of_letters_type_G_element(Letter):
cpdef Letter e(self, int i)
cpdef Letter f(self, int i)
cpdef int epsilon(self, int i)
cpdef int phi(self, int i)

cdef class LetterTuple(Element):
cdef readonly tuple value
cpdef int epsilon(self, int i)
cpdef int phi(self, int i)

cdef class Crystal_of_letters_type_E6_element(LetterTuple):
cpdef LetterTuple e(self, int i)
cpdef LetterTuple f(self, int i)

cdef class Crystal_of_letters_type_E6_element_dual(LetterTuple):
cpdef LetterTuple lift(self)
cpdef LetterTuple retract(self, LetterTuple p)
cpdef LetterTuple e(self, int i)
cpdef LetterTuple f(self, int i)

cdef class Crystal_of_letters_type_E7_element(LetterTuple):
cpdef LetterTuple e(self, int i)
cpdef LetterTuple f(self, int i)

cdef class BKKLetter(Letter):
cpdef Letter e(self, int i)
cpdef Letter f(self, int i)

cdef class QueerLetter_element(Letter):
cpdef Letter e(self, int i)
cpdef Letter f(self, int i)
cpdef int epsilon(self, int i)
cpdef int phi(self, int i)

cdef class LetterWrapped(Element):
cdef readonly Element value
cpdef tuple _to_tuple(self)
cpdef LetterWrapped e(self, int i)
cpdef LetterWrapped f(self, int i)
cpdef int epsilon(self, int i)
cpdef int phi(self, int i)
18 changes: 5 additions & 13 deletions src/sage/combinat/crystals/letters.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -354,8 +354,6 @@ cdef class Letter(Element):
sage: C(1) != C(-1)
True
"""
cdef readonly int value

def __init__(self, parent, int value):
"""
EXAMPLES::
Expand Down Expand Up @@ -504,11 +502,11 @@ cdef class Letter(Element):
if op == Py_LT:
return self._parent.lt_elements(self, x)
if op == Py_GT:
return x.parent().lt_elements(x, self)
return x._parent.lt_elements(x, self)
if op == Py_LE:
return self.value == x.value or self._parent.lt_elements(self, x)
if op == Py_GE:
return self.value == x.value or x.parent().lt_elements(x, self)
return self.value == x.value or x._parent.lt_elements(x, self)
return False

cdef class EmptyLetter(Element):
Expand All @@ -522,8 +520,6 @@ cdef class EmptyLetter(Element):
Used in the rigged configuration bijections.
"""
cdef readonly str value

def __init__(self, parent):
"""
Initialize ``self``.
Expand Down Expand Up @@ -623,7 +619,7 @@ cdef class EmptyLetter(Element):
sage: C('E').weight()
(0, 0, 0)
"""
return self.parent().weight_lattice_realization().zero()
return self._parent.weight_lattice_realization().zero()

cpdef e(self, int i):
"""
Expand Down Expand Up @@ -1304,8 +1300,6 @@ cdef class LetterTuple(Element):
"""
Abstract class for type `E` letters.
"""
cdef readonly tuple value

def __init__(self, parent, tuple value):
"""
Initialize ``self``.
Expand Down Expand Up @@ -2785,8 +2779,6 @@ cdef class LetterWrapped(Element):
Element which uses another crystal implementation and converts
those elements to a tuple with `\pm i`.
"""
cdef readonly Element value

def __init__(self, parent, Element value):
"""
Initialize ``self``.
Expand Down Expand Up @@ -2940,7 +2932,7 @@ cdef class LetterWrapped(Element):
cdef Element ret = self.value.e(i)
if ret is None:
return None
return type(self)(self.parent(), ret)
return type(self)(self._parent, ret)

cpdef LetterWrapped f(self, int i):
r"""
Expand All @@ -2956,7 +2948,7 @@ cdef class LetterWrapped(Element):
cdef Element ret = self.value.f(i)
if ret is None:
return None
return type(self)(self.parent(), ret)
return type(self)(self._parent, ret)

cpdef int epsilon(self, int i):
r"""
Expand Down
21 changes: 21 additions & 0 deletions src/sage/combinat/crystals/spins.pxd
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from sage.structure.element cimport Element

cdef class Spin(Element):
cdef bint* _value
cdef int _n
cdef long _hash

cdef Spin _new_c(self, bint* value)

cdef class Spin_crystal_type_B_element(Spin):
cpdef Spin e(self, int i)
cpdef Spin f(self, int i)
cpdef int epsilon(self, int i)
cpdef int phi(self, int i)

cdef class Spin_crystal_type_D_element(Spin):
cpdef Spin e(self, int i)
cpdef Spin f(self, int i)
cpdef int epsilon(self, int i)
cpdef int phi(self, int i)

Loading

0 comments on commit 62bdcc4

Please sign in to comment.