Lie algebra approach:
sage: d = {('J0', 'J1'): {'J2': 1}, ('J0', 'J2'): {'J1': -1}, ('J1', 'J2'): {'J0': 2}}
sage: F.<J0, J1, J2> = LieAlgebra(QQ, d)
sage: F
Lie algebra on 3 generators (J0, J1, J2) over Rational Field
sage: F.bracket(J0, J1)
J2
sage: F.bracket(J0, F.bracket(J0, J1))
-J1
sage: F.bracket(J0, F.bracket(J0, J1)) + F.bracket(F.bracket(J1, J2), J1)
-J1 + 2*J2
Flawed approach below; feel free to ignore (or work on Sage to improve things!).
The following naïve approach doesn't seem to work well in Sage:
sage: F.<J0,J1,J2> = FreeAlgebra(QQ)
sage: def comm(x,y): return x*y-y*x
sage: I = F.ideal(comm(J0, J1) - J2, comm(J0, J2) + J1, comm(J1, J2) - 2*J0)
sage: A = F.quotient(I)
sage: comm(J0, comm(J0, J1)) + comm(comm(J1, J2), J1)
J0^2*J1 - 2*J0*J1*J0 + J1*J0^2 - J1^2*J2 + 2*J1*J2*J1 - J2*J1^2
sage: A(comm(J0, comm(J0, J1)) + comm(comm(J1, J2), J1))
J0bar^2*J1bar - 2*J0bar*J1bar*J0bar + J1bar*J0bar^2 - J1bar^2*J2bar + 2*J1bar*J2bar*J1bar - J2bar*J1bar^2
This is clearly flawed. It can't even tell that the generators of the ideal are sent to zero in the quotient:
sage: [A(x)==0 for x in I.gens()]
[False, False, False]
Another approach would be to construct the algebra from scratch. You should be able to describe a vector space basis for it, so you can then construct it using CombinatorialFreeModule, the way Clifford algebras (among many other examples) are constructed in Sage.
Searching the source code for 'Casimir' comes up almost empty.
Thank you! I was expecting that as it is not a straightforward calculation.
Maybe I am pushing my luck but can we define calculations like
$[J1,J0J2]=[J1,J0]J2+J0[J1,J2]$
?
You could define
Fas in my answer and then useA = F.enveloping_algebra(), and take a quotient ofAbyA.ideal( <your relation> , side='twosided').Thank you, I changed
.enveloping_algebra()to.universal_enveloping_algebra()as in the followingand it worked. However, if I change QQ to CC or SR, this yields the error "AttributeError: 'LieAlgebraWithStructureCoefficients_with_category' object has no attribute 'lift'". I may need to use imaginary numbers or symbolic variables in the future.