]> gitweb.michael.orlitzky.com - sage.d.git/commitdiff
eja: fix construction of subalgebra elements from superalgebra ones.
authorMichael Orlitzky <michael@orlitzky.com>
Fri, 2 Aug 2019 20:22:04 +0000 (16:22 -0400)
committerMichael Orlitzky <michael@orlitzky.com>
Fri, 2 Aug 2019 20:22:04 +0000 (16:22 -0400)
mjo/eja/eja_subalgebra.py

index 7971e15a095a9a5e4a246bc89fbdf90cb5e97d94..5e782cf4a69b13d0d6c2e36beb5b190d81ddb3b4 100644 (file)
@@ -24,39 +24,6 @@ class FiniteDimensionalEuclideanJordanElementSubalgebraElement(FiniteDimensional
         True
 
     """
-    def __init__(self, A, elt):
-        """
-        SETUP::
-
-            sage: from mjo.eja.eja_algebra import RealSymmetricEJA
-            sage: from mjo.eja.eja_subalgebra import FiniteDimensionalEuclideanJordanElementSubalgebra
-
-        EXAMPLES::
-
-            sage: J = RealSymmetricEJA(3)
-            sage: x = sum( i*J.gens()[i] for i in range(6) )
-            sage: K = FiniteDimensionalEuclideanJordanElementSubalgebra(x)
-            sage: [ K.element_class(K,x^k) for k in range(J.rank()) ]
-            [f0, f1, f2]
-
-        ::
-
-        """
-        if elt in A.superalgebra():
-            # Try to convert a parent algebra element into a
-            # subalgebra element...
-            try:
-                coords = A.vector_space().coordinate_vector(elt.to_vector())
-                elt = A.from_vector(coords).monomial_coefficients()
-            except AttributeError:
-                # Catches a missing method in elt.to_vector()
-                pass
-
-        s = super(FiniteDimensionalEuclideanJordanElementSubalgebraElement,
-                  self)
-
-        s.__init__(A, elt)
-
 
     def superalgebra_element(self):
         """
@@ -75,9 +42,9 @@ class FiniteDimensionalEuclideanJordanElementSubalgebraElement(FiniteDimensional
             sage: x
             e0 + e1 + e2 + e3 + e4 + e5
             sage: A = x.subalgebra_generated_by()
-            sage: A.element_class(A,x)
+            sage: A(x)
             f1
-            sage: A.element_class(A,x).superalgebra_element()
+            sage: A(x).superalgebra_element()
             e0 + e1 + e2 + e3 + e4 + e5
 
         TESTS:
@@ -88,10 +55,10 @@ class FiniteDimensionalEuclideanJordanElementSubalgebraElement(FiniteDimensional
             sage: J = random_eja()
             sage: x = J.random_element()
             sage: A = x.subalgebra_generated_by()
-            sage: A.element_class(A,x).superalgebra_element() == x
+            sage: A(x).superalgebra_element() == x
             True
             sage: y = A.random_element()
-            sage: A.element_class(A,y.superalgebra_element()) == y
+            sage: A(y.superalgebra_element()) == y
             True
 
         """
@@ -184,6 +151,32 @@ class FiniteDimensionalEuclideanJordanElementSubalgebra(FiniteDimensionalEuclide
                               natural_basis=natural_basis)
 
 
+    def _element_constructor_(self, elt):
+        """
+        Construct an element of this subalgebra from the given one.
+        The only valid arguments are elements of the parent algebra
+        that happen to live in this subalgebra.
+
+        SETUP::
+
+            sage: from mjo.eja.eja_algebra import RealSymmetricEJA
+            sage: from mjo.eja.eja_subalgebra import FiniteDimensionalEuclideanJordanElementSubalgebra
+
+        EXAMPLES::
+
+            sage: J = RealSymmetricEJA(3)
+            sage: x = sum( i*J.gens()[i] for i in range(6) )
+            sage: K = FiniteDimensionalEuclideanJordanElementSubalgebra(x)
+            sage: [ K(x^k) for k in range(J.rank()) ]
+            [f0, f1, f2]
+
+        ::
+
+        """
+        if elt in self.superalgebra():
+            coords = self.vector_space().coordinate_vector(elt.to_vector())
+            return self.from_vector(coords)
+
 
     def superalgebra(self):
         """