Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Unexpected error with sign() function in SageMath

I have the following rather strange issue with SageMath. More specifically the problem seem to be related with SageMath libraries dealing with permutations and Lie algebras. Here is the part of the code which does not compile properly for some reason:

gl = lie_algebras.gl(QQ, 4)
Ugl = gl.pbw_basis()
E = matrix(Ugl, 4, 4, Ugl.gens())

for sigma in Permutations(4):
    for tau in Permutations(4):
        pr = sigma.signature() * tau.signature()
    for i in range(4):
        pr = pr * E[sigma[i] - 1, tau[i] - 1]

The interesting thing is that while the code above does not work well, the issue could be resolved just by adding 1 *, see below:

gl = lie_algebras.gl(QQ, 4)
Ugl = gl.pbw_basis()
E = matrix(Ugl, 4, 4, Ugl.gens())

for sigma in Permutations(4):
    for tau in Permutations(4):
        pr = sigma.signature() * tau.signature()
    for i in range(4):
        pr = 1 * pr * E[sigma[i] - 1, tau[i] - 1]

My experiments show that there is some issue with SageMath function signature() since if I replace the line pr = sigma.signature() * tau.signature() with pr = 1, then both versions compile successfully. The final block of the error message for the first excerpt is as follows:

/usr/lib/python3/dist-packages/sage/algebras/lie_algebras/poincare_birkhoff_witt.py in _act_on_(self, x, self_on_left)
    513             # Try the _acted_upon_ first as it might have a direct PBW action
    514             #   implemented that is faster
--> 515             ret = x._acted_upon_(self, not self_on_left)
    516             if ret is not None:
    517                 return ret

AttributeError: 'int' object has no attribute '_acted_upon_'

Therefore, it might be the case that there is something strange happening with the action of integers on element of Lie algebras (some type-related issue?).

Of course, since the second version works I can proceed, but it looks weird and I would be really interested in understanding the source of this error (to avoid similar ones in the future).

Comment. I did no realize at first that for SageMath there is a special Q&A forum, so initially I posted it on SE.