Skip to content

Commit 1c7bb41

Browse files
committed
convert between two implementations of fin-dim algebras
This provides functionality for converting between two implementations of finite-dimensional algebras: - the modern one, implemented as MagmaticAlgebras.WithBasis.FiniteDimensional in sage.categories.magmatic_algebras (in the magmatic case) and as FiniteDimensionalAlgebrasWithBasis in sage.categories.finite_dimensional_algebras_with_basis (in the assocative case), and - the old one, implemented as FiniteDimensionalAlgebra in sage.algebras.finite_dimensional_algebras.finite_dimensional_algebra. To be more precise, the latter now automatically inherits from the former if the optional parameters assume_associative and assume_unital are set to True, whereas the former can be converted into the latter via the to_finite_dimensional_algebra method. This way, the methods of one (e.g. ``center_basis`` on the modern one or ``is_unitary`` on the old one) can be used on the other. Fixing various other issues in both classes as well.
1 parent f8576cc commit 1c7bb41

6 files changed

+295
-31
lines changed

Diff for: src/sage/algebras/finite_dimensional_algebras/finite_dimensional_algebra.py

+83-5
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
# Distributed under the terms of the GNU General Public License (GPL)
1010
# as published by the Free Software Foundation; either version 2 of
1111
# the License, or (at your option) any later version.
12-
# http:s//www.gnu.org/licenses/
12+
# https://www.gnu.org/licenses/
1313
# ***************************************************************************
1414

1515
from .finite_dimensional_algebra_element import FiniteDimensionalAlgebraElement
@@ -18,6 +18,7 @@
1818
from sage.rings.integer_ring import ZZ
1919

2020
from sage.categories.magmatic_algebras import MagmaticAlgebras
21+
from sage.categories.algebras import Algebras
2122
from sage.matrix.constructor import matrix
2223
from sage.structure.element import Matrix
2324
from sage.structure.category_object import normalize_names
@@ -32,6 +33,9 @@ class FiniteDimensionalAlgebra(UniqueRepresentation, Parent):
3233
r"""
3334
Create a finite-dimensional `k`-algebra from a multiplication table.
3435
36+
This is a magmatic `k`-algebra, i.e., not necessarily
37+
associative or unital.
38+
3539
INPUT:
3640
3741
- ``k`` -- a field
@@ -45,6 +49,10 @@ class FiniteDimensionalAlgebra(UniqueRepresentation, Parent):
4549
``True``, then the category is set to ``category.Associative()``
4650
and methods requiring associativity assume this
4751
52+
- ``assume_unital`` -- boolean (default: ``False``); if
53+
``True``, then the category is set to ``category.Unital()``
54+
and methods requiring unitality assume this
55+
4856
- ``category`` -- (default:
4957
``MagmaticAlgebras(k).FiniteDimensional().WithBasis()``)
5058
the category to which this algebra belongs
@@ -67,6 +75,49 @@ class FiniteDimensionalAlgebra(UniqueRepresentation, Parent):
6775
....: Matrix([[0,0,0], [0,0,0], [0,0,1]])])
6876
sage: B
6977
Finite-dimensional algebra of degree 3 over Rational Field
78+
sage: B.one()
79+
e0 + e2
80+
sage: B.is_associative()
81+
True
82+
83+
A more complicated example (the 3-rd descent algebra in
84+
a slightly rescaled I-basis, see :class:`DescentAlgebra`)::
85+
86+
sage: Ma = Matrix([[6,0,0,0], [0,0,0,0], [0,0,0,0], [0,0,0,0]])
87+
sage: Mb = Matrix([[0,0,0,0], [0,1,0,0], [0,1,0,0], [0,0,0,0]])
88+
sage: Mc = Matrix([[0,0,0,0], [0,0,1,0], [0,0,1,0], [0,0,0,0]])
89+
sage: Md = Matrix([[0,0,0,0], [0,1,-1,0], [0,-1,1,0], [0,0,0,2]])
90+
sage: C = FiniteDimensionalAlgebra(QQ, [Ma, Mb, Mc, Md])
91+
sage: C.one()
92+
1/6*e0 + 1/2*e1 + 1/2*e2 + 1/2*e3
93+
sage: C.is_associative()
94+
True
95+
sage: C.is_commutative()
96+
False
97+
98+
If we set both ``is_associative`` and ``is_unital`` to
99+
``True``, then this is an associative unital algebra and
100+
belongs to the category of
101+
:class:`sage.categories.finite_dimensional_algebras_with_basis.FiniteDimensionalAlgebrasWithBasis`::
102+
103+
sage: C = FiniteDimensionalAlgebra(QQ, [Ma, Mb, Mc, Md],
104+
....: assume_associative=True,
105+
....: assume_unital=True)
106+
sage: C.radical_basis()
107+
(e1 - e2,)
108+
sage: C.radical()
109+
Radical of Finite-dimensional algebra of degree 4 over Rational Field
110+
sage: C.center_basis()
111+
(e0, e1 + e2 + e3)
112+
sage: C.center()
113+
Center of Finite-dimensional algebra of degree 4 over Rational Field
114+
sage: C.center().is_commutative()
115+
True
116+
sage: e = C.basis()
117+
sage: C.annihilator_basis([e[1]])
118+
(e0, e1 - e2, e3)
119+
sage: C.annihilator_basis([e[1]], side='left')
120+
(e0, e1 - e2 - e3)
70121
71122
TESTS::
72123
@@ -82,7 +133,7 @@ class FiniteDimensionalAlgebra(UniqueRepresentation, Parent):
82133
"""
83134
@staticmethod
84135
def __classcall_private__(cls, k, table, names='e', assume_associative=False,
85-
category=None):
136+
assume_unital=False, category=None):
86137
"""
87138
Normalize input.
88139
@@ -105,6 +156,26 @@ def __classcall_private__(cls, k, table, names='e', assume_associative=False,
105156
sage: A1 is A2
106157
True
107158
159+
Likewise for the ``assume_associative`` keyword::
160+
161+
sage: A3 = FiniteDimensionalAlgebra(GF(3), table,
162+
....: category=cat.Unital())
163+
sage: A4 = FiniteDimensionalAlgebra(GF(3), table, assume_unital=True)
164+
sage: A3 is A4
165+
True
166+
167+
With both keywords on, the
168+
:class:`sage.categories.algebras.Algebras` category
169+
is used::
170+
171+
sage: cat_a = Algebras(GF(3)).FiniteDimensional().WithBasis()
172+
sage: A5 = FiniteDimensionalAlgebra(GF(3), table,
173+
....: category=cat_a)
174+
sage: A6 = FiniteDimensionalAlgebra(GF(3), table, assume_associative=True,
175+
....: assume_unital=True)
176+
sage: A5 is A6
177+
True
178+
108179
Uniqueness depends on the category::
109180
110181
sage: cat = Algebras(GF(3)).FiniteDimensional().WithBasis()
@@ -144,6 +215,12 @@ def __classcall_private__(cls, k, table, names='e', assume_associative=False,
144215
cat = cat.or_subcategory(category)
145216
if assume_associative:
146217
cat = cat.Associative()
218+
if assume_unital:
219+
# both unital and associative, so algebra in modern sense
220+
cat = Algebras(k).FiniteDimensional().WithBasis()
221+
cat = cat.or_subcategory(category)
222+
elif assume_unital:
223+
cat = cat.Unital()
147224

148225
names = normalize_names(n, names)
149226

@@ -610,10 +687,10 @@ def is_unitary(self):
610687
v = matrix(k, 1, n**2, (n - 1) * ([kone] + n * [kzero]) + [kone])
611688
try:
612689
sol1 = B1.solve_left(v)
613-
sol2 = B2.solve_left(v)
614690
except ValueError:
615691
return False
616-
assert sol1 == sol2
692+
if sol1 * B2 != v:
693+
return False
617694
self._one = sol1
618695
return True
619696

@@ -931,7 +1008,8 @@ def maximal_ideals(self):
9311008
"""
9321009
Return a list consisting of all maximal ideals of ``self``.
9331010
934-
The algebra ``self`` has to be in the category of associative algebras.
1011+
The algebra ``self`` has to be in the category of
1012+
commutative, associative algebras.
9351013
9361014
EXAMPLES::
9371015

