X-Git-Url: http://gitweb.michael.orlitzky.com/?a=blobdiff_plain;f=mjo%2Feja%2Feja_algebra.py;h=8219c5b4ff32b7acdb55de21aac53f657a11b20f;hb=e0031c84e8b7d89071f052f44d1cf28b2370b161;hp=c822d14f6d0900a8b90c24d377fb31196003e0e8;hpb=cda12a746b75b33381325e31afab44c6e9b85950;p=sage.d.git diff --git a/mjo/eja/eja_algebra.py b/mjo/eja/eja_algebra.py index c822d14..8219c5b 100644 --- a/mjo/eja/eja_algebra.py +++ b/mjo/eja/eja_algebra.py @@ -2111,6 +2111,20 @@ class BilinearFormEJA(RationalBasisEuclideanJordanAlgebra): sage: J0.multiplication_table() == J0.multiplication_table() True + An error is raised if the matrix `B` does not correspond to a + positive-definite bilinear form:: + + sage: B = matrix.random(QQ,2,3) + sage: J = BilinearFormEJA(B) + Traceback (most recent call last): + ... + ValueError: bilinear form is not positive-definite + sage: B = matrix.zero(QQ,3) + sage: J = BilinearFormEJA(B) + Traceback (most recent call last): + ... + ValueError: bilinear form is not positive-definite + TESTS: We can create a zero-dimensional algebra:: @@ -2151,7 +2165,7 @@ class BilinearFormEJA(RationalBasisEuclideanJordanAlgebra): n = B.nrows() if not B.is_positive_definite(): - raise TypeError("matrix B is not positive-definite") + raise ValueError("bilinear form is not positive-definite") V = VectorSpace(field, n) mult_table = [[V.zero() for j in range(n)] for i in range(n)] @@ -2181,6 +2195,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 +2239,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 """ @@ -2272,6 +2306,16 @@ class JordanSpinEJA(BilinearFormEJA): B = matrix.identity(field, n) super(JordanSpinEJA, self).__init__(B, field, **kwargs) + @classmethod + def random_instance(cls, field=AA, **kwargs): + """ + Return a random instance of this type of algebra. + + Needed here to override the implementation for ``BilinearFormEJA``. + """ + n = ZZ.random_element(cls._max_random_instance_size() + 1) + return cls(n, field, **kwargs) + class TrivialEJA(FiniteDimensionalEuclideanJordanAlgebra): """