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.
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
"""