- # We have to pass through vectors to convert from the
- # given entry algebra to ours. Otherwise we can fail
- # to convert an element of (for example) Octonions(QQ)
- # to Octonions(AA).
- return self.entry_algebra().from_vector(e_ij.to_vector())
+ if e_ij in self.entry_algebra():
+ # Don't re-create an element if it already lives where
+ # it should!
+ return e_ij
+
+ try:
+ # This branch works with e.g. QQbar, where no
+ # to/from_vector() methods are available.
+ return self.entry_algebra()(e_ij)
+ except TypeError:
+ # We have to pass through vectors to convert from the
+ # given entry algebra to ours. Otherwise we can fail to
+ # convert an element of (for example) Octonions(QQ) to
+ # Octonions(AA).
+ return self.entry_algebra().from_vector(e_ij.to_vector())