Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

The following works (over QQ instead of SR):

def f( Q ):
    D, M = Q.rational_diagonal_form( return_matrix=True )
    base = M.columns()

    BASEpos  = []
    BASEneg  = []
    BASEnull = []

    for j in range( 0, Q.dim() ):
        if   D[j,j] > 0 :    BASEpos  += [ 1/sqrt(  D[j,j] ) * base[j] ]
        elif D[j,j] < 0 :    BASEneg  += [ 1/sqrt( -D[j,j] ) * base[j] ]
        elif D[j,j] ==0 :    BASEnull += [                     base[j] ]

    return span( QQ, BASEpos + BASEneg )

Q = QuadraticForm( QQ, 4, [ 0,0,0,1,  0,-1,0,  0,0,  0 ] )
f( Q )

Results:

Vector space of degree 4 and dimension 4 over Rational Field
Basis matrix:
[1 0 0 0]
[0 1 0 0]
[0 0 1 0]
[0 0 0 1]