From: Michael Orlitzky Date: Sun, 22 Nov 2020 14:57:43 +0000 (-0500) Subject: eja: add random_instance() for BilinearFormEJA. X-Git-Url: http://gitweb.michael.orlitzky.com/?a=commitdiff_plain;h=3f8818f3eca0b2ea388130ff805875012cf902cb;p=sage.d.git eja: add random_instance() for BilinearFormEJA. --- diff --git a/mjo/eja/eja_algebra.py b/mjo/eja/eja_algebra.py index c822d14..8ca501d 100644 --- a/mjo/eja/eja_algebra.py +++ b/mjo/eja/eja_algebra.py @@ -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 """