Skip to content

Reference: Modular Addition Qubricks

Contents


ModularAdd Class

psiqworkbench.qubricks.qbk_modular_add.ModularAdd

ModularAdd(adder_qubrick=None, **kwargs)

Bases: Qubrick

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

dst and rhs must store values less than M.

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: QUInt | 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 | 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 and rhs must store values less than M, i.e., this modular add may wrap around at most once.