Skip to content
Construct PsiQDK Workbench

Reference: Modular Addition Qubricks

ModularAdd

ModularAdd(adder_qubrick=None, **kwargs)

Bases: Qubrick

Modular addition: computes dst = (dst + rhs) % M, where M is a positive integer.

dst must store a value less than M.

rhs as type QUInt, QInt, and Qubits must store a value less than M. As type QInt, rhs must also store a value greater than -M. If rhs is of type int, it can store any value.

While this was implemented independently, it ended up similar to the one described in "How to compute a 256-bit elliptic curve private key with only 50 million Toffoli gates" (https://arxiv.org/abs/2306.08585 ⧉).

Parameters:

Name Type Description Default
adder_qubrick Qubrick or None

Qubrick to perform internal additions. Defaults to GidneyAdd.

None

compute

compute(
    dst: QUInt,
    rhs: QInt | int,
    M: int,
    ctrl: Qubits | None = None,
)

Computes dst = (dst + rhs) % M.

Parameters:

Name Type Description Default
dst QUInt

Register to add the number to.

required
rhs QUInt | QInt | int

The number to add to dst.

required
M int

The modulo used for modular addition.

required
ctrl Qubits | None

Optional quantum control.

None
Note
  • dst is unsigned, and must store a value less than M.
  • If rhs is a QInt or QUInt, it must store values less than M.
  • If rhs is a QInt, it must store a value greater than -M.
  • If rhs is an int, it may store any value.