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

Commit

Permalink
Use PathAlgebraElement for path algebras. Still missing: Pickling
Browse files Browse the repository at this point in the history
  • Loading branch information
simon-king-jena committed Nov 30, 2014
1 parent 1fda709 commit 15ed81d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 14 deletions.
34 changes: 22 additions & 12 deletions src/sage/quivers/algebra.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

from sage.misc.cachefunc import cached_method
from sage.combinat.free_module import CombinatorialFreeModule, CombinatorialFreeModuleElement
from algebra_elements import PathAlgebraElement

class PathAlgebra(CombinatorialFreeModule):
r"""
Expand Down Expand Up @@ -110,14 +111,16 @@ class PathAlgebra(CombinatorialFreeModule):
sage: TestSuite(A).run()
"""

Element = PathAlgebraElement

###########################################################################
# #
# PRIVATE FUNCTIONS #
# These functions are not meant to be seen by the end user. #
# #
###########################################################################

def __init__(self, k, P):
def __init__(self, k, P, order = "negdegrevlex"):
"""
Creates a :class:`PathAlgebra` object. Type ``PathAlgebra?`` for
more information.
Expand Down Expand Up @@ -148,13 +151,17 @@ def __init__(self, k, P):
from sage.categories.graded_algebras_with_basis import GradedAlgebrasWithBasis
self._quiver = P.quiver()
self._semigroup = P
self._ordstr = order
super(PathAlgebra, self).__init__(k, self._semigroup,
prefix='',
element_class=self.Element,
#element_class=self.Element,
category=GradedAlgebrasWithBasis(k),
bracket=False)
self._assign_names(self._semigroup.variable_names())

def order_string(self):
return self._ordstr

@cached_method
def gens(self):
"""
Expand Down Expand Up @@ -184,7 +191,7 @@ def arrows(self):
sage: A.arrows()
(a, b, c)
"""
return tuple(self._from_dict( {index: self.base_ring().one()},
return tuple(self._from_dict( {index: self.base_ring().one(), 'order': self._ordstr},
remove_zeros=False )
for index in self._semigroup.arrows())

Expand All @@ -201,7 +208,7 @@ def idempotents(self):
sage: A.idempotents()
(e_1, e_2, e_3, e_4)
"""
return tuple(self._from_dict( {index: self.base_ring().one()},
return tuple(self._from_dict( {index: self.base_ring().one(), 'order': self._ordstr},
remove_zeros=False )
for index in self._semigroup.idempotents())

Expand All @@ -225,7 +232,7 @@ def gen(self, i):
sage: A.gen(5)
b
"""
return self._from_dict( {self._semigroup.gen(i): self.base_ring().one()},
return self._from_dict( {self._semigroup.gen(i): self.base_ring().one(), 'order':self._ordstr},
remove_zeros = False )

def ngens(self):
Expand All @@ -252,16 +259,16 @@ def _element_constructor_(self, x):
sage: B = DiGraph({1:{2:['a']}, 2:{3:['b']}}).path_semigroup().algebra(QQ)
sage: x = A('a') + 1 # indirect doctest
sage: x
a + e_1 + e_2
e_1 + a + e_2
sage: B(x) # indirect doctest
a + e_1 + e_2
e_1 + a + e_2
sage: A(1) # indirect doctest
e_1 + e_2
"""
from sage.quivers.paths import QuiverPath
# If it's an element of another path algebra, do a linear combination
# of the basis
if isinstance(x, CombinatorialFreeModuleElement) and isinstance(x.parent(), PathAlgebra):
if isinstance(x, PathAlgebraElement) and isinstance(x.parent(), PathAlgebra):
coeffs = x.monomial_coefficients()
result = self.zero()
for key in coeffs:
Expand Down Expand Up @@ -395,7 +402,7 @@ def _monomial(self, index):
ValueError: (1, 2, 'b') is not in list
"""
if index is not None:
return self._from_dict( {self._semigroup(index): self.base_ring().one()},
return self._from_dict( {self._semigroup(index): self.base_ring().one(), 'order': self._ordstr},
remove_zeros=False )
return self.zero()

Expand Down Expand Up @@ -445,6 +452,7 @@ def degree_on_basis(self, p):
"""
return len(self._semigroup(p))

@cached_method
def one(self):
"""
Return the multiplicative identity element.
Expand All @@ -458,8 +466,10 @@ def one(self):
sage: A.one()
e_1 + e_2 + e_3
"""
return self.sum_of_monomials([self._semigroup([(v, v)], check=False)
for v in self._quiver])
one = self.base_ring().one()
D = dict((index,one) for index in self._semigroup.idempotents())
D['order'] = self._ordstr
return self._from_dict( D )

###########################################################################
# #
Expand Down Expand Up @@ -575,7 +585,7 @@ def __iter__(self):
# #
###########################################################################

class Element(CombinatorialFreeModuleElement):
class BlaElement(CombinatorialFreeModuleElement):
def is_homogeneous(self):
"""
Return ``True`` if and only if this element is homogeneous.
Expand Down
6 changes: 4 additions & 2 deletions src/sage/quivers/algebra_elements.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ cdef class PathAlgebraElement(RingElement):
homog_poly_free(self.data)
def __init__(self, S, data, order="negdegrevlex"):
self._hash = -1
if 'order' in data:
order = data.pop('order')
if order=="negdegrevlex":
self.cmp_terms = negdegrevlex
elif order=="degrevlex":
Expand All @@ -42,7 +44,7 @@ cdef class PathAlgebraElement(RingElement):
RingElement.__init__(self, S)
cdef dict homog = {}
cdef list L
for tmp, c in data.monomial_coefficients().iteritems():
for tmp, c in data.iteritems():
homog.setdefault((tmp.initial_vertex(),tmp.terminal_vertex()),[]).append((tmp,c))
cdef path_homog_poly_t *HP
for (s,e),L in sorted(homog.iteritems(), reverse=True):
Expand Down Expand Up @@ -148,7 +150,7 @@ cdef class PathAlgebraElement(RingElement):
if deg == -1:
deg = T.mon.path.length
elif deg != T.mon.path.length:
raise ValueError("Element is not homogeneous")
raise ValueError("Element is not homogeneous.")
T = T.nxt
H = H.nxt
return deg
Expand Down

0 comments on commit 15ed81d

Please sign in to comment.