qrisp.q_divmod#

q_divmod(numerator, divisor, adder='thapliyal', prec=0)[source]#

Performs division up to arbitrary precision. Returns the quotient and the remainder.

Parameters:
numeratorQuantumFloat

The QuantumFloat to divide.

divisorQuantumFloat

The QuantumFloat to divide by.

adderstr, optional

The type of adder to use. Available are “thapliyal” and “cuccarro”. The default is “thapliyal”.

precint, optional

The precision of the division. If the precision is set to \(k\), the approximated quotient \(q_{apr}\) and the true quotient \(q_{true}\) satisfy \(|q_{apr} - q_{true}|<2^{-k}\). The default is 0.

Returns:
quotientQuantumFloat

The approximated quotient.

remainderQuantumFloat

The remainder which satisfying \(q*d + r = n\).

Examples

We calculate 10/8 with varying precision:

>>> from qrisp import QuantumFloat, q_divmod, multi_measurement
>>> num = QuantumFloat(4)
>>> div = QuantumFloat(4)
>>> num[:] = 10
>>> div[:] = 8
>>> quotient, remainder = q_divmod(num, div, prec = 1)
>>> multi_measurement([quotient, remainder])
{(1.0, 2.0): 1.0}

Now with higher precision

>>> num = QuantumFloat(4)
>>> div = QuantumFloat(4)
>>> num[:] = 10
>>> div[:] = 8
>>> quotient, remainder = q_divmod(num, div, prec = 3)
>>> multi_measurement([quotient, remainder])
{(1.25, 0.0): 1.0}