PolyΒΆ

class PolyΒΆ

The polynomial class used for representing objective functions and constraints.

Methods

__init__

__init__

as_dict

Return the dictionary representation of the polynomial.

as_variable

Return the variable representation of the polynomial.

asdict

alias of as_dict()

decode

Equivalent to evaluate().

degree

Return the degree of the polynomial.

evaluate

Evaluate the polynomial by substituting variables using the given values.

is_linear

Return True if the polynomial is linear.

is_number

Return True if the polynomial is a constant polynomial.

is_quadratic

Return True if the polynomial is quadratic.

is_variable

Return True if the polynomial represents a single variable.

substitute

Assign numbers or other polynomials to variables in the polynomial.

Attributes

id

Variable ID.

lower_bound

Lower bound of the variable.

name

Variable name.

type

Variable type.

upper_bound

Upper bound of the variable.

variables

List of all variables in the polynomial.

class IteratorΒΆ
__init__(*args, **kwargs)ΒΆ
__iter__(self) IteratorΒΆ

__iter__

Return type:

Iterator

__next__(self) tuple[tuple[Poly, ...], float]ΒΆ

__next__

Return type:

tuple[tuple[Poly, …], float]

__add__(self, arg: Poly | float, /) PolyΒΆ
__add__(self, arg: ndarray[], /) PolyArray[Dim]
__add__(self, arg: Constraint | ConstraintList, /) Model

__add__

Overload 1.

Args:
  • arg (amplify.Poly | float)

Returns:

amplify.Poly:

Overload 2.

Args:
  • arg (ndarray)

Returns:

amplify.PolyArray[Dim]:

Overload 3.

Args:
  • arg (amplify.Constraint | amplify.ConstraintList)

Returns:

amplify.Model:

__and__(self, arg: Poly | bool, /) PolyΒΆ
__and__(self, arg: ndarray[dtype=bool], /) PolyArray[Dim]

Logical AND of two polynomials. This is meaningful only for polynomials that take values 0 or 1. __and__

q_0 & q_1 is equivalent to q_0 * q_1.

Overload 1.

Args:
  • arg (amplify.Poly | bool)

Returns:

amplify.Poly:

Overload 2.

Args:
  • arg (ndarray)

Returns:

amplify.PolyArray[Dim]:

__bool__(self) boolΒΆ

Cast a polynomial to a boolean value. Only valid for constant polynomials that take values 0 or 1.

Return type:

bool

__eq__(self, arg: object, /) boolΒΆ

__eq__

Parameters:

arg (object)

Return type:

bool

__float__(self) floatΒΆ

Cast a polynomial to a float value. Only valid for constant polynomials.

Return type:

float

__iadd__(self, arg: Poly | float, /) PolyΒΆ

__iadd__

Parameters:

arg (Poly | float)

Return type:

Poly

__iand__(self, arg: Poly | bool, /) PolyΒΆ

__iand__

Parameters:

arg (Poly | bool)

Return type:

Poly

__imul__(self, arg: Poly | float, /) PolyΒΆ

__imul__

Parameters:

arg (Poly | float)

Return type:

Poly

__index__(self) intΒΆ

Cast a polynomial to an integer. Only valid for constant polynomials.

Return type:

int

__init__(self) NoneΒΆ
__init__(self, arg: float, /) None
__init__(self, arg: Variable, /) None

__init__

Overload 2.

Args:
  • arg (float)

Overload 3.

Args:
  • arg (amplify.Variable)

__int__(self) intΒΆ

Cast a polynomial to an integer. Only valid for constant polynomials.

Return type:

int

__invert__(self) PolyΒΆ

Logical NOT of a polynomial. This is meaningful only for polynomials that take values 0 or 1.

~q_0 is equivalent to 1 - q_0.

Return type:

Poly

__ior__(self, arg: Poly | bool, /) PolyΒΆ

__ior__

Parameters:

arg (Poly | bool)

Return type:

Poly

__ipow__(self, arg: int, /) PolyΒΆ

__ipow__

Parameters:

arg (int)

Return type:

Poly

__isub__(self, arg: Poly | float, /) PolyΒΆ

__isub__

Parameters:

arg (Poly | float)

Return type:

Poly

__iter__(self) IteratorΒΆ

Iterate over the terms in the polynomial.

Each term is represented as a tuple of a tuple of variables and a coefficient. For example, the polynomial 3 * x_0 * x_1 - 2 * x_0 + 5 is iterated as ((Poly(x_0), Poly(x_1)), 3.0), ((Poly(x_0),), -2.0), and ((), 5.0).

Return type:

Iterator

__itruediv__(self, arg: float, /) PolyΒΆ

