Integer square roots with fewer Toffoli gates
Reduce the Toffoli cost of exact integer square roots, a building block of reversible numerical functions.
Verifier
The verifier checks your file and computes its score. QArena runs the same code on every submission.
Verifications of this board run on the first lane of this list that is up and has room: the Mac mini, then CU Boulder's Alpine, then NCAR Derecho, then RunPod. A lane that is down, full or slow passes the file to the next one automatically, with the same verifier version; the limits of one verification are 120 s of CPU, 300 s of wall time and 512 MB of memory on the Mac mini, and 240 s of CPU, 480 s of wall time and 512 MB of memory on CU Boulder's Alpine, NCAR Derecho and RunPod (2 times the board's own CPU and wall time on the other lanes, because their processors are slower); the result goes to QArena only.
Download the bundle, extract it and run these commands from its folder (the one holding verifiers/). The bundle
includes an accepted example file.
python3 -I verifiers/run_one.py intsqrt isqrt-n20-a20 example/isqrt-n20-a20.json
The verifier prints one line of JSON with a status: accepted with the score, rejected with the reason,
or error if verification could not finish.
Files
| File | Role |
|---|---|
| run_one.py | Runs the verifier |
| common.py | Shared helpers |
| intsqrt.py | Validates submissions for this problem |
How verification works
The verifier runs your circuit on all 2^n inputs at once. Each wire holds one bit per input, packed into one long integer, so a gate is one XOR over all inputs, preceded by an AND for a Toffoli gate. It then checks, for every input, that the input wires are unchanged, that the root wires hold floor(√x) (from Python's exact integer square root, never floating point) and that every workspace wire is back to zero. X, CNOT and Toffoli gates permute basis states without adding phases, so this check proves that the circuit computes the square root exactly on any superposition of inputs. On the -mx instances the verifier also follows every measurement sign exactly, as on constant-add: a measurement multiplies the state by (-1) to the power (outcome times the measured value), and each sign must end up the same for every input, so every outcome leaves the same correct result. A second, independently written program, which keeps one byte per input and wire and decides correctness by the inequalities y² ≤ x < (y+1)², agreed with the verifier on all 66,404 random and adversarial files of the cross-check.