mimiqcircuits.classical.xor_operation

Classes

Xor([N])

Bitwise XOR of classical bits, written to a classical bit.

class Xor(N=3)[source]

Bases: AbstractClassical

Bitwise XOR of classical bits, written to a classical bit.

Xor(N) acts on N bits: the first is the destination and the other N - 1 are the inputs. The destination is set to the parity of the inputs: 1 if an odd number of them is 1. The destination may also be one of the inputs, which updates it in place.

Parameters:

N (int) – Total number of bits, destination included. At least 3; defaults to 3.

Raises:

ValueError – If N is less than 3.

Examples

>>> from mimiqcircuits import *
>>> # placeholders show the destination ?0 and the inputs
>>> Xor()
c[?0] = c[?1] ^ c[?2]
>>> Xor(8)
c[?0] = ^ @ c[?1:?7]
>>> # c[0] = c[2] ^ c[3]
>>> c = Circuit()
>>> c.push(Xor(), 0, 2, 3)
4-bit circuit with 1 instruction:
└── c[0] = c[2] ^ c[3]

>>> c = Circuit()
>>> c.push(Xor(5), 0, 1, 2, 3, 4)
5-bit circuit with 1 instruction:
└── c[0] = c[1] ^ c[2] ^ c[3] ^ c[4]

>>> c = Circuit()
>>> c.push(Xor(8), 0, 1, 2, 3, 4, 5, 6, 7)
8-bit circuit with 1 instruction:
└── c[0] = ^ @ c[1, 2, 3, 4, 5, 6, 7]
__init__(N=3)[source]

Create an Xor on N bits: one destination and N - 1 inputs.

Raises:

ValueError – If N is less than 3.

iswrapper()[source]

Whether the operation wraps another operation.

True for composite operations such as Control, Power, Inverse, Parallel or IfStatement, False otherwise.

Returns:

bool

__repr__()[source]

Return the operation written with placeholder bits, such as c[?0].

__str__()[source]

Return the operator symbol, "^".

format_with_targets(qubits, bits, zvars)[source]

Return the operation written with the given target bits.