mimiqcircuits.complex

Classes

Add([N, c])

Sum z-variables and a constant, and assign the result to the first z-variable.

Multiply([N, c])

Multiply z-variables and a constant, and assign the result to the first z-variable.

Pow(exponent)

Raise a z-variable to a power in place: z[i] = z[i]^exponent.

class Pow(exponent)[source]

Bases: Operation

Raise 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
inverse()[source]

Raise TypeError, as other non-invertible operations do.

\(z \mapsto z^p\) has no inverse in general: \((-1)^2 = 1^2\).

iswrapper()[source]

Return False.

class Add(N=1, c=0.0)[source]

Bases: Operation

Sum z-variables and a constant, and assign the result to the first z-variable.

The operation acts on N z-variables: the first is the destination, the remaining N-1 are 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 example c.push(Add(3), 0, 0, 1) evaluates z[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 N is 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]
iswrapper()[source]

Return False.

class Multiply(N=1, c=1.0)[source]

Bases: Operation

Multiply z-variables and a constant, and assign the result to the first z-variable.

The operation acts on N z-variables: the first is the destination, the remaining N-1 are 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 example c.push(Multiply(3), 0, 0, 1) evaluates z[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 N is 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]
iswrapper()[source]

Return False.