]> gitweb.michael.orlitzky.com - sage.d.git/commitdiff
eja: add random_elements() method to get multiple random elements at once.
authorMichael Orlitzky <michael@orlitzky.com>
Sat, 24 Aug 2019 00:02:28 +0000 (20:02 -0400)
committerMichael Orlitzky <michael@orlitzky.com>
Sat, 24 Aug 2019 00:02:28 +0000 (20:02 -0400)
mjo/eja/eja_algebra.py
mjo/eja/eja_element.py

index 29ff1da38480b3b9b07d1ff39555948e31785732..1ae3286cea5a26eda3d82f7161aab639bc9d724c 100644 (file)
@@ -5,6 +5,8 @@ are used in optimization, and have some additional nice methods beyond
 what can be supported in a general Jordan Algebra.
 """
 
+from itertools import repeat
+
 from sage.algebras.quatalg.quaternion_algebra import QuaternionAlgebra
 from sage.categories.magmatic_algebras import MagmaticAlgebras
 from sage.combinat.free_module import CombinatorialFreeModule
@@ -51,8 +53,7 @@ class FiniteDimensionalEuclideanJordanAlgebra(CombinatorialFreeModule):
 
             sage: set_random_seed()
             sage: J = random_eja()
-            sage: x = J.random_element()
-            sage: y = J.random_element()
+            sage: x,y = J.random_elements(2)
             sage: x*y == y*x
             True
 
@@ -446,9 +447,7 @@ class FiniteDimensionalEuclideanJordanAlgebra(CombinatorialFreeModule):
 
             sage: set_random_seed()
             sage: J = random_eja()
-            sage: x = J.random_element()
-            sage: y = J.random_element()
-            sage: z = J.random_element()
+            sage: x,y,z = J.random_elements(3)
             sage: (x*y).inner_product(z) == y.inner_product(x*z)
             True
 
@@ -657,6 +656,25 @@ class FiniteDimensionalEuclideanJordanAlgebra(CombinatorialFreeModule):
             s = super(FiniteDimensionalEuclideanJordanAlgebra, self)
             return s.random_element()
 
+    def random_elements(self, count):
+        """
+        Return ``count`` random elements as a tuple.
+
+        SETUP::
+
+            sage: from mjo.eja.eja_algebra import JordanSpinEJA
+
+        EXAMPLES::
+
+            sage: J = JordanSpinEJA(3)
+            sage: x,y,z = J.random_elements(3)
+            sage: all( [ x in J, y in J, z in J ])
+            True
+            sage: len( J.random_elements(10) ) == 10
+            True
+
+        """
+        return  tuple( self.random_element() for idx in xrange(count) )
 
     @classmethod
     def random_instance(cls, field=QQ, **kwargs):
@@ -824,8 +842,7 @@ class RealCartesianProductEJA(FiniteDimensionalEuclideanJordanAlgebra):
 
             sage: set_random_seed()
             sage: J = RealCartesianProductEJA.random_instance()
-            sage: x = J.random_element()
-            sage: y = J.random_element()
+            sage: x,y = J.random_elements(2)
             sage: X = x.natural_representation()
             sage: Y = y.natural_representation()
             sage: x.inner_product(y) == J.natural_inner_product(X,Y)
@@ -1032,8 +1049,7 @@ class RealSymmetricEJA(MatrixEuclideanJordanAlgebra):
 
         sage: set_random_seed()
         sage: J = RealSymmetricEJA.random_instance()
-        sage: x = J.random_element()
-        sage: y = J.random_element()
+        sage: x,y = J.random_elements(2)
         sage: actual = (x*y).natural_representation()
         sage: X = x.natural_representation()
         sage: Y = y.natural_representation()
@@ -1275,8 +1291,7 @@ class ComplexHermitianEJA(ComplexMatrixEuclideanJordanAlgebra):
 
         sage: set_random_seed()
         sage: J = ComplexHermitianEJA.random_instance()
-        sage: x = J.random_element()
-        sage: y = J.random_element()
+        sage: x,y = J.random_elements(2)
         sage: actual = (x*y).natural_representation()
         sage: X = x.natural_representation()
         sage: Y = y.natural_representation()
@@ -1525,8 +1540,7 @@ class QuaternionHermitianEJA(QuaternionMatrixEuclideanJordanAlgebra):
 
         sage: set_random_seed()
         sage: J = QuaternionHermitianEJA.random_instance()
-        sage: x = J.random_element()
-        sage: y = J.random_element()
+        sage: x,y = J.random_elements(2)
         sage: actual = (x*y).natural_representation()
         sage: X = x.natural_representation()
         sage: Y = y.natural_representation()
@@ -1691,8 +1705,7 @@ class JordanSpinEJA(FiniteDimensionalEuclideanJordanAlgebra):
 
             sage: set_random_seed()
             sage: J = JordanSpinEJA.random_instance()
-            sage: x = J.random_element()
-            sage: y = J.random_element()
+            sage: x,y = J.random_elements(2)
             sage: X = x.natural_representation()
             sage: Y = y.natural_representation()
             sage: x.inner_product(y) == J.natural_inner_product(X,Y)
index f26766df80f65de8c31fe12ef3eab5d5bd727c7a..8a17c25d4a0d52d98c063f856d888207e2ca74ea 100644 (file)
@@ -243,8 +243,7 @@ class FiniteDimensionalEuclideanJordanAlgebraElement(IndexedFreeModuleElement):
 
             sage: set_random_seed()
             sage: J = random_eja()
-            sage: x = J.random_element()
-            sage: y = J.random_element()
+            sage: x,y = J.random_elements(2)
             sage: x.inner_product(y) in RR
             True
 
@@ -280,9 +279,7 @@ class FiniteDimensionalEuclideanJordanAlgebraElement(IndexedFreeModuleElement):
         Test Lemma 1 from Chapter III of Koecher::
 
             sage: set_random_seed()
-            sage: J = random_eja()
-            sage: u = J.random_element()
-            sage: v = J.random_element()
+            sage: u,v = random_eja().random_elements(2)
             sage: lhs = u.operator_commutes_with(u*v)
             sage: rhs = v.operator_commutes_with(u^2)
             sage: lhs == rhs
@@ -292,9 +289,7 @@ class FiniteDimensionalEuclideanJordanAlgebraElement(IndexedFreeModuleElement):
         Chapter III, or from Baes (2.3)::
 
             sage: set_random_seed()
-            sage: J = random_eja()
-            sage: x = J.random_element()
-            sage: y = J.random_element()
+            sage: x,y = random_eja().random_elements(2)
             sage: Lx = x.operator()
             sage: Ly = y.operator()
             sage: Lxx = (x*x).operator()
@@ -306,10 +301,7 @@ class FiniteDimensionalEuclideanJordanAlgebraElement(IndexedFreeModuleElement):
         Baes (2.4)::
 
             sage: set_random_seed()
-            sage: J = random_eja()
-            sage: x = J.random_element()
-            sage: y = J.random_element()
-            sage: z = J.random_element()
+            sage: x,y,z = random_eja().random_elements(3)
             sage: Lx = x.operator()
             sage: Ly = y.operator()
             sage: Lz = z.operator()
@@ -323,10 +315,7 @@ class FiniteDimensionalEuclideanJordanAlgebraElement(IndexedFreeModuleElement):
         Baes (2.5)::
 
             sage: set_random_seed()
-            sage: J = random_eja()
-            sage: u = J.random_element()
-            sage: y = J.random_element()
-            sage: z = J.random_element()
+            sage: u,y,z = random_eja().random_elements(3)
             sage: Lu = u.operator()
             sage: Ly = y.operator()
             sage: Lz = z.operator()
@@ -388,8 +377,7 @@ class FiniteDimensionalEuclideanJordanAlgebraElement(IndexedFreeModuleElement):
 
             sage: set_random_seed()
             sage: J = random_eja().random_element().subalgebra_generated_by()
-            sage: x = J.random_element()
-            sage: y = J.random_element()
+            sage: x,y = J.random_elements(2)
             sage: (x*y).det() == x.det()*y.det()
             True
 
@@ -885,8 +873,7 @@ class FiniteDimensionalEuclideanJordanAlgebraElement(IndexedFreeModuleElement):
 
             sage: set_random_seed()
             sage: J = random_eja()
-            sage: x = J.random_element()
-            sage: y = J.random_element()
+            sage: x,y = J.random_elements(2)
             sage: x.operator()(y) == x*y
             True
             sage: y.operator()(x) == x*y
@@ -936,8 +923,7 @@ class FiniteDimensionalEuclideanJordanAlgebraElement(IndexedFreeModuleElement):
 
             sage: set_random_seed()
             sage: J = random_eja()
-            sage: x = J.random_element()
-            sage: y = J.random_element()
+            sage: x,y = J.random_elements(2)
             sage: Lx = x.operator()
             sage: Lxx = (x*x).operator()
             sage: Qx = x.quadratic_representation()
@@ -1039,9 +1025,7 @@ class FiniteDimensionalEuclideanJordanAlgebraElement(IndexedFreeModuleElement):
             sage: set_random_seed()
             sage: x0 = random_eja().random_element()
             sage: A = x0.subalgebra_generated_by()
-            sage: x = A.random_element()
-            sage: y = A.random_element()
-            sage: z = A.random_element()
+            sage: x,y,z = A.random_elements(3)
             sage: (x*y)*z == x*(y*z)
             True
 
@@ -1181,9 +1165,7 @@ class FiniteDimensionalEuclideanJordanAlgebraElement(IndexedFreeModuleElement):
 
             sage: set_random_seed()
             sage: J = random_eja()
-            sage: x = J.random_element();
-            sage: y = J.random_element()
-            sage: z = J.random_element()
+            sage: x,y,z = J.random_elements(3)
             sage: # commutative
             sage: x.trace_inner_product(y) == y.trace_inner_product(x)
             True