qrisp.cuccaro_adder#

cuccaro_adder(a: int | QuantumVariable, b: QuantumVariable, c_in: QuantumBool | Qubit | None = None, c_out: QuantumBool | Qubit | None = None, ctrl: QuantumBool | None = None) None[source]#

In-place adder as introduced in https://arxiv.org/abs/quant-ph/0410184

This function works in both static and dynamic modes. The allowed inputs are both quantum types or one classical type and one quantum type. Note that when the first input is larger than the second input, the function will perform modulo addition (relative to the size of the second input) after the first input is truncated to be the same size as the second input.

The custom control implementation is based on Theorem 2.12 of https://arxiv.org/abs/2407.20167

Note

If the first input is quantum and the second classical, the function cannot work as addition is performed “in-place” on the second input.

Parameters:
aint or QuantumVariable

The value that should be added.

bQuantumVariable or list[Qubit]

The value that should be modified in the in-place addition.

c_inQuantumBool or Qubit, optional

An optional carry in value. The default is None.

c_outQuantumBool or Qubit, optional

An optional carry out value. The default is None.

Returns:
None

The function modifies the second input in place.

Raises:
TypeError

If carry in or carry out is not of type QuantumBool or Qubit in static mode.

ValueError

If the inputs are not valid quantum or classical types.

Examples

Static mode with both quantum inputs:

>>> from qrisp import QuantumFloat, cuccaro_adder
>>> a = QuantumFloat(4)
>>> b = QuantumFloat(4)
>>> a[:] = 4
>>> b[:] = 5
>>> cuccaro_adder(a,b)
>>> print(b)
{9: 1.0}