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

Commit

Permalink
trac #27937. fix functorial construction of monoid algebras
Browse files Browse the repository at this point in the history
  • Loading branch information
mwageringel committed Jun 11, 2019
1 parent 9b91a09 commit 5b97d03
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 11 deletions.
24 changes: 21 additions & 3 deletions src/sage/categories/sets_cat.py
Original file line number Diff line number Diff line change
Expand Up @@ -2470,11 +2470,29 @@ def construction(self):
EXAMPLES::
sage: A = GroupAlgebra(KleinFourGroup(), QQ)
sage: A.construction()
sage: F, arg = A.construction(); F, arg
(GroupAlgebraFunctor, Rational Field)
sage: F(arg) is A
True
This also works for structures such as monoid algebras (see
:trac:`27937`)::
sage: A = FreeAbelianMonoid('x,y').algebra(QQ)
sage: F, arg = A.construction(); F, arg
(The algebra functorial construction,
Free abelian monoid on 2 generators (x, y))
sage: F(arg) is A
True
"""
from sage.categories.algebra_functor import GroupAlgebraFunctor
return GroupAlgebraFunctor(self.group()), self.base_ring()
from sage.categories.algebra_functor import (
GroupAlgebraFunctor, AlgebraFunctor)
try:
group = self.group()
except AttributeError:
return (AlgebraFunctor(self.base_ring()),
self.basis().keys())
return GroupAlgebraFunctor(group), self.base_ring()

def _repr_(self):
r"""
Expand Down
20 changes: 12 additions & 8 deletions src/sage/matrix/matrix2.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -2426,6 +2426,12 @@ cdef class Matrix(Matrix1):
sage: A._charpoly_df()
x - 23

Test that :trac:`27937` is fixed::

sage: R = FreeAbelianMonoid('u,v').algebra(QQ)
sage: matrix(4, 4, lambda i, j: R.an_element())._charpoly_df()
B[1]*x^4 - 4*B[u]*x^3

.. NOTE::

The key feature of this implementation is that it is division-free.
Expand Down Expand Up @@ -2457,7 +2463,7 @@ cdef class Matrix(Matrix1):
# test for 0 x n or m x 0 matrices.
#
if n == 0:
return S(1)
return S.one()

# In the notation of Algorithm 3.1,
#
Expand All @@ -2474,9 +2480,9 @@ cdef class Matrix(Matrix1):
#
from sage.matrix.constructor import matrix

F = [R(0) for i in xrange(n)]
F = [R.zero()] * n
cdef Matrix a = <Matrix> matrix(R, n-1, n)
A = [R(0) for i in xrange(n)]
A = [R.zero()] * n

F[0] = - M.get_unsafe(0, 0)
for t in xrange(1,n):
Expand All @@ -2495,7 +2501,7 @@ cdef class Matrix(Matrix1):
# Set a(p, t) to the product of M[<=t, <=t] * a(p-1, t)
#
for i in xrange(t+1):
s = R(0)
s = R.zero()
for j in xrange(t+1):
s = s + M.get_unsafe(i, j) * a.get_unsafe(p-1, j)
a.set_unsafe(p, i, s)
Expand All @@ -2506,7 +2512,7 @@ cdef class Matrix(Matrix1):

# Set A[t, t] to be M[t, <=t] * a(p-1, t)
#
s = R(0)
s = R.zero()
for j in xrange(t+1):
s = s + M.get_unsafe(t, j) * a.get_unsafe(t-1, j)
A[t] = s
Expand All @@ -2518,9 +2524,7 @@ cdef class Matrix(Matrix1):
F[p] = s - A[p]

X = S.gen(0)
f = X ** n
for p in xrange(n):
f = f + F[p] * X ** (n-1-p)
f = X ** n + S(list(reversed(F)))

return f

Expand Down

0 comments on commit 5b97d03

Please sign in to comment.