Diff for: src/sage/algebras/finite_dimensional_algebras/finite_dimensional_algebra_element.pyx

+25
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,26 @@ cdef class FiniteDimensionalAlgebraElement(AlgebraElement):
334334
from sage.misc.latex import latex
335335
return latex(self.matrix())
336336

337+
def __hash__(self):
338+
"""
339+
Return the hash value for ``self``.
340+
341+
The result is cached.
342+
(TODO: Not sure why, but caching does not work.)
343+
344+
EXAMPLES::
345+
346+
sage: A = FiniteDimensionalAlgebra(GF(3), [Matrix([[1,0], [0,1]]),
347+
....: Matrix([[0,1], [0,0]])])
348+
sage: a = A([1,2])
349+
sage: b = A([2,3])
350+
sage: hash(a) == hash(A([1,2]))
351+
True
352+
sage: hash(a) == hash(b)
353+
False
354+
"""
355+
return hash(tuple(self._vector.list()))
356+
337357
def __getitem__(self, m):
338358
"""
339359
Return the `m`-th coefficient of ``self``.
@@ -350,13 +370,18 @@ cdef class FiniteDimensionalAlgebraElement(AlgebraElement):
350370

351371
def __len__(self):
352372
"""
373+
Return the number of coefficients of ``self``,
374+
including the zero coefficients.
375+
353376
EXAMPLES::
354377
355378
sage: A = FiniteDimensionalAlgebra(QQ, [Matrix([[1,0,0], [0,1,0], [0,0,0]]),
356379
....: Matrix([[0,1,0], [0,0,0], [0,0,0]]),
357380
....: Matrix([[0,0,0], [0,0,0], [0,0,1]])])
358381
sage: len(A([2,1/4,3]))
359382
3
383+
sage: len(A([2,0,3/4]))
384+
3
360385
"""
361386
return self._vector.ncols()
362387

0 commit comments

Comments
 (0)