Skip to content

Commit d01b249

Browse files
committed
move methods to category of algebras
1 parent 33505aa commit d01b249

File tree

2 files changed

+78
-80
lines changed

2 files changed

+78
-80
lines changed

src/sage/categories/algebras.py

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,84 @@ def Supercommutative(self):
144144
Semisimple = LazyImport('sage.categories.semisimple_algebras',
145145
'SemisimpleAlgebras')
146146

147+
class ParentMethods:
148+
def characteristic(self):
149+
r"""
150+
Return the characteristic of this algebra, which is the same
151+
as the characteristic of its base ring.
152+
153+
EXAMPLES::
154+
155+
sage: # needs sage.modules
156+
sage: ZZ.characteristic()
157+
0
158+
sage: A = GF(7^3, 'a') # needs sage.rings.finite_rings
159+
sage: A.characteristic() # needs sage.rings.finite_rings
160+
7
161+
"""
162+
return self.base_ring().characteristic()
163+
164+
def has_standard_involution(self):
165+
r"""
166+
Return ``True`` if the algebra has a standard involution and ``False`` otherwise.
167+
168+
This algorithm follows Algorithm 2.10 from John Voight's *Identifying the Matrix Ring*.
169+
Currently the only type of algebra this will work for is a quaternion algebra.
170+
Though this function seems redundant, once algebras have more functionality, in particular
171+
have a method to construct a basis, this algorithm will have more general purpose.
172+
173+
EXAMPLES::
174+
175+
sage: # needs sage.combinat sage.modules
176+
sage: B = QuaternionAlgebra(2)
177+
sage: B.has_standard_involution()
178+
True
179+
sage: R.<x> = PolynomialRing(QQ)
180+
sage: K.<u> = NumberField(x**2 - 2) # needs sage.rings.number_field
181+
sage: A = QuaternionAlgebra(K, -2, 5) # needs sage.rings.number_field
182+
sage: A.has_standard_involution() # needs sage.rings.number_field
183+
True
184+
sage: L.<a,b> = FreeAlgebra(QQ, 2)
185+
sage: L.has_standard_involution()
186+
Traceback (most recent call last):
187+
...
188+
NotImplementedError: has_standard_involution is not implemented for this algebra
189+
"""
190+
field = self.base_ring()
191+
try:
192+
basis = self.basis()
193+
except AttributeError:
194+
raise AttributeError("Basis is not yet implemented for this algebra.")
195+
try:
196+
# TODO: The following code is specific to the quaternion algebra
197+
# and should belong there
198+
# step 1
199+
for i in range(1, 4):
200+
ei = basis[i]
201+
a = ei**2
202+
coef = a.coefficient_tuple()
203+
ti = coef[i]
204+
ni = a - ti * ei
205+
if ni not in field:
206+
return False
207+
# step 2
208+
for i in range(1, 4):
209+
for j in range(2, 4):
210+
ei = basis[i]
211+
ej = basis[j]
212+
a = ei**2
213+
coef = a.coefficient_tuple()
214+
ti = coef[i]
215+
b = ej**2
216+
coef = b.coefficient_tuple()
217+
tj = coef[j]
218+
nij = (ei + ej)**2 - (ti + tj) * (ei + ej)
219+
if nij not in field:
220+
return False
221+
except AttributeError:
222+
raise NotImplementedError("has_standard_involution is not implemented for this algebra")
223+
return True
224+
147225
class ElementMethods:
148226
# TODO: move the content of AlgebraElement here or higher in the category hierarchy
149227
def _div_(self, y):

src/sage/rings/ring.pyx

Lines changed: 0 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -2274,86 +2274,6 @@ cdef class Algebra(Ring):
22742274
Ring.__init__(self,base_ring, names=names, normalize=normalize,
22752275
category=category)
22762276

2277-
def characteristic(self):
2278-
r"""
2279-
Return the characteristic of this algebra, which is the same
2280-
as the characteristic of its base ring.
2281-
2282-
See objects with the ``base_ring`` attribute for additional examples.
2283-
Here are some examples that explicitly use the :class:`Algebra` class.
2284-
2285-
EXAMPLES::
2286-
2287-
sage: # needs sage.modules
2288-
sage: A = Algebra(ZZ); A
2289-
<sage.rings.ring.Algebra object at ...>
2290-
sage: A.characteristic()
2291-
0
2292-
sage: A = Algebra(GF(7^3, 'a')) # needs sage.rings.finite_rings
2293-
sage: A.characteristic() # needs sage.rings.finite_rings
2294-
7
2295-
"""
2296-
return self.base_ring().characteristic()
2297-
2298-
def has_standard_involution(self):
2299-
r"""
2300-
Return ``True`` if the algebra has a standard involution and ``False`` otherwise.
2301-
This algorithm follows Algorithm 2.10 from John Voight's *Identifying the Matrix Ring*.
2302-
Currently the only type of algebra this will work for is a quaternion algebra.
2303-
Though this function seems redundant, once algebras have more functionality, in particular
2304-
have a method to construct a basis, this algorithm will have more general purpose.
2305-
2306-
EXAMPLES::
2307-
2308-
sage: # needs sage.combinat sage.modules
2309-
sage: B = QuaternionAlgebra(2)
2310-
sage: B.has_standard_involution()
2311-
True
2312-
sage: R.<x> = PolynomialRing(QQ)
2313-
sage: K.<u> = NumberField(x**2 - 2) # needs sage.rings.number_field
2314-
sage: A = QuaternionAlgebra(K, -2, 5) # needs sage.rings.number_field
2315-
sage: A.has_standard_involution() # needs sage.rings.number_field
2316-
True
2317-
sage: L.<a,b> = FreeAlgebra(QQ, 2)
2318-
sage: L.has_standard_involution()
2319-
Traceback (most recent call last):
2320-
...
2321-
NotImplementedError: has_standard_involution is not implemented for this algebra
2322-
"""
2323-
field = self.base_ring()
2324-
try:
2325-
basis = self.basis()
2326-
except AttributeError:
2327-
raise AttributeError("Basis is not yet implemented for this algebra.")
2328-
try:
2329-
# TODO: The following code is specific to the quaternion algebra
2330-
# and should belong there
2331-
#step 1
2332-
for i in range(1,4):
2333-
ei = basis[i]
2334-
a = ei**2
2335-
coef = a.coefficient_tuple()
2336-
ti = coef[i]
2337-
ni = a - ti*ei
2338-
if ni not in field:
2339-
return False
2340-
#step 2
2341-
for i in range(1,4):
2342-
for j in range(2,4):
2343-
ei = basis[i]
2344-
ej = basis[j]
2345-
a = ei**2
2346-
coef = a.coefficient_tuple()
2347-
ti = coef[i]
2348-
b = ej**2
2349-
coef = b.coefficient_tuple()
2350-
tj = coef[j]
2351-
nij = (ei + ej)**2 - (ti + tj)*(ei + ej)
2352-
if nij not in field:
2353-
return False
2354-
except AttributeError:
2355-
raise NotImplementedError("has_standard_involution is not implemented for this algebra")
2356-
return True
23572277

23582278
cdef class CommutativeAlgebra(CommutativeRing):
23592279
"""

0 commit comments

Comments
 (0)