sagemath / sage

Main repository of SageMath. Now open for Issues and Pull Requests.
https://www.sagemath.org
Other
1.21k stars 421 forks source link

(nondeterministic) AttributeError exception in tensor product of algebras #24822

Open fe60a72e-b3d0-4317-856b-4536ec0e4b8d opened 6 years ago

fe60a72e-b3d0-4317-856b-4536ec0e4b8d commented 6 years ago

The following code

set_random_seed(2)
L = lie_algebras.sl(QQ, 2)
U = L.universal_enveloping_algebra()
PBW = L.pbw_basis()
E, F, H = PBW.algebra_generators()
Q = QuadraticForm(QQ, 2, [1,0,1])
C = CliffordAlgebra(Q)
e, f = C.algebra_generators()
UC = PBW.tensor(C)
x = UC.algebra_generators()[(E, e)]
UC.algebra_generators()[E*F - F*E, (1, 1)]

usually works but sometimes fires AttributeError exception. Or sometimes it runs fine, but when you try the tensor product with the algebras swapped it throws the exception. E.g.

CU = C.tensor(PBW)

produced

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-2-fec37a9bf7f3> in <module>()
----> 1 CU = C.tensor(PBW)

/home/vit/bin/sage-dev/local/lib/python2.7/site-packages/sage/categories/modules_with_basis.pyc in tensor(*parents)
    831                 sage: A.rename(None)
    832             """
--> 833             return parents[0].__class__.Tensor(parents, category = tensor.category_from_parents(parents))
    834 
    835         def cardinality(self):

/home/vit/bin/sage-dev/local/lib/python2.7/site-packages/sage/categories/covariant_functorial_construction.pyc in category_from_parents(self, parents)
    146         # category of the result does not depend on the order/repetition
    147         # of the categories of the parents
--> 148         return self.category_from_categories(tuple(set(parent.category() for parent in parents)))
    149 
    150     @cached_method

/home/vit/bin/sage-dev/local/lib/python2.7/site-packages/sage/misc/cachefunc.pyx in sage.misc.cachefunc.CachedMethodCaller.__call__ (build/cythonized/sage/misc/cachefunc.c:10785)()
   2012                 return cache[k]
   2013         except KeyError:
-> 2014             w = self._instance_call(*args, **kwds)
   2015             cache[k] = w
   2016             return w

/home/vit/bin/sage-dev/local/lib/python2.7/site-packages/sage/misc/cachefunc.pyx in sage.misc.cachefunc.CachedMethodCaller._instance_call (build/cythonized/sage/misc/cachefunc.c:10236)()
   1888             True
   1889         """
-> 1890         return self.f(self._instance, *args, **kwds)
   1891 
   1892     cdef fix_args_kwds(self, tuple args, dict kwds):

/home/vit/bin/sage-dev/local/lib/python2.7/site-packages/sage/categories/covariant_functorial_construction.pyc in category_from_categories(self, categories)
    172         """
    173         assert(len(categories) > 0)
--> 174         return self.category_from_category(Category.meet(categories))
    175 
    176     def category_from_category(self, category):

/home/vit/bin/sage-dev/local/lib/python2.7/site-packages/sage/categories/covariant_functorial_construction.pyc in category_from_category(self, category)
    191         # TODO: add support for parametrized functors
    192         """
--> 193         return getattr(category, self._functor_category)()
    194 
    195     def _repr_(self):

AttributeError: 'Rings_with_category' object has no attribute 'TensorProducts'

Well, at least that was the situation yesterday. Today it seems that PBW.tensor(C) always works and C.tensor(PBW) always doesn't. No... wait a minute. Nope. Now both tensor products work. So it is still nondeterministic. :-(

Tested on Sage-8.2beta6

CC: @nthiery @tscrim @darijgr

Component: categories

Keywords: tensor, algebras

Issue created by migration from https://trac.sagemath.org/ticket/24822

darijgr commented 6 years ago
comment:2

Confirmed with

L = lie_algebras.sl(QQ, 2)
U = L.universal_enveloping_algebra()
PBW = L.pbw_basis()
E, F, H = PBW.algebra_generators()
Q = QuadraticForm(QQ, 2, [1,0,1])
C = CliffordAlgebra(Q)
e, f = C.algebra_generators()
UC = PBW.tensor(C)
C.tensor(PBW)

HOWEVER, I'm not sure if this is a bug! C is a superalgebra whereas PBW is an algebra. Per se, I wouldn't expect Sage to know how to tensor them. I suspect we need to teach it. Or maybe even create a functorial construction that turns a superalgebra into an algebra and vice versa?

tscrim commented 6 years ago
comment:3

FTR, I have confirmed this as well.

No, the category framework should be able to work this out as a superalgebra is an algebra under the forgetful functor (i.e., Algebras(QQ) appears in all_super_categories() of Algebras(QQ).Super()). It definitely should not result in the error above. It is also very strange that it is a heisenbug.

darijgr commented 6 years ago
comment:4

A superalgebra is an algebra, but an algebra is also a superalgebra. So there is a tensor product in either category. And they're different! The one in Algebras has forgotten the super-structure from the super-tensorand. How do we decide which to use?

tscrim commented 6 years ago
comment:5

IIRC, Sage takes the safest route by taking the meet category, which in this case should be Algebras(QQ) since we essentially say an algebra is not a superalgebra (in the same way we do not say a ring is a ZZ-algebra).