mimiqcircuits.classical¶
Classical operations and utilities.
- class SetBit0[source]¶
Bases:
AbstractClassicalSet a classical bit to 0, whatever its value.
Acts on one classical bit.
Examples
>>> from mimiqcircuits import * >>> SetBit0().name 'set0' >>> # set bit 1 to 0 >>> c = Circuit() >>> c.push(SetBit0(), 1) 2-bit circuit with 1 instruction: └── c[1] = 0
- inverse()[source]¶
Return
SetBit1().Setting a bit is not invertible; this pairing only mirrors the opposite operation.
- class SetBit1[source]¶
Bases:
AbstractClassicalSet a classical bit to 1, whatever its value.
Acts on one classical bit.
Examples
>>> from mimiqcircuits import * >>> SetBit1().name 'set1' >>> # set bit 1 to 1 >>> c = Circuit() >>> c.push(SetBit1(), 1) 2-bit circuit with 1 instruction: └── c[1] = 1
- inverse()[source]¶
Return
SetBit0().Setting a bit is not invertible; this pairing only mirrors the opposite operation.
- class Not[source]¶
Bases:
AbstractClassicalFlip a classical bit:
0 → 1and1 → 0.Acts on one classical bit. It is its own inverse.
Examples
>>> from mimiqcircuits import * >>> Not().name '!' >>> # flip bit 1 >>> c = Circuit() >>> c.push(Not(), 1) 2-bit circuit with 1 instruction: └── c[1] = !c[1]
- class And(N=3)[source]¶
Bases:
AbstractClassicalBitwise AND of classical bits, written to a classical bit.
And(N)acts onNbits: the first is the destination and the otherN - 1are the inputs. The destination is set to 1 only if all inputs are 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
Nis less than 3.
Examples
>>> from mimiqcircuits import * >>> # placeholders show the destination ?0 and the inputs >>> And() c[?0] = c[?1] & c[?2] >>> And(8) c[?0] = & @ c[?1:?7] >>> # c[0] = c[2] & c[3] >>> c = Circuit() >>> c.push(And(), 0, 2, 3) 4-bit circuit with 1 instruction: └── c[0] = c[2] & c[3] >>> c = Circuit() >>> c.push(And(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(And(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 And on
Nbits: one destination andN - 1inputs.- Raises:
ValueError – If
Nis less than 3.
- class Or(N=3)[source]¶
Bases:
AbstractClassicalBitwise OR of classical bits, written to a classical bit.
Or(N)acts onNbits: the first is the destination and the otherN - 1are the inputs. The destination is set to 1 if at least one input 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
Nis less than 3.
Examples
>>> from mimiqcircuits import * >>> # placeholders show the destination ?0 and the inputs >>> Or() c[?0] = c[?1] | c[?2] >>> Or(8) c[?0] = | @ c[?1:?7] >>> # c[0] = c[2] | c[3] >>> c = Circuit() >>> c.push(Or(), 0, 2, 3) 4-bit circuit with 1 instruction: └── c[0] = c[2] | c[3] >>> c = Circuit() >>> c.push(Or(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(Or(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 Or on
Nbits: one destination andN - 1inputs.- Raises:
ValueError – If
Nis less than 3.
- class Xor(N=3)[source]¶
Bases:
AbstractClassicalBitwise XOR of classical bits, written to a classical bit.
Xor(N)acts onNbits: the first is the destination and the otherN - 1are 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
Nis 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
Nbits: one destination andN - 1inputs.- Raises:
ValueError – If
Nis less than 3.
- class ParityCheck(N=3)[source]¶
Bases:
objectDeprecated alias of
Xor.ParityCheck(N)returnsXor(N), which computes the same parity of N-1 classical bits into the first bit, and emits aDeprecationWarning. No object is ever an instance ofParityCheck.Examples
>>> import warnings >>> from mimiqcircuits import * >>> with warnings.catch_warnings(): ... warnings.simplefilter("ignore", DeprecationWarning) ... ParityCheck(5) c[?0] = c[?1] ^ c[?2] ^ c[?3] ^ c[?4]
Modules