Helper code for ternary quadratic forms#

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

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
>>> from sage.all import *
>>> from sage.quadratic_forms.ternary import evaluate
>>> Q = TernaryQF([Integer(1), Integer(2), Integer(3), -Integer(1), Integer(0), Integer(0)])
>>> v = (Integer(1), -Integer(1), Integer(19))
>>> Q(v)
1105
>>> evaluate(Integer(1), Integer(2), Integer(3), -Integer(1), Integer(0), Integer(0), v)
1105
sage.quadratic_forms.ternary.extend(v)[source]#

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
>>> from sage.all import *
>>> from sage.quadratic_forms.ternary import extend
>>> v = (Integer(6), Integer(4), Integer(12))
>>> m = extend(v)
>>> M = matrix(Integer(3), m); M
[ 6  1  0]
[ 4  1  0]
[12  0  1]
>>> M.det()
2
>>> v = (-Integer(12), Integer(20), Integer(30))
>>> m = extend(v)
>>> M = matrix(Integer(3), m)
>>> M
[-12   1   0]
[ 20  -2   1]
[ 30   0  -7]
>>> M.det()
2
sage.quadratic_forms.ternary.primitivize(v0, v1, v2, p)[source]#

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)
>>> from sage.all import *
>>> from sage.quadratic_forms.ternary import primitivize
>>> primitivize(Integer(12), Integer(13), Integer(14), Integer(5))
(3, 2, 1)
>>> primitivize(Integer(12), Integer(13), Integer(15), Integer(5))
(4, 1, 0)
sage.quadratic_forms.ternary.pseudorandom_primitive_zero_mod_p(a, b, c, r, s, t, p)[source]#

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
>>> from sage.all import *
>>> Q = TernaryQF([Integer(1), Integer(2), Integer(2), -Integer(1), Integer(0), Integer(0)])
>>> p = Integer(1009)
>>> from sage.quadratic_forms.ternary import pseudorandom_primitive_zero_mod_p
>>> v = pseudorandom_primitive_zero_mod_p(Integer(1), Integer(2), Integer(2), -Integer(1), Integer(0), Integer(0), p)               # needs sage.libs.pari
>>> v[Integer(2)]                                                                      # needs sage.libs.pari
1
>>> Q(v)%p                                                                    # needs sage.libs.pari
0
sage.quadratic_forms.ternary.red_mfact(a, b)[source]#

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
>>> from sage.all import *
>>> from sage.quadratic_forms.ternary import red_mfact
>>> red_mfact(Integer(0), Integer(3))
0
>>> red_mfact(-Integer(5), Integer(100))
9