dimod.reduce_binary_polynomial#

reduce_binary_polynomial(poly: BinaryPolynomial) Tuple[List[Tuple[FrozenSet[Hashable], Number]], List[Tuple[FrozenSet[Hashable], Hashable]]][source]#

Reduce a binary polynomial to linear and quadratic terms, plus constraints.

Introduces auxillary variables and constraints to reduce the polynomial to linear and quadratic terms.

Parameters:

poly – a binary polynomial that might have higher order terms.

Returns:

Two-tuple of a list of terms and their biases, as tuples, and a list of the original and auxiliary variables, as a tuple.

Example

>>> poly = dimod.BinaryPolynomial({(0,): -1, (1,): 1, (2,): 1.5, (0, 1): -1, (0, 1, 2): -2}, dimod.BINARY)
>>> dimod.reduce_binary_polynomial(poly)           
([(frozenset({0}), -1),
  (frozenset({1}), 1),
  (frozenset({2}), 1.5),
  (frozenset({0, 1}), -1),
  (frozenset({'0*1', 2}), -2)],
 [(frozenset({0, 1}), '0*1')])