Matrix/Vector-Valued Linear Functions: Elements#

Here is an example of a linear function tensored with a vector space:

sage: mip.<x> = MixedIntegerLinearProgram('ppl')   # base ring is QQ
sage: lt = x[0] * vector([3,4]) + 1;   lt
(1, 1) + (3, 4)*x_0
sage: type(lt)
<class 'sage.numerical.linear_tensor_element.LinearTensor'>
class sage.numerical.linear_tensor_element.LinearTensor#

Bases: ModuleElement

A linear function tensored with a free module

Warning

You should never instantiate LinearTensor manually. Use the element constructor in the parent instead.

EXAMPLES:

sage: parent = MixedIntegerLinearProgram().linear_functions_parent().tensor(RDF^2)
sage: parent({0: [1,2], 3: [-7,-8]})
(1.0, 2.0)*x_0 + (-7.0, -8.0)*x_3
coefficient(x)#

Return one of the coefficients.

INPUT:

  • x – a linear variable or an integer. If an integer \(i\) is passed, then \(x_i\) is used as linear variable. Pass -1 for the constant term.

OUTPUT:

A constant, that is, an element of the free module factor. The coefficient of x in the linear function.

EXAMPLES:

sage: mip.<b> = MixedIntegerLinearProgram()
sage: lt = vector([1,2]) * b[3] + vector([4,5]) * b[0] - 5;  lt
(-5.0, -5.0) + (1.0, 2.0)*x_0 + (4.0, 5.0)*x_1
sage: lt.coefficient(b[3])
(1.0, 2.0)
sage: lt.coefficient(0)      # x_0 is b[3]
(1.0, 2.0)
sage: lt.coefficient(4)
(0.0, 0.0)
sage: lt.coefficient(-1)
(-5.0, -5.0)
dict()#

Return the dictionary corresponding to the tensor product.

OUTPUT:

The linear function tensor product is represented as a dictionary. The value are the coefficient (free module elements) of the variable represented by the keys (which are integers). The key -1 corresponds to the constant term.

EXAMPLES:

sage: p = MixedIntegerLinearProgram().linear_functions_parent().tensor(RDF^2)
sage: lt = p({0:[1,2], 3:[4,5]})
sage: lt.dict()
{0: (1.0, 2.0), 3: (4.0, 5.0)}