# openfermion.ops.BinaryPolynomial

The BinaryPolynomial class provides an analytic representation of non-linear binary functions.

### Used in the notebooks

Used in the tutorials

An instance of this class describes a term of binary variables (variables of the values {0,1}, indexed by integers like w0, w1, w2 and so on) that is considered to be evaluated modulo 2. This implies the following set of rules:

the binary addition w1 + w1 = 0, binary multiplication w2 * w2 = w2 and power rule w3 ^ 0 = 1, where raising to every other integer power than zero reproduces w3.

Of course, we can also add a non-trivial constant, which is 1. Due to these binary rules, every function available will be a multinomial like e.g.

1 + w1 w2 + w0 w1 .

These binary functions are used for non-linear binary codes in order to decompress qubit bases back into fermion bases. In that instance, one BinaryPolynomial object characterizes the occupation of single orbital given a multi-qubit state in configuration |w0> |w1> |w2> ... .

For initialization, the preferred data types is either a string of the multinomial, where each variable and constant is to be well separated by a whitespace, or in its native form of tuples, 1 + w1 w2 + w0 w1 is represented as [(_SYMBOLIC_ONE,),(1,2),(0,1)]

After initialization,BinaryPolynomial terms can be manipulated with the overloaded signs +, * and ^, according to the binary rules mentioned.

.. code-block:: python

bin_fun = BinaryPolynomial('1 + w1 w2 + w0 w1')

# Equivalently

bin_fun = BinaryPolynomial(1) + BinaryPolynomial([(1,2),(0,1)])

# Equivalently

bin_fun = BinaryPolynomial([(_SYMBOLIC_ONE,),(1,2),(0,1)])

`term` `str, list, tuple`

used for initializing a BinaryPolynomial

`ValueError` when term is not a string,list or tuple

`terms` `list`

a list of tuples. Each tuple represents a summand of the BinaryPolynomial term and each summand can contain multiple tuples representing the factors.

## Methods

### `enumerate_qubits`

View source

Enumerates all qubits indexed in a given BinaryPolynomial.

Returns (list): a list of qubits

### `evaluate`

View source

Evaluates a BinaryPolynomial

Args
`binary_list` `list, array, str`

a list of binary values corresponding each binary variable (in order of their indices) in the expression

Returns (int, 0 or 1): result of the evaluation

Raises
`BinaryPolynomialError` Length of list provided must match the number of qubits indexed in BinaryPolynomial

### `identity`

View source

Returns: multiplicative_identity (BinaryPolynomial): A symbolic operator u with the property that ux = xu = x for all operators x of the same class.

### `shift`

View source

Shift all qubit indices by a given constant.

Args
`const` `int`

the constant to shift the indices by

Raises
`TypeError` const must be integer

### `zero`

View source

Returns: additive_identity (BinaryPolynomial): A symbolic operator o with the property that o+x = x+o = x for all operators x of the same class.

### `__add__`

View source

Args
`addend` `int or BinaryPolynomial`

The operator or int to add.

Returns
`sum` `BinaryPolynomial`

the sum of terms

### `__mul__`

View source

Return self * multiplier for int, or a BinaryPolynomial.

Args
multiplier (int or BinaryPolynomial): the multiplier of the BinaryPolynomial object

Returns
`product` `BinaryPolynomial`

result of the multiplication

Raises
`TypeError` Invalid type cannot be multiply with BinaryPolynomial.

### `__pow__`

View source

Exponentiate the BinaryPolynomial.

Args
`exponent` `int`

The exponent with which to raise the operator.

Returns
`exponentiated` `BinaryPolynomial`

Exponentiated symbolicBinary

Raises
`TypeError` Can only raise BinaryPolynomial to non-negative integer powers.

### `__radd__`

View source

Method for right addition to BinaryPolynomial.

Args
`addend` `int or BinaryPolynomial`

Returns
`sum` `BinaryPolynomial`

the sum of terms

Raises
`TypeError` Cannot add invalid type.

### `__rmul__`

View source

Return multiplier * self for a scalar or BinaryPolynomial.

Args
`multiplier` `int or BinaryPolynomial`

the multiplier of the BinaryPolynomial object

Returns
`product` `BinaryPolynomial`

A new instance of BinaryPolynomial.

Raises
`TypeError` Object of invalid type cannot multiply BinaryPolynomial.

[{ "type": "thumb-down", "id": "missingTheInformationINeed", "label":"Missing the information I need" },{ "type": "thumb-down", "id": "tooComplicatedTooManySteps", "label":"Too complicated / too many steps" },{ "type": "thumb-down", "id": "outOfDate", "label":"Out of date" },{ "type": "thumb-down", "id": "samplesCodeIssue", "label":"Samples / code issue" },{ "type": "thumb-down", "id": "otherDown", "label":"Other" }]
[{ "type": "thumb-up", "id": "easyToUnderstand", "label":"Easy to understand" },{ "type": "thumb-up", "id": "solvedMyProblem", "label":"Solved my problem" },{ "type": "thumb-up", "id": "otherUp", "label":"Other" }]
{"lastModified": "Last updated 2024-04-26 UTC."}