# Helper code for ternary quadratic forms#

sage.quadratic_forms.ternary.evaluate(a, b, c, r, s, t, v)#

Function to evaluate the ternary quadratic form $$(a, b, c, r, s, t)$$ in a 3-tuple $$v$$.

EXAMPLES:

sage: from sage.quadratic_forms.ternary import evaluate
sage: Q = TernaryQF([1, 2, 3, -1, 0, 0])
sage: v = (1, -1, 19)
sage: Q(v)
1105
sage: evaluate(1, 2, 3, -1, 0, 0, v)
1105


Return the coefficients of a matrix $$M$$ such that $$M$$ has determinant gcd($$v$$) and the first column is $$v$$.

EXAMPLES:

sage: from sage.quadratic_forms.ternary import extend
sage: v = (6, 4, 12)
sage: m = extend(v)
sage: M = matrix(3, m); M
[ 6  1  0]
[ 4  1  0]
[12  0  1]
sage: M.det()
2
sage: v = (-12, 20, 30)
sage: m = extend(v)
sage: M = matrix(3, m)
sage: M
[-12   1   0]
[ 20  -2   1]
[ 30   0  -7]
sage: M.det()
2

sage.quadratic_forms.ternary.primitivize(v0, v1, v2, p)#

Given a 3-tuple $$v$$ not singular mod $$p$$, return a primitive 3-tuple version of $$v$$ mod $$p$$.

EXAMPLES:

sage: from sage.quadratic_forms.ternary import primitivize
sage: primitivize(12, 13, 14, 5)
(3, 2, 1)
sage: primitivize(12, 13, 15, 5)
(4, 1, 0)

sage.quadratic_forms.ternary.pseudorandom_primitive_zero_mod_p(a, b, c, r, s, t, p)#

Find a zero of the form $$(a, b, 1)$$ of the ternary quadratic form given by the coefficients $$(a, b, c, r, s, t)$$ mod $$p$$, where $$p$$ is a odd prime that doesn’t divide the discriminant.

EXAMPLES:

sage: Q = TernaryQF([1, 2, 2, -1, 0, 0])
sage: p = 1009
sage: from sage.quadratic_forms.ternary import pseudorandom_primitive_zero_mod_p
sage: v = pseudorandom_primitive_zero_mod_p(1, 2, 2, -1, 0, 0, p)               # needs sage.libs.pari
sage: v[2]                                                                      # needs sage.libs.pari
1
sage: Q(v)%p                                                                    # needs sage.libs.pari
0


Auxiliary function for reduction that finds the reduction factor of integers $$a$$, $$b$$.

INPUT:

• a, b – integers

OUTPUT: Integer

EXAMPLES:

sage: from sage.quadratic_forms.ternary import red_mfact
sage: red_mfact(0, 3)
0
sage: red_mfact(-5, 100)
9