]> gitweb.michael.orlitzky.com - sage.d.git/blobdiff - mjo/eja/eja_algebra.py
eja: add random_elements() method to get multiple random elements at once.
[sage.d.git] / mjo / eja / eja_algebra.py
index a207250b4092f97e07d93a62c0ed7e23d9f9536d..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
 
@@ -441,14 +442,12 @@ class FiniteDimensionalEuclideanJordanAlgebra(CombinatorialFreeModule):
 
         EXAMPLES:
 
-        The inner product must satisfy its axiom for this algebra to truly
-        be a Euclidean Jordan Algebra::
+        Our inner product satisfies the Jordan axiom, which is also
+        referred to as "associativity" for a symmetric bilinear form::
 
             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):
@@ -800,16 +818,6 @@ class RealCartesianProductEJA(FiniteDimensionalEuclideanJordanAlgebra):
         sage: RealCartesianProductEJA(3, prefix='r').gens()
         (r0, r1, r2)
 
-    Our inner product satisfies the Jordan axiom::
-
-        sage: set_random_seed()
-        sage: J = RealCartesianProductEJA.random_instance()
-        sage: x = J.random_element()
-        sage: y = J.random_element()
-        sage: z = J.random_element()
-        sage: (x*y).inner_product(z) == y.inner_product(x*z)
-        True
-
     """
     def __init__(self, n, field=QQ, **kwargs):
         V = VectorSpace(field, n)
@@ -834,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)
@@ -1042,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()
@@ -1058,16 +1064,6 @@ class RealSymmetricEJA(MatrixEuclideanJordanAlgebra):
         sage: RealSymmetricEJA(3, prefix='q').gens()
         (q0, q1, q2, q3, q4, q5)
 
-    Our inner product satisfies the Jordan axiom::
-
-        sage: set_random_seed()
-        sage: J = RealSymmetricEJA.random_instance()
-        sage: x = J.random_element()
-        sage: y = J.random_element()
-        sage: z = J.random_element()
-        sage: (x*y).inner_product(z) == y.inner_product(x*z)
-        True
-
     Our natural basis is normalized with respect to the natural inner
     product unless we specify otherwise::
 
@@ -1295,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()
@@ -1311,16 +1306,6 @@ class ComplexHermitianEJA(ComplexMatrixEuclideanJordanAlgebra):
         sage: ComplexHermitianEJA(2, prefix='z').gens()
         (z0, z1, z2, z3)
 
-    Our inner product satisfies the Jordan axiom::
-
-        sage: set_random_seed()
-        sage: J = ComplexHermitianEJA.random_instance()
-        sage: x = J.random_element()
-        sage: y = J.random_element()
-        sage: z = J.random_element()
-        sage: (x*y).inner_product(z) == y.inner_product(x*z)
-        True
-
     Our natural basis is normalized with respect to the natural inner
     product unless we specify otherwise::
 
@@ -1555,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()
@@ -1571,16 +1555,6 @@ class QuaternionHermitianEJA(QuaternionMatrixEuclideanJordanAlgebra):
         sage: QuaternionHermitianEJA(2, prefix='a').gens()
         (a0, a1, a2, a3, a4, a5)
 
-    Our inner product satisfies the Jordan axiom::
-
-        sage: set_random_seed()
-        sage: J = QuaternionHermitianEJA.random_instance()
-        sage: x = J.random_element()
-        sage: y = J.random_element()
-        sage: z = J.random_element()
-        sage: (x*y).inner_product(z) == y.inner_product(x*z)
-        True
-
     Our natural basis is normalized with respect to the natural inner
     product unless we specify otherwise::
 
@@ -1692,16 +1666,6 @@ class JordanSpinEJA(FiniteDimensionalEuclideanJordanAlgebra):
         sage: JordanSpinEJA(2, prefix='B').gens()
         (B0, B1)
 
-    Our inner product satisfies the Jordan axiom::
-
-        sage: set_random_seed()
-        sage: J = JordanSpinEJA.random_instance()
-        sage: x = J.random_element()
-        sage: y = J.random_element()
-        sage: z = J.random_element()
-        sage: (x*y).inner_product(z) == y.inner_product(x*z)
-        True
-
     """
     def __init__(self, n, field=QQ, **kwargs):
         V = VectorSpace(field, n)
@@ -1741,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)