Evaluation#

sage.quadratic_forms.quadratic_form__evaluate.QFEvaluateMatrix(Q, M, Q2)[source]#

Evaluate this quadratic form \(Q\) on a matrix \(M\) of elements coercible to the base ring of the quadratic form, which in matrix notation is given by:

\[Q_2 = M^t\cdot Q\cdot M.\]

Note

This is a Python wrapper for the fast evaluation routine QFEvaluateMatrix_cdef(). This routine is for internal use and is called more conveniently as Q(M). The inclusion of Q2 as an argument is to avoid having to create a QuadraticForm() here, which for now creates circular imports.

INPUT:

  • QQuadraticForm over a base ring \(R\)

  • M – a Q.dim() \(\times\) Q2.dim() matrix of elements of \(R\)

OUTPUT: a QuadraticForm over \(R\)

EXAMPLES:

sage: from sage.quadratic_forms.quadratic_form__evaluate import QFEvaluateMatrix
sage: Q = QuadraticForm(ZZ, 4, range(10)); Q
Quadratic form in 4 variables over Integer Ring with coefficients:
[ 0 1 2 3 ]
[ * 4 5 6 ]
[ * * 7 8 ]
[ * * * 9 ]
sage: Q2 = QuadraticForm(ZZ, 2)
sage: M = Matrix(ZZ, 4, 2, [1,0,0,0, 0,1,0,0]); M
[1 0]
[0 0]
[0 1]
[0 0]
sage: QFEvaluateMatrix(Q, M, Q2)
Quadratic form in 2 variables over Integer Ring with coefficients:
[ 0 2 ]
[ * 7 ]
>>> from sage.all import *
>>> from sage.quadratic_forms.quadratic_form__evaluate import QFEvaluateMatrix
>>> Q = QuadraticForm(ZZ, Integer(4), range(Integer(10))); Q
Quadratic form in 4 variables over Integer Ring with coefficients:
[ 0 1 2 3 ]
[ * 4 5 6 ]
[ * * 7 8 ]
[ * * * 9 ]
>>> Q2 = QuadraticForm(ZZ, Integer(2))
>>> M = Matrix(ZZ, Integer(4), Integer(2), [Integer(1),Integer(0),Integer(0),Integer(0), Integer(0),Integer(1),Integer(0),Integer(0)]); M
[1 0]
[0 0]
[0 1]
[0 0]
>>> QFEvaluateMatrix(Q, M, Q2)
Quadratic form in 2 variables over Integer Ring with coefficients:
[ 0 2 ]
[ * 7 ]
sage.quadratic_forms.quadratic_form__evaluate.QFEvaluateVector(Q, v)[source]#

Evaluate this quadratic form \(Q\) on a vector or matrix of elements coercible to the base ring of the quadratic form.

If a vector is given, then the output will be the ring element \(Q(v)\), but if a matrix is given, then the output will be the quadratic form \(Q'\) which in matrix notation is given by:

\[Q' = v^t\cdot Q\cdot v.\]

Note

This is a Python wrapper for the fast evaluation routine QFEvaluateVector_cdef(). This routine is for internal use and is called more conveniently as Q(M).

INPUT:

  • QQuadraticForm over a base ring \(R\)

  • v – a tuple or list (or column matrix) of Q.dim() elements of \(R\)

OUTPUT: an element of \(R\)

EXAMPLES:

sage: from sage.quadratic_forms.quadratic_form__evaluate import QFEvaluateVector
sage: Q = QuadraticForm(ZZ, 4, range(10)); Q
Quadratic form in 4 variables over Integer Ring with coefficients:
[ 0 1 2 3 ]
[ * 4 5 6 ]
[ * * 7 8 ]
[ * * * 9 ]
sage: QFEvaluateVector(Q, (1,0,0,0))
0
sage: QFEvaluateVector(Q, (1,0,1,0))
9
>>> from sage.all import *
>>> from sage.quadratic_forms.quadratic_form__evaluate import QFEvaluateVector
>>> Q = QuadraticForm(ZZ, Integer(4), range(Integer(10))); Q
Quadratic form in 4 variables over Integer Ring with coefficients:
[ 0 1 2 3 ]
[ * 4 5 6 ]
[ * * 7 8 ]
[ * * * 9 ]
>>> QFEvaluateVector(Q, (Integer(1),Integer(0),Integer(0),Integer(0)))
0
>>> QFEvaluateVector(Q, (Integer(1),Integer(0),Integer(1),Integer(0)))
9