__itruediv__

Parameters:

arg (float)

Return type:

Poly

__ixor__(self, arg: Poly | bool, /) PolyΒΆ

__ixor__

Parameters:

arg (Poly | bool)

Return type:

Poly

__len__(self) intΒΆ

Return the number of terms in the polynomial.

Return type:

int

__mul__(self, arg: Poly | float, /) PolyΒΆ
__mul__(self, arg: ndarray[], /) PolyArray[Dim]

__mul__

Overload 1.

Args:
  • arg (amplify.Poly | float)

Returns:

amplify.Poly:

Overload 2.

Args:
  • arg (ndarray)

Returns:

amplify.PolyArray[Dim]:

__ne__(self, arg: object, /) boolΒΆ

__ne__

Parameters:

arg (object)

Return type:

bool

__neg__(self) PolyΒΆ

__neg__

Return type:

Poly

__or__(self, arg: Poly | bool, /) PolyΒΆ
__or__(self, arg: ndarray[dtype=bool], /) PolyArray[Dim]

Logical OR of two polynomials. This is meaningful only for polynomials that take values 0 or 1. __or__

q_0 | q_1 is equivalent to -q_0 * q_1 + q_0 + q_1.

Overload 1.

Args:
  • arg (amplify.Poly | bool)

Returns:

amplify.Poly:

Overload 2.

Args:
  • arg (ndarray)

Returns:

amplify.PolyArray[Dim]:

__pos__(self) PolyΒΆ

__pos__

Return type:

Poly

__pow__(self, arg: int, /) PolyΒΆ

__pow__

Parameters:

arg (int)

Return type:

Poly

__radd__(self, arg: float, /) PolyΒΆ
__radd__(self, arg: ndarray[], /) PolyArray[Dim]
__radd__(self, arg: Constraint | ConstraintList, /) Model

__radd__

Overload 1.

Args:
  • arg (float)

Returns:

amplify.Poly:

Overload 2.

Args:
  • arg (ndarray)

Returns:

amplify.PolyArray[Dim]:

Overload 3.

Args:
  • arg (amplify.Constraint | amplify.ConstraintList)

Returns:

amplify.Model:

__rand__(self, arg: bool, /) PolyΒΆ
__rand__(self, arg: ndarray[dtype=bool], /) PolyArray[Dim]

__rand__

Overload 1.

Args:
  • arg (bool)

Returns:

amplify.Poly:

Overload 2.

Args:
  • arg (ndarray)

Returns:

amplify.PolyArray[Dim]:

__repr__(self) strΒΆ

__repr__

Return type:

str

__rmul__(self, arg: float, /) PolyΒΆ
__rmul__(self, arg: ndarray[], /) PolyArray[Dim]

__rmul__

Overload 1.

Args:
  • arg (float)

Returns:

amplify.Poly:

Overload 2.

Args:
  • arg (ndarray)

Returns:

amplify.PolyArray[Dim]:

__ror__(self, arg: bool, /) PolyΒΆ
__ror__(self, arg: ndarray[dtype=bool], /) PolyArray[Dim]

__ror__

Overload 1.

Args:
  • arg (bool)

Returns:

amplify.Poly:

Overload 2.

Args:
  • arg (ndarray)

Returns:

amplify.PolyArray[Dim]:

__rsub__(self, arg: float, /) PolyΒΆ
__rsub__(self, arg: ndarray[], /) PolyArray[Dim]

__rsub__

Overload 1.

Args:
  • arg (float)

Returns:

amplify.Poly:

Overload 2.

Args:
  • arg (ndarray)

Returns:

amplify.PolyArray[Dim]:

__rxor__(self, arg: bool, /) PolyΒΆ
__rxor__(self, arg: ndarray[dtype=bool], /) PolyArray[Dim]

__rxor__

Overload 1.

Args:
  • arg (bool)

Returns:

amplify.Poly:

Overload 2.

Args:
  • arg (ndarray)

Returns:

amplify.PolyArray[Dim]:

__str__(self) strΒΆ

__str__

Return type:

str

__sub__(self, arg: Poly | float, /) PolyΒΆ
__sub__(self, arg: ndarray[], /) PolyArray[Dim]

__sub__

Overload 1.

Args:
  • arg (amplify.Poly | float)

Returns:

amplify.Poly:

Overload 2.

Args:
  • arg (ndarray)

Returns:

amplify.PolyArray[Dim]:

__truediv__(self, arg: float, /) PolyΒΆ
__truediv__(self, arg: ndarray[], /) PolyArray[Dim]

__truediv__

Overload 1.

Args:
  • arg (float)

Returns:

