mimiqcircuits.complex¶
Classes
|
Sum z-variables and a constant, and assign the result to the first z-variable. |
|
Multiply z-variables and a constant, and assign the result to the first z-variable. |
|
Raise a z-variable to a power in place: |
- class Pow(exponent)[source]¶
Bases:
OperationRaise a z-variable to a power in place:
z[i] = z[i]^exponent.Acts on one z-variable.
Pow(1)does nothing and emits a warning.- Parameters:
exponent – The exponent, a number.
Examples
>>> from mimiqcircuits import * >>> Pow(-1) z[?] = z[?]^(-1) >>> c = Circuit() >>> c.push(Pow(2), 1) 2-zvar circuit with 1 instruction: └── z[1] = z[1]^2
- class Add(N=1, c=0.0)[source]¶
Bases:
OperationSum z-variables and a constant, and assign the result to the first z-variable.
The operation acts on
Nz-variables: the first is the destination, the remainingN-1are the inputs. The destination is overwritten:z[0] = c + z[1] + ... + z[N-1].To accumulate into the destination instead, pass it again as one of the inputs (z-variable aliasing is allowed for
Add): for examplec.push(Add(3), 0, 0, 1)evaluatesz[0] = z[0] + z[1].- Parameters:
N (int) – Number of z-variables, destination included. At least 1. Defaults to
1.c – Constant term. Defaults to
0.0.
- Raises:
ValueError – If
Nis less than 1.
Examples
>>> from mimiqcircuits import * >>> Add(1) z[?0] = 0.0 >>> Add(1,c=1) z[?0] = 1 >>> Add(3,1) z[?0] = 1 + z[?1] + z[?2] >>> Add(4, c=3) z[?0] = 3 + z[?1] + z[?2] + z[?3] >>> c = Circuit() >>> c.push(Add(2), 1, 2) 3-zvar circuit with 1 instruction: └── z[1] = 0.0 + z[2] >>> c = Circuit() >>> c.push(Add(3), 0, 0, 1) # accumulate via aliasing 2-zvar circuit with 1 instruction: └── z[0] = 0.0 + z[0] + z[1]
- class Multiply(N=1, c=1.0)[source]¶
Bases:
OperationMultiply z-variables and a constant, and assign the result to the first z-variable.
The operation acts on
Nz-variables: the first is the destination, the remainingN-1are the inputs. The destination is overwritten:z[0] = c * z[1] * ... * z[N-1].To accumulate into the destination instead, pass it again as one of the inputs (z-variable aliasing is allowed for
Multiply): for examplec.push(Multiply(3), 0, 0, 1)evaluatesz[0] = z[0] * z[1].- Parameters:
N (int) – Number of z-variables, destination included. At least 1. Defaults to
1.c – Constant factor. Defaults to
1.0.
- Raises:
ValueError – If
Nis less than 1.
Examples
>>> from mimiqcircuits import * >>> Multiply(1) z[?0] = 1.0 >>> Multiply(3) z[?0] = 1.0 * z[?1] * z[?2] >>> Multiply(3, c=2) z[?0] = 2 * z[?1] * z[?2] >>> Multiply(2,2) z[?0] = 2 * z[?1] >>> c = Circuit() >>> c.push(Multiply(2), 1, 2) 3-zvar circuit with 1 instruction: └── z[1] = 1.0 * z[2] >>> c = Circuit() >>> c.push(Multiply(3), 0, 0, 1) # accumulate via aliasing 2-zvar circuit with 1 instruction: └── z[0] = 1.0 * z[0] * z[1]