Skip to content
Open
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions src/sage/algebras/lie_algebras/lie_algebra.py
Original file line number Diff line number Diff line change
Expand Up @@ -1240,9 +1240,34 @@ def _element_constructor_(self, x):
-[1, 3, 2] + [3, 2, 1]
sage: L(2)
2*[1, 2, 3]

Test that constructing elements from vectors works correctly
(this used to cause infinite recursion)::

sage: gl = lie_algebras.gl(QQ, 2)
sage: v = gl.an_element().to_vector()
sage: gl(v) == gl.an_element()
True

Test that morphisms can be constructed (this used to fail with
RecursionError)::
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could use :exc:`RecursionError` here to create a link in the docs

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But it seems this part about this function not appear in the document


sage: gl = lie_algebras.gl(QQ, 2)
sage: phi = gl.morphism({e: e for e in gl.gens()})
sage: all(phi(e) == e for e in gl.gens())
True
"""
if isinstance(x, list) and len(x) == 2:
return self(x[0])._bracket_(self(x[1]))

# Check if x is a vector from the module to avoid infinite recursion
# when constructing elements from vectors (e.g., in morphism construction)
try:
if hasattr(x, 'parent') and x.parent() == self.module():
return self.from_vector(x)
except (AttributeError, NotImplementedError):
pass

return self.element_class(self, self._assoc(x))

def associative_algebra(self):
Expand Down
Loading