]> gitweb.michael.orlitzky.com - sage.d.git/commitdiff
eja: add inverse() method for operators.
authorMichael Orlitzky <michael@orlitzky.com>
Thu, 10 Oct 2019 13:24:17 +0000 (09:24 -0400)
committerMichael Orlitzky <michael@orlitzky.com>
Thu, 10 Oct 2019 13:24:17 +0000 (09:24 -0400)
mjo/eja/eja_operator.py

index 781d987518af32043ef11ccbb1533f9ad4f3b6ef..41d68560524e9394a97dc6ff3ecbaf19e27cd06a 100644 (file)
@@ -383,6 +383,56 @@ class FiniteDimensionalEuclideanJordanAlgebraOperator(Map):
         return (self + (-other))
 
 
+    def inverse(self):
+        """
+        Return the inverse of this operator, if it exists.
+
+        The reason this method is not simply an alias for the built-in
+        :meth:`__invert__` is that the built-in inversion is a bit magic
+        since it's intended to be a unary operator. If we alias ``inverse``
+        to ``__invert__``, then we wind up having to call e.g. ``A.inverse``
+        without parentheses.
+
+        SETUP::
+
+            sage: from mjo.eja.eja_algebra import RealSymmetricEJA, random_eja
+
+        EXAMPLES::
+
+            sage: J = RealSymmetricEJA(2)
+            sage: x = sum(J.gens())
+            sage: x.operator().inverse().matrix()
+            [3/2  -1 1/2]
+            [ -1   2  -1]
+            [1/2  -1 3/2]
+            sage: x.operator().matrix().inverse()
+            [3/2  -1 1/2]
+            [ -1   2  -1]
+            [1/2  -1 3/2]
+
+        TESTS:
+
+        The identity operator is its own inverse::
+
+            sage: set_random_seed()
+            sage: J = random_eja()
+            sage: idJ = J.one().operator()
+            sage: idJ.inverse() == idJ
+            True
+
+        The zero operator is never invertible::
+
+            sage: set_random_seed()
+            sage: J = random_eja()
+            sage: J.zero().operator().inverse()
+            Traceback (most recent call last):
+            ...
+            ZeroDivisionError: input matrix must be nonsingular
+
+        """
+        return ~self
+
+
     def is_invertible(self):
         """
         Return whether or not this operator is invertible.