qrisp.QuantumModulus.inpl_mult#
- QuantumModulus.inpl_mult(factor: int | np.integer | Array | BigInteger, inverse: int | np.integer | Array | BigInteger | None = None) QuantumModulus[source]#
Multiply the register in place by a classical factor, optionally with its precomputed inverse.
qm.inpl_mult(X)is the same asqm *= X. To uncompute a temporary register, the in-place multiplication also multiplies by the inverse of \(X\) modulo \(N\), and computing this inverse is its most expensive classical step. If the inverse is known in advance, for example for the powers \(a^{2^i}\) of Shor’s algorithm, passing it skips this computation. The circuit is the same.- Parameters:
- factorint, Array or BigInteger
The classical factor \(X\), coprime to the modulus. NumPy integers are accepted as well.
- inverseint, Array or BigInteger, optional
The inverse of \(X\) modulo \(N\). It is not checked. The default is None, which computes it.
- Returns:
- QuantumModulus
The register, multiplied in place.
- Raises:
- TypeError
If the factor or the inverse is not a classical integer.
Examples
Multiply by 7 modulo 15, whose inverse modulo 15 is 13:
>>> from qrisp import QuantumModulus >>> qm = QuantumModulus(15) >>> qm[:] = 2 >>> qm = qm.inpl_mult(7, inverse=13) >>> print(qm) {14: 1.0}