### Navigation

- index
- modules |
- next |
- previous |
- Numerical Optimization »

# Matrix/Vector-Valued Linear Functions: Elements

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)
    <type 'sage.numerical.linear_tensor_element.LinearTensor'>

class `sage.numerical.linear_tensor_element.``LinearTensor`

  Bases: `sage.structure.element.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 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.

    EXAMPLE:

        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)

    TESTS:

        sage: lt.coefficient(b[3] + b[4])
        Traceback (most recent call last):
        ...
        ValueError: x is a sum, must be a single variable
        sage: lt.coefficient(2*b[3])
        Traceback (most recent call last):
        ...
        ValueError: x must have a unit coefficient
        sage: mip.<q> = MixedIntegerLinearProgram(solver='ppl')
        sage: lt.coefficient(q[0])
        Traceback (most recent call last):
        ...
        ValueError: x is from a different linear functions module

  `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.

    EXAMPLE:

        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)}

### Navigation

- index
- modules |
- next |
- previous |
- Numerical Optimization »