The BinaryPolynomial class provides an analytic representation
openfermion.ops.BinaryPolynomial(
term=None
)
Used in the notebooks
of non-linear binary functions. 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.
Example:
.. 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)])
Args |
term (str, list, tuple): used for initializing a BinaryPolynomial
|
Raises |
ValueError
|
when term is not a string,list or tuple
|
Methods
enumerate_qubits
View source
enumerate_qubits()
Enumerates all qubits indexed in a given BinaryPolynomial.
Returns (list): a list of qubits
evaluate
View source
evaluate(
binary_list
)
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
@classmethod
identity()
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(
const
)
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
@classmethod
zero()
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
__add__(
addend
)
Left addition of BinaryPolynomial.
Args |
addend (int or BinaryPolynomial): The operator or int to add.
|
Returns |
sum (BinaryPolynomial): the sum of terms
|
__mul__
View source
__mul__(
multiplier
)
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
__pow__(
exponent
)
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
__radd__(
addend
)
Method for right addition to BinaryPolynomial.
Args |
addend (int or BinaryPolynomial): The operator to add.
|
Returns |
sum (BinaryPolynomial): the sum of terms
|
Raises |
TypeError
|
Cannot add invalid type.
|
__rmul__
View source
__rmul__(
multiplier
)
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.
|