amplify.Poly:

Overload 2.

Args:
  • arg (ndarray)

Returns:

amplify.PolyArray[Dim]:

__xor__(self, arg: Poly | bool, /) PolyΒΆ
__xor__(self, arg: ndarray[dtype=bool], /) PolyArray[Dim]

Logical XOR of two polynomials. This is meaningful only for polynomials that take values 0 or 1. __xor__

q_0 ^ q_1 is equivalent to -2 * q_0 * q_1 + q_0 + q_1.

Overload 1.

Args:
  • arg (amplify.Poly | bool)

Returns:

amplify.Poly:

Overload 2.

Args:
  • arg (ndarray)

Returns:

amplify.PolyArray[Dim]:

as_dict(self) dict[tuple[int, ...], float]ΒΆ

Return the dictionary representation of the polynomial.

The polynomial is represented as a dictionary where keys are tuples of variable indices and values are coefficients. For example, the polynomial 3 * x_0 - 2 * x_0 * x_1 + 5 will be represented as {(): 5, (0,): 3, (0, 1): -2}.

Return type:

dict[tuple[int, …], float]

as_variable(self) VariableΒΆ

Return the variable representation of the polynomial. Only valid for polynomials that represent a single variable.

Return type:

Variable

asdict(self) dict[tuple[int, ...], float]ΒΆ

alias of as_dict()

Return type:

dict[tuple[int, …], float]

decode(self, values: Values) floatΒΆ
decode(self, values: Values, default: float) float
decode(self, values: Values, default: None) Poly

Equivalent to evaluate(). decode decode

This method is deprecated since Amplify v1.0.0 and will be removed in a future version. Please see the migration guide for details: https://amplify.fixstars.com/docs/amplify/v1/migration.html

Overload 1.

Args:
  • values (amplify.Values)

Returns:

float:

Overload 2.

Args:
  • values (amplify.Values)

  • default (float)

Returns:

float:

Overload 3.

Args:
  • values (amplify.Values)

  • default (None)

Returns:

amplify.Poly:

degree(self) intΒΆ

Return the degree of the polynomial.

Return type:

int

evaluate(self, values: Values) floatΒΆ
evaluate(self, values: Values, default: float) float
evaluate(self, values: Values, default: None) Poly

Evaluate the polynomial by substituting variables using the given values. evaluate evaluate

This method is usually used to obtain optimization results in array form.

If the keyword argument default is not specified, variables that are not specified in values will be substituted by a reasonable default value.

If the keyword argument default is specified with a float value, variables that are not specified in values will be substituted by that value.

If the keyword argument default is specified with None, variables that are not specified in values will remain as symbolic variables without substitution.

Overload 1.

Args:
  • values (amplify.Values): Values obtained from optimization results, e.g. result.best.values.

Returns:

float:

Overload 2.

Args:
  • values (amplify.Values): Values that can be obtained from optimization results, e.g. result.best.values.

  • default (float): The default value for variables not specified in values.

Returns:

float:

Overload 3.

Args:
  • values (amplify.Values): Values obtained from optimization results, e.g. result.best.values.

  • default (None): Set to None to keep variables not specified in values symbolic.

Returns:

amplify.Poly:

is_linear(self) boolΒΆ

Return True if the polynomial is linear.

Return type:

bool

is_number(self) boolΒΆ

Return True if the polynomial is a constant polynomial.

Return type:

bool

is_quadratic(self) boolΒΆ

Return True if the polynomial is quadratic.

Return type:

bool

is_variable(self) boolΒΆ

Return True if the polynomial represents a single variable.

Return type:

bool

substitute(
self,
mapping: Mapping[Poly, Poly | float | int] | Mapping[Variable, Poly | float | int],
) PolyΒΆ

Assign numbers or other polynomials to variables in the polynomial.

Parameters:

mapping (Mapping[Poly, Poly | float | int] | Mapping[Variable, Poly | float | int]) – Key-value pairs of variables and replacement values. Each value can be a number or another polynomial.

Return type:

Poly

property idΒΆ

Variable ID. Only valid for polynomials that represent a single variable.

Return type:

int

property lower_boundΒΆ

Lower bound of the variable. Only valid for polynomials that represent a single variable.

Return type:

float | None

property nameΒΆ

Variable name. Only valid for polynomials that represent a single variable.

Return type:

str

property typeΒΆ

Variable type. Only valid for polynomials that represent a single variable.

Return type:

VariableType

property upper_boundΒΆ

Upper bound of the variable. Only valid for polynomials that represent a single variable.

Return type:

float | None

property variablesΒΆ

List of all variables in the polynomial.

Return type:

list[Variable]