]> gitweb.michael.orlitzky.com - sage.d.git/commitdiff
eja: add random_instance() for BilinearFormEJA.
authorMichael Orlitzky <michael@orlitzky.com>
Sun, 22 Nov 2020 14:57:43 +0000 (09:57 -0500)
committerMichael Orlitzky <michael@orlitzky.com>
Sun, 22 Nov 2020 14:57:43 +0000 (09:57 -0500)
mjo/eja/eja_algebra.py

index c822d14f6d0900a8b90c24d377fb31196003e0e8..8ca501d6ba944a539901d384a78a5c8a0f45a7ca 100644 (file)
@@ -2181,6 +2181,31 @@ class BilinearFormEJA(RationalBasisEuclideanJordanAlgebra):
     def _max_random_instance_size():
         return 5
 
+    @classmethod
+    def random_instance(cls, field=AA, **kwargs):
+        """
+        Return a random instance of this algebra.
+        """
+        n = ZZ.random_element(cls._max_random_instance_size() + 1)
+        if n == 0:
+            # Special case needed since we use (n-1) below.
+            B = matrix.identity(field, 0)
+            return cls(B, field, **kwargs)
+
+        B11 = matrix.identity(field,1)
+        M = matrix.random(field, n-1)
+        I = matrix.identity(field, n-1)
+        alpha = field.zero()
+        while alpha.is_zero():
+            alpha = field.random_element().abs()
+        B22 = M.transpose()*M + alpha*I
+
+        from sage.matrix.special import block_matrix
+        B = block_matrix(2,2, [ [B11,   ZZ(0) ],
+                                [ZZ(0), B22 ] ])
+
+        return cls(B, field, **kwargs)
+
     def inner_product(self, x, y):
         r"""
         Half of the trace inner product.
@@ -2200,16 +2225,11 @@ class BilinearFormEJA(RationalBasisEuclideanJordanAlgebra):
         paper::
 
             sage: set_random_seed()
-            sage: n = ZZ.random_element(2,5)
-            sage: M = matrix.random(QQ, max(0,n-1), algorithm='unimodular')
-            sage: B11 = matrix.identity(QQ,1)
-            sage: B22 = M.transpose()*M
-            sage: B = block_matrix(2,2,[ [B11,0  ],
-            ....:                        [0, B22 ] ])
-            sage: J = BilinearFormEJA(B)
+            sage: J = BilinearFormEJA.random_instance()
+            sage: n = J.dimension()
             sage: x = J.random_element()
             sage: y = J.random_element()
-            sage: x.inner_product(y) == (x*y).trace()/2
+            sage: (n == 1) or (x.inner_product(y) == (x*y).trace()/2)
             True
 
         """