# Rational quadratic form from invariants

I'm trying to restore rational quadratic form from invariants using quadratic_form_from_invariants function. But why this code doesn't work? I'm taking rational quadratic form invariants and trying to restore it back. Or am I doing something wrong?

    Q = DiagonalQuadraticForm(QQ, [1, -1, -1])
P = [p for p in [-1] + list(prime_range(1000)) if Q.hasse_invariant(p) == -1]

params = Q.dim(), Q.Gram_det(), P, Q.signature_vector()[1]
print(params)



It gets results

  (3, 1, [-1, 2], 2)
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Input In [1], in <cell line: 7>()
4 params = Q.dim(), Q.Gram_det(), P, Q.signature_vector()[Integer(1)]
5 print(params)

152     f = 1
153 if (f + len(P)) % 2 == 1:
--> 154     raise ValueError("invariants do not define a rational quadratic form")
155 D = []
156 while rk >= 2:

ValueError: invariants do not define a rational quadratic form


Thanks!

edit retag close merge delete

You may try P = [p for p in 2*[-1] + list(prime_range(1000)) if Q.hasse_invariant(p) == -1] to avoid that raise - the implementer had something different in mind and wanted P to be a list of primes...