qrisp.qf_inversion#

qf_inversion(qf, prec=None)[source]#

Calculates the multiplicative inverse of a QuantumFloat.

Parameters:
qfQuantumFloat

The QuantumFloat to invert.

precint, optional

The precision of the inversion. If the precision is set to \(k\), the approximated inverse \(q_{apr}\) and the true inverse \(q_{true}\) satisfy \(|q_{res} - q_{true}|<2^{-k}\). By default, a suited precision will be determined from the other input.

Returns:
resultQuantumFloat

A QuantumFloat containing the inverse.

Examples

We calculate the inverse of 0.75

>>> from qrisp import QuantumFloat, qf_inversion
>>> qf = QuantumFloat(2, -2)
>>> qf[:] = 0.75
>>> qf_inv = qf_inversion(qf, prec = 4)
>>> print(qf_inv)
{1.3125: 1.0}
>>> 0.75**-1
1.3333333333333333