I asked the following question on ask.sagemath : https://ask.sagemath.org/question/49897/acess-bracked-elements-in-free-lie-algebra-element/ and I'll copy it here.
I'm trying to access the left and right elements in a free lie algebra element, whose monomials are stored as binary trees. Thus I want a method (like exists in the source for lie_algebra_element) which would return something like sage: L = LieAlgebra(QQ, 3, 'x') sage: x0,x1,x2 = L.gens() sage: Lyn = FL.Lyndon() sage: a = Lyn.graded_basis(3)[2]; a [[x0, x1], x1] sage: a._left [x0,x1] sage: a._right x1 Of course the last 4 lines are fake. One way of seeing this is the following: sage: isinstance(a, LyndonBracket) False sage: isinstance(a, LieBracket) False How do I fix this "the right way" ? My current solution is just to set sage: a_tree = eval(repr(a)); a_tree [[x0, x1], x1] But this feels extremely wrong. The response suggested to do the following: sage: a_tree = a.list()[0][0]; a_tree[[x0, x1], x1] sage: isinstance(a_tree, sage.algebras.lie_algebras.lie_algebra_element.LyndonBracket)True sage: a_tree._left[x0, x1] sage: a_tree._right x1 But this has its own issues: sage: x1 == a_tree._right False Because x1 is an element of the free Lie algbera but a_tree._right is just some LieGenerator. The responder also suggested I post here. Perhaps there's a better way to represent elements of the free lie algebra so that the brackets are accessible (say if you ever want to expand something using the Jacobi identity, which I do) in a reasonable manner? -- You received this message because you are subscribed to the Google Groups "sage-devel" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-devel+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/sage-devel/f9ef9522-e59c-45bb-82f7-8930cbdecfb9%40googlegroups.com.