qrisp.q_div#

q_div(numerator, divisor, prec=None)[source]#

Performs division up to arbitrary precision and uncomputes the remainder.

Parameters:
numeratorQuantumFloat

The QuantumFloat to divide.

divisorQuantumFloat

The QuantumFloat to divide by.

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}\). By default, a suited precision will be determined from the other inputs.

Returns:
quotientQuantumFloat

The result of the division.

Examples

We calculate 10/8:

>>> from qrisp import QuantumFloat, q_div
>>> num = QuantumFloat(4)
>>> div = QuantumFloat(4)
>>> num[:] = 10
>>> div[:] = 8
>>> quotient = q_div(num, div, prec = 2)
>>> print(quotient)
{1.25: 1.0}