back to the dreu folder

Manual for the Regev-Style Circuit and Lattice Post-Processing Repository

Repository: simransummermalik/TheoreticalComputing

Author: Summer Malik, with research collaborators Carolina Amorim and Owen Barnes

Purpose: This manual explains the project from the beginning, defines the mathematical objects, walks through the full quantum-to-classical pipeline, explains what the experiments found, and gives commands for testing and reproducing the repository.

Scope note: This repository does not factor cryptographically large integers and does not claim a new general factoring algorithm. It implements, audits, and tests a finite Regev-style research pipeline on small controlled instances.


Contents

  1. Introduction
  2. How to read this manual
  3. The project in one page
  4. What factoring is
  5. How Shor and Regev fit into the story
  6. The complete pipeline
  7. Symbols used throughout the project
  8. Roots, squared bases, and why provenance matters
  9. The modular-product map
  10. The exponent state and the four sampling models
  11. Reversible modular arithmetic
  12. The multidimensional quantum Fourier transform
  13. Exact and approximate QFTs
  14. Measurement and decoding
  15. Building the augmented lattice
  16. What LLL does
  17. The relation lattices L and L0
  18. How a recovered relation becomes a factor
  19. The finite-shot QFT certificate
  20. The current certification-gap result
  21. Negative results that the repository keeps
  22. Research timeline
  23. Repository layout
  24. Python module reference
  25. Script reference
  26. Installation and setup
  27. Running the tests
  28. Reproducing the current result
  29. Running earlier studies
  30. How to read the outputs
  31. Common problems
  32. How to extend the project without invalidating it
  33. What is verified, what is not, and how claims are labeled
  34. Glossary
  35. Primary references

1. Introduction

This repository began with a Qiskit notebook inspired by Regev's quantum factoring algorithm. The notebook could construct multidimensional quantum circuits and produce samples, but the research question was larger than simply making a circuit run.

A complete factoring pipeline needs both a quantum stage and a classical stage. The quantum circuit produces structured Fourier samples. Those samples must then be converted into an integer lattice, reduced, interpreted as modular relations, classified, and finally tested for factor extraction.

The repository therefore became an audit and reconstruction project. It asks:

The repository now contains circuit construction, exact finite sampling laws, lattice construction, LLL recovery, relation verification, factor extraction, noise and QFT models, frozen experimental protocols, adversarial audits, statistical analysis, and reproducible outputs.

Back to contents

2. How to read this manual

The manual moves from the outside of the project toward the inside.

First, it explains factoring and the overall pipeline. Then it defines the mathematical objects used by the code. After that, it follows one sample through the entire system: roots, circuit bases, state preparation, modular exponentiation, QFT, measurement, lattice construction, LLL, relation classification, and factor extraction.

The later sections explain the current research result, the negative results, the repository structure, and the commands used to test or reproduce the work.

A reader who only wants the main idea can read:

A reader who wants to run the code can skip to:

Back to contents

3. The project in one page

Factoring means taking a composite integer and finding smaller integers whose product equals it. For example:

15 = 3 × 5
  

Regev's algorithm is a quantum factoring approach that uses several exponent registers and a substantial classical lattice-reduction stage. The quantum computer does not directly print the factors. It produces measurements containing information about hidden multiplicative relations.

This repository implements and audits a finite version of that idea:

choose N and roots
      ↓
square the roots to obtain circuit bases
      ↓
prepare several exponent registers
      ↓
compute modular products in superposition
      ↓
apply a QFT to every exponent register
      ↓
measure Fourier vectors
      ↓
build an augmented integer lattice
      ↓
run LLL
      ↓
verify candidate relations
      ↓
separate useful relations from useless relations
      ↓
attempt gcd factor extraction
  

The current main research question concerns QFT precision. An exact QFT uses every controlled phase rotation. An approximate QFT omits some of the smallest rotations to reduce gate count.

A conservative worst-case certificate used by the project refused to approve any approximation in the frozen five-percent regime. However, a later held-out experiment found that limited truncation could preserve the actual lattice-recovery endpoint in the tested finite models.

The main conclusion is not that approximate QFT is always safe. The conclusion is narrower:

In the tested small finite regime, the worst-case certificate required more precision than the prepared-state lattice-recovery endpoint actually needed.

Back to contents

4. What factoring is

An integer is prime when its only positive divisors are one and itself. Examples include 2, 3, 5, 7, and 11.

An integer is composite when it can be written as a product of smaller positive integers. For example:

21 = 3 × 7
35 = 5 × 7
77 = 7 × 11
  

The factoring problem asks us to recover those smaller factors when only the product is given.

Small examples are easy. The cryptographic difficulty comes from very large integers chosen so that ordinary classical factoring methods require too much time.

The project uses small semiprimes because the goal is not to break cryptography. The goal is to inspect the algorithmic structure, verify the implementation, and measure finite behavior in a controlled environment.

Back to contents

5. How Shor and Regev fit into the story

Shor's approach

Shor's algorithm reduces factoring to an order-finding problem. A quantum circuit creates a periodic state, and a quantum Fourier transform helps expose the period. Classical continued fractions and greatest-common-divisor calculations then convert the period into factors.

Regev's approach

Regev proposed a different factoring construction. Instead of relying on one long exponent register, the method distributes the exponent information across several registers. The quantum stage produces multiple high-dimensional Fourier samples. The classical stage then uses lattice reduction to recover a useful multiplicative relation.

The trade is important:

This repository is Regev-style rather than a complete full-scale implementation of every asymptotic component in Regev's paper. It works with small finite states and clearly labels the difference between notebook surrogates, finite Gaussian models, and theorem-consistent synthetic models.

Back to contents

6. The complete pipeline

Input: an odd composite integer N

1. Choose stored roots b1, ..., bd.
2. Compute squared circuit bases:
       ai = bi² mod N
3. Prepare d exponent registers.
4. Place the exponent registers in superposition.
5. Reversibly compute:
       hA(x) = product ai^xi mod N
6. Apply one QFT or inverse QFT to each exponent register.
7. Measure m Fourier vectors.
8. Decode the Qiskit bitstrings into ordered integer vectors.
9. Convert the vectors into an exact augmented integer lattice.
10. Run LLL on that lattice.
11. Extract candidate integer relations z.
12. Verify:
       product ai^zi = 1 mod N
13. Compute the stored-root product:
       beta = product bi^zi mod N
14. If beta is neither +1 nor -1 modulo N, try:
       gcd(beta - 1, N)
       gcd(beta + 1, N)
15. Validate any returned factor pair.
  

Each step has a different correctness condition. A circuit can run successfully while the bit order is wrong. LLL can return a short vector that is not an exact modular relation. A relation can be valid but useless for factoring. A gcd can return one or N instead of a proper factor.

The repository therefore checks every boundary instead of treating the pipeline as one black box.

Back to contents

7. Symbols used throughout the project

Symbol Meaning
N The odd composite integer being factored.
n The bit length of N. It is not the same as N.
d The number of roots, circuit bases, exponent registers, and relation coordinates.
nd The number of qubits in each exponent register.
M The Fourier modulus. If a register has nd qubits, then M = 2^nd.
q Another notation for log2(M), the number of qubits in one Fourier register.
m The number of Fourier samples passed to classical recovery.
bi A stored modular root used later in factor extraction.
ai The squared circuit base ai = bi² mod N.
x An exponent vector used by modular exponentiation.
k A measured Fourier outcome vector.
z A candidate integer multiplicative relation.
S The scaling factor used in the augmented lattice.
Delta The allowed loss in a downstream recovery-event probability.
t The approximate-QFT distance cutoff.
L The full lattice of exact multiplicative relations among the squared bases.
L0 The valid relations whose stored-root product is +1 or -1 and therefore gives no factor.

Back to contents

8. Roots, squared bases, and why provenance matters

The circuit uses squared bases:

ai = bi² mod N
  

The value bi is the stored root. The value ai is the base used by the modular-exponentiation circuit.

The distinction is essential. A modular number can have multiple square roots. If the code stores only ai and later guesses a root, it may use a different root than the one that generated the circuit base.

This repository avoids that error by keeping every pair (bi, ai) together in an immutable rooted-base object.

For example, modulo 15:

4² = 16 = 1 mod 15

gcd(4 - 1, 15) = gcd(3, 15) = 3
gcd(4 + 1, 15) = gcd(5, 15) = 5
  

The number 4 is a nontrivial square root of one modulo 15. It is not +1 or -1 modulo 15, so its two neighboring gcd calculations reveal the factors.

Setup factor leakage

A candidate root must be coprime to N. The code therefore checks gcd(bi, N). If that gcd is already a proper factor, the setup process has factored N classically.

The repository records this as a setup factor leak. It is not counted as a successful quantum sample-to-lattice recovery.

This prevents an easy classical discovery from being mislabeled as evidence that the quantum circuit or lattice decoder worked.

Back to contents

9. The modular-product map

Given an exponent vector:

x = (x1, x2, ..., xd)
  

define:

hA(x) = product over i of ai^xi mod N
  

Different exponent vectors can produce the same modular output. Those collisions are not an implementation accident. They are the arithmetic structure that later creates interference in the Fourier basis.

For a particular output y, define the fiber:

Fy = { x : hA(x) = y }
  

A fiber is simply the set of exponent vectors that all produce the same arithmetic result. During the QFT, phases from vectors inside the same fiber can add or cancel.

Back to contents

10. The exponent state and the four sampling models

The repository does not use one word such as “Regev samples” for every possible state model. It keeps four models separate because they answer different questions.

Model Definition What it is used for
A Exact finite uniform hard-box state. Reproduces the state prepared by the audited notebook.
B Exact finite truncated discrete-Gaussian amplitude state. Moves closer to Regev's intended Gaussian state preparation while remaining finite.
C Synthetic noisy dual-lattice samples satisfying a stated finite noise inequality. Tests the classical theorem-model endpoint. Generator-side oracle information is hidden from recovery.
D Hard-box samples with readout or whole-shot corruption. Provides an explicit corruption surrogate without calling it hardware noise.

Why model A and model B are not the same

A hard-box state assigns equal amplitude to every exponent vector inside a finite Cartesian box. A discrete-Gaussian state gives larger amplitudes near the center and smaller amplitudes farther away.

The two states can produce different Fourier laws and different lattice-recovery behavior. The repository therefore reports results by model instead of pooling them into one conclusion.

Why model C is different

Model C does not attempt to reproduce the entire quantum circuit. It generates samples that satisfy the geometric noisy-dual condition needed to test the classical reconstruction stage.

This lets the project ask whether the lattice endpoint behaves correctly when the theorem-style sample assumptions are deliberately satisfied.

Back to contents

11. Reversible modular arithmetic

A quantum circuit must be reversible. Ordinary programming operations often erase information, but a unitary quantum operation cannot simply discard an unknown input.

The circuit therefore uses reversible modular multiplication and modular exponentiation. Conceptually, it performs:

|x1, ..., xd>|1>|0>
        ↓
|x1, ..., xd>|product ai^xi mod N>|0>
  

The exponent registers are preserved. The modular result is written into a shared output register. Temporary ancilla qubits are used as workspace and should be returned to zero.

What the tests check

A circuit diagram with a high-level modular-exponentiation block can look shallow. After decomposition, that block expands into many elementary gates. This is why logical circuit depth and transpiled depth must not be confused.

Back to contents

12. The multidimensional quantum Fourier transform

Each exponent register receives its own one-dimensional QFT. The full transform is a tensor product:

FM ⊗ FM ⊗ ... ⊗ FM
  

There are d copies, one for each exponent register.

For the inverse-QFT convention used in the main pipeline, the phase associated with outcome k and exponent vector x is:

chi_k(x) = exp(-2πi <k,x> / M)
  

The inner product <k,x> combines all coordinates. This is why the measured outcome is a vector rather than one number.

Roots of unity

A root of unity is a complex phase that returns to one after an integer number of powers. QFT amplitudes are sums of these phases.

Inside one modular fiber, the exact probability law is:

P_A(k) = M^(-2d) × sum over y of
         | sum over x in Fy of chi_k(x) |²
  

If the phases align, they interfere constructively and increase the probability. If they point in opposing directions, they cancel.

This is the central reason that approximate-QFT error is structured. Omitting a controlled phase changes coherent phase sums before measurement. It is not automatically equivalent to randomly deleting or corrupting a few completed samples.

Forward versus inverse convention

A sign error changes the transform. A swap-order error changes qubit ordering. A classical-bit decoding error can make a correct quantum distribution appear wrong.

The repository validates the matrix convention directly against roots-of-unity matrices and Qiskit-generated matrices. It audits:

Back to contents

13. Exact and approximate QFTs

An exact q-qubit QFT includes:

q(q - 1) / 2
  

controlled-phase gates in one register.

Across d registers, the logical controlled-phase count is:

d × q(q - 1) / 2
  

Small-angle controlled rotations contribute to precision but also increase circuit size. An approximate QFT removes some of the smallest rotations.

The distance cutoff t

The repository uses a distance cutoff. A controlled phase is kept when the two qubits are separated by at most t positions.

The one-register sum of omitted phase angles is:

eta(q,t) = π × sum from r=t+1 to q-1 of (q-r)/2^r
  

This quantity enters the conservative error certificate.

Logical savings versus hardware savings

Removing controlled phases reduces the QFT gate count. That does not automatically prove a full program speedup.

Modular arithmetic dominates the full circuit, and a transpiler can decompose or optimize gates differently. The repository therefore labels:

Back to contents

14. Measurement and decoding

Qiskit displays classical bitstrings in an order that does not directly match the logical list of exponent registers.

The decoder must:

  1. remove spaces from the displayed bitstring;
  2. reverse the full displayed order when required by Qiskit's convention;
  3. split the bits into d chunks of nd bits;
  4. convert each register chunk into an integer;
  5. return an ordered vector:
k = (k1, k2, ..., kd)
  

A correct circuit paired with an incorrect decoder produces incorrect mathematical samples. The repository therefore tests the decoding contract instead of treating bit order as a display detail.

Back to contents

15. Building the augmented lattice

The measured Fourier rows are normalized:

wi = ki / M
  

If the rows are arranged into a matrix W, the rational augmented lattice has the block form:

B = [ I_d    0   ]
    [ S W   S I_m]
  

Here:

The lattice should be exact. Converting rational entries to floating-point values and rounding them can silently create a different lattice.

The implementation clears denominators exactly and passes an integer basis to LLL.

Why the lattice is augmented

The top block represents candidate relation coordinates. The bottom block records how well those coordinates agree with the measured Fourier rows after scaling.

A useful short vector should combine a small relation candidate with a small sample-consistency error.

Back to contents

16. What LLL does

LLL stands for Lenstra–Lenstra–Lovász lattice-basis reduction.

A lattice can be represented by many different bases. Some bases contain long, nearly dependent vectors and are hard to interpret. LLL transforms the basis into a shorter and better-conditioned basis.

LLL does not always return the mathematically shortest possible vector. It returns vectors that satisfy a polynomial-time approximation guarantee.

The primary endpoint uses exact integer LLL through SymPy. The implementation also checks the unimodular transformation:

transformation × original basis = reduced basis
  

If this identity fails, the reduced rows cannot be trusted as exact combinations of the original lattice basis.

Claim 5.1 stopping rule

The implementation evaluates the Regev-style Gram–Schmidt cutoff using exact rational arithmetic. This determines how much of the reduced basis belongs to the short-vector prefix considered by the recovery procedure.

This stopping rule is separate from “take the first LLL row and hope.” The repository records and checks the actual prefix condition.

Back to contents

17. The relation lattices L and L0

The full relation lattice is:

L = { z in Z^d :
      product ai^zi = 1 mod N }
  

A candidate vector is not accepted merely because it is short. The code computes the modular product and verifies exact membership in L.

The useless sublattice L0

For a verified relation z, compute:

beta = product bi^zi mod N
  

Because each ai is bi², a valid relation in L makes beta a square root of one modulo N.

If:

beta = +1 mod N
or
beta = -1 mod N
  

then the relation is valid but does not split N. These relations form L0.

A relation in:

L \ L0
  

has a nontrivial square root of one and can yield a proper factor.

Why valid does not mean useful

LLL may successfully recover a short exact relation that lies in L0. That is not an implementation failure. It is a valid arithmetic relation that happens to be useless for factoring.

This distinction motivated the quotient-deflation study described later in the manual.

Back to contents

18. How a recovered relation becomes a factor

After verifying z in L and computing beta, the code attempts:

p = gcd(beta - 1, N)
q = gcd(beta + 1, N)
  

A successful factor must satisfy:

1 < p < N
or
1 < q < N
  

If both factors are returned, the repository validates:

p × q = N
  

Known factors are not given to the recovery algorithm. They are stored separately and used only after a result is returned, so that the output can be checked.

The factor firewall

The code tries to prevent accidental use of the answer during recovery.

Back to contents

19. The finite-shot QFT certificate

The project derived a conservative bound connecting QFT approximation to a downstream recovery event.

Its dimensionless decision variable is:

B(d,M,m,t;Delta)
  = m × min(1, 2d × eta(q,t)) / Delta
  

The certificate approves a cutoff only when:

B ≤ 1
  

The variables mean:

The derived no-certificate condition is:

M < 4πdm / Delta
  

Under that condition, the implemented worst-case certificate cannot authorize even the first non-exact QFT cutoff.

What the certificate means

The certificate is a sufficient guarantee. If it approves a cutoff, the stated worst-case error budget is respected.

Failure to approve is not the same as proof of failure. The certificate may lose information when it replaces the actual prepared state, fiber structure, interference pattern, measurement, and recovery event with worst-case inequalities.

Back to contents

20. The current certification-gap result

The final frozen holdout used:

The experiment produced 12,288 raw endpoint trials.

What the original certificate selected

The original worst-case certificate approved zero omitted phase layers. In every tested configuration, it selected the exact QFT.

What the held-out recovery endpoint found

M Largest passing omission for hard-box model A Largest passing omission for finite-Gaussian model B
8 1 phase layer 1 phase layer
16 1 phase layer 2 phase layers
32 1 phase layer 2 phase layers

A cell passed only when both of the following approximate-minus-exact lower confidence bounds remained above the frozen -0.10 non-inferiority margin:

Resource effect

The largest passing cells saved:

These are not demonstrated full-device speedups. The modular arithmetic remains much larger than the QFT, and no hardware experiment was performed.

The conclusion

The exact-QFT decision made by the original worst-case certificate was mainly a limitation of that proof technique in this finite regime. It was not a necessary condition for the tested prepared-state lattice-recovery endpoint.

This conclusion is limited to the tested semiprimes, dimensions, Fourier sizes, sample count, state models, and current LLL decoder.

Back to contents

21. Negative results that the repository keeps

The repository intentionally preserves failed hypotheses. A negative result is useful when the experiment was frozen, the comparison was fair, and the claim boundary is clear.

Base-selection diversity

The first hypothesis was that selecting modular bases with greater bounded-product diversity would improve lattice recovery.

The relationship was model-dependent. It appeared negatively associated with recovery in the finite hard-box and Gaussian models and disappeared in the theorem-consistent noisy-dual model.

The repository therefore does not claim a general Regev base-selection improvement.

Quotient deflation and LDAR

Another hypothesis was that LLL wasted effort repeatedly finding short L0 relations. The project implemented exact quotient construction, verified deflation, adaptive resampling, bounded enumeration, and matched-cost baselines.

The complete method did not beat the matched reference on the frozen 20-modulus holdout. It was worse in models A, B, and D and tied in saturated model C.

The original five-percent adaptive selector

The selector was intended to choose a resource-saving approximate QFT while remaining inside a five-percent loss certificate.

It never selected a non-exact cutoff in the frozen grid. That positive selector hypothesis was falsified.

The later certification-gap experiment did not make the selector successful. It showed that the selector was too conservative relative to the finite endpoint.

Back to contents

22. Research timeline

Stage 1: reconstruct the original notebook

The project recovered the register sizes, imported arithmetic behavior, QFT conventions, measurement order, and circuit path. It identified the notebook state as a finite uniform box, not the full Gaussian state from Regev's formulation.

Stage 2: test dependency-aware base selection

A bounded diversity metric was implemented. The first evaluation was later recognized as circular because the selector and evaluator examined the same bounded relation region.

Stage 3: mandatory red-team revision

The revision permanently paired roots with bases, built the real augmented-lattice endpoint, separated the sampling models, added factor-blind controls, and ran held-out base-selection ablations.

Stage 4: quotient-aware recovery

The project tested whether quotienting or suppressing L0 directions would improve factor-bearing recovery. The positive hypothesis failed under the frozen budget.

Stage 5: first finite QFT/noise study

A small d=3, M=8 experiment showed that aggressive truncation damaged recovery, but the register was too small to support fine cutoff choices. The study was retained as background.

Stage 6: QFT precision scaling

The project derived the certificate-scaling law and evaluated a large analytic grid. The five-percent selector chose exact QFT everywhere.

Stage 7: certification-gap holdout

A theorem audit found and corrected a reversed gate-order bug in the custom approximate QFT. All affected rows were invalidated and regenerated. Sharper factor-blind certificates and an eight-semiprime held-out endpoint then measured the gap between theorem rejection and actual recovery.

Back to contents

23. Repository layout

regev_research/
    Python library modules for circuits, exact distributions,
    lattices, quotient methods, experiments, and certificates

scripts/
    Reproducible command-line entry points

tests/
    Unit, regression, matrix, arithmetic, lattice, and protocol tests

results/
    Frozen raw trials, aggregate summaries, bootstrap draws,
    completion records, and resource tables

figures/
    Generated plots from the original and red-team studies

external/
    Audited external reversible-arithmetic dependency

*.ipynb
    Original and generated executable notebooks

*.md
    Reports, theory notes, frozen protocols, and adversarial audits
  

The repository is designed so that implementation, frozen experiment configuration, raw output, statistical analysis, and written claims can be inspected separately.

Back to contents

24. Python module reference

Module Purpose
core.py Rooted-base objects, modular arithmetic, factor-blind relation diagnostics, exact hard-box Fourier law, and factor extraction.
circuits.py Qiskit circuit construction, exact or truncated product QFTs, and compiled resource reports.
qft_noise.py Roots-of-unity matrices, exact and approximate fiber laws, noise mappings, gate counts, and cutoff formulas.
qft_certificate.py Worst-case theorem decision, boundary checks, sharper state/distribution certificates, and proof-slack utilities.
dual.py Factor-blind exact relation-lattice construction for oracle-side validation and theorem-consistent noisy-dual sampling.
lattice.py Exact denominator clearing, augmented integer lattice, verified LLL transform, Claim-5.1 prefix, L/L0 classification, and factor endpoint.
redteam.py Exact finite sampling laws and the frozen rooted-base ablations.
redteam_experiments.py The 24-modulus, six-method, three-model red-team study with clustered inference.
quotient.py Exact integer quotient construction using HNF and SNF.
quotient_metrics.py Oracle-side relation and quotient diagnostics that are not passed to the recovery selector.
quotient_predictors.py Post-hoc joins and clustered predictor comparisons on frozen study rows.
quotient_recovery.py Bounded enumeration, quotient deduplication, L0 suppression, LDAR, BKZ comparisons, and matched baselines.
quotient_experiments.py Frozen quotient-study parameters and sample-model definitions.
quotient_study.py Checkpointed held-out execution and aggregation for the large quotient study.
rv_filter.py A finite structural comparator inspired by Ragavan–Vaikuntanathan, with unmet theorem assumptions reported explicitly.
experiments.py Superseded first-stage experiments retained for audit reproduction.
__init__.py Public imports for core rooted-base, lattice, quotient, and QFT utilities.

Back to contents

25. Script reference

Script What it runs
scripts/run_qft_certificate_gap.py The current eight-semiprime certification-gap holdout, sharper certificates, resources, comparisons, and figures.
scripts/run_qft_precision_scaling.py The earlier QFT certificate-scaling grid, matrix checks, feasible finite endpoints, and resource summaries.
scripts/run_qft_noise_experiment.py The superseded first finite QFT/noise experiment.
scripts/run_redteam.py The frozen base-selection red-team experiment.
scripts/run_quotient_study.py The expensive held-out quotient experiment.
scripts/analyze_quotient_study.py Reanalyzes the checked-in quotient trial table without rerunning recovery.
scripts/run_research.py The superseded first-stage analysis.
scripts/build_revised_notebook.py Builds the revised executable notebook from one Python source.
scripts/execute_revised_notebook.py Executes the generated notebook with errors disallowed.

Back to contents

26. Installation and setup

Requirements

The checked-in quotient outputs are large. Re-running the quotient study can create large checkpoint files. The current certification-gap study is much smaller.

Step 1: clone the repository

git clone https://github.com/simransummermalik/TheoreticalComputing.git
cd TheoreticalComputing
  

Step 2: create a virtual environment

python3 -m venv .venv
  

A virtual environment keeps the research dependencies separate from the computer's global Python installation.

Step 3: activate the environment

source .venv/bin/activate
  

Activation is optional when commands explicitly use .venv/bin/python, but it is convenient during interactive work.

Step 4: install pinned dependencies

.venv/bin/python -m pip install -r requirements-research.txt
  

The environment includes Qiskit and Aer for circuits, NumPy and SciPy for numerical work, SymPy for exact integer algebra, pandas and Matplotlib for analysis, fpylll for verified BKZ comparisons, notebook tooling, and pytest.

Step 5: install the audited arithmetic dependency

Only run the clone command if the external directory is missing:

git clone --depth 1 \
  https://github.com/Wlitkopa/regev-quantum-algorithm.git \
  external/regev-quantum-algorithm

git -C external/regev-quantum-algorithm fetch --depth 1 \
  origin a18f75d414485086db9b257407e0bd01f8a8f81c

git -C external/regev-quantum-algorithm checkout \
  a18f75d414485086db9b257407e0bd01f8a8f81c
  

The fixed commit keeps the reversible-arithmetic dependency reproducible.

Back to contents

27. Running the tests

Run the full test suite from the repository root:

MPLCONFIGDIR=/tmp/mpl \
PYTHONPATH=. \
.venv/bin/python -m pytest -q
  

The current repository documentation reports this expected final line:

104 passed
  

What the environment variables do

PYTHONPATH=. tells Python that the repository root should be searched for imports.

MPLCONFIGDIR=/tmp/mpl gives Matplotlib a writable temporary cache directory and avoids permission warnings in restricted environments.

What the tests cover

Back to contents

28. Reproducing the current result

Run:

MPLCONFIGDIR=/tmp/mpl \
PYTHONPATH=. \
.venv/bin/python scripts/run_qft_certificate_gap.py
  

This rewrites:

results/qft_certificate_gap/
  

The output directory includes:

Why completion hashes matter

A result directory can be copied, edited, or partially regenerated. A completion record lets a reader check whether the files match the output produced by one completed run.

This does not prove the scientific claim by itself. It proves that the result bundle is internally tied to a recorded execution.

Back to contents

29. Running earlier studies

QFT precision scaling

MPLCONFIGDIR=/tmp/mpl \
PYTHONPATH=. \
.venv/bin/python scripts/run_qft_precision_scaling.py
  

First finite QFT/noise experiment

MPLCONFIGDIR=/tmp/mpl \
PYTHONPATH=. \
.venv/bin/python scripts/run_qft_noise_experiment.py
  

Base-selection red team

MPLCONFIGDIR=/tmp/mpl \
PYTHONPATH=. \
.venv/bin/python scripts/run_redteam.py
  

Analyze the completed quotient study

PYTHONPATH=. \
.venv/bin/python scripts/analyze_quotient_study.py
  

The quotient study is expensive and already has a complete checked-in trial table. Use the analysis script unless a full rerun is specifically required.

Build and execute the revised notebook

.venv/bin/python scripts/build_revised_notebook.py

.venv/bin/python -m ipykernel install \
  --prefix .jupyter \
  --name regev-research \
  --display-name "Regev Research"

JUPYTER_DATA_DIR="$PWD/.jupyter/share/jupyter" \
IPYTHONDIR=/tmp/ipython \
MPLBACKEND=Agg \
MPLCONFIGDIR=/tmp/mpl \
.venv/bin/python scripts/execute_revised_notebook.py
  

Back to contents

30. How to read the outputs

Raw trials

A raw trial row represents one frozen combination of modulus, model, cutoff, replicate, and recovery result. Raw rows should not be pooled without respecting the experimental unit.

The modulus N is the generalization unit

Thousands of repeated shots on one modulus do not create thousands of independently generalized factoring problems.

The repository therefore aggregates and resamples at the whole-N level when making across-modulus claims.

Factor success

Factor success means the recovery path returned a proper factor pair that multiplied back to N. Setup gcd leaks are excluded.

Verified L\L0 success

This is a stricter structural endpoint. It records whether recovery found an exact relation whose stored-root product belonged to a factor-bearing class.

Confidence intervals

Cluster intervals resample whole moduli. They reflect uncertainty across the tested N values, not merely uncertainty across repeated shots at one N.

Non-inferiority

Non-inferiority asks whether the approximate method is not worse than the exact method by more than a predeclared margin.

In the current holdout, the frozen absolute margin was 0.10. The approximate-minus-exact lower confidence bound had to remain above -0.10.

Back to contents

31. Common problems

ModuleNotFoundError: No module named regev_research

Run the command from the repository root and include:

PYTHONPATH=.
  

Missing gates.r_haner or modular-exponentiation imports

Confirm that this file exists:

external/regev-quantum-algorithm/gates/r_haner/modular_exponentiation.py
  

Verify the dependency commit:

git -C external/regev-quantum-algorithm rev-parse HEAD
  

Expected:

a18f75d414485086db9b257407e0bd01f8a8f81c
  

Matplotlib cache is not writable

Prefix the command with:

MPLCONFIGDIR=/tmp/mpl
  

Jupyter cannot find the regev-research kernel

Install it from the virtual environment:

.venv/bin/python -m ipykernel install \
  --prefix .jupyter \
  --name regev-research \
  --display-name "Regev Research"
  

LLL and BKZ are being confused

The primary endpoint uses exact integer LLL through SymPy. BKZ experiments use fpylll only when the transformation can be verified.

A deterministic fallback is labeled as a surrogate. It should not be reported as actual BKZ.

The quotient study uses too much time or storage

Do not rerun it by default. Analyze the checked-in 117,760-row trial table:

PYTHONPATH=. \
.venv/bin/python scripts/analyze_quotient_study.py
  

A toy circuit returned factors. Is the algorithm proven?

No. A toy success may be caused by easy group structure, setup gcd leakage, a favorable root family, or repeated tuning on the same input.

The evidence must be tied to the labeled sample-to-lattice endpoint and the tested finite model.

Back to contents

32. How to extend the project without invalidating it

  1. Keep every chosen root permanently paired with its squared base.
  2. Do not give known factors, group orders, arbitrary square roots, or generator oracles to a factor-blind recovery method.
  3. Write the mathematical contract of every new function.
  4. Test what the code actually computes, not only what its name suggests.
  5. Freeze moduli, seeds, parameter grids, budgets, and failure conditions before the final holdout.
  6. Use N as the primary unit for generalization.
  7. Compare methods using the same quantum-sample count and classical-search budget.
  8. Verify z in L before classifying it or attempting gcd extraction.
  9. Keep hard-box, Gaussian, noisy-dual, and corruption-surrogate conclusions separate.
  10. Separate measured gate counts, analytic bounds, deterministic estimates, and simulator runtimes.
  11. Preserve negative results instead of moving the endpoint after seeing held-out data.
  12. Invalidate and regenerate outputs when a correctness bug changes the experimental calculation.

Back to contents

33. What is verified, what is not, and how claims are labeled

Verified implementation facts

Falsified positive hypotheses

Not established

The strongest current claim

In the tested finite hard-box and finite-Gaussian models, limited QFT phase-layer omission met a frozen lattice-recovery non-inferiority endpoint even though the original worst-case certificate rejected every non-exact cutoff.

This is a finite certification-gap result. It is not a general faster factoring algorithm.

Back to contents

34. Glossary

Ancilla
A temporary quantum work qubit used by reversible arithmetic.
Approximate QFT
A QFT circuit that omits selected small controlled-phase rotations.
BKZ
A stronger, usually more expensive family of lattice-reduction algorithms.
Composite integer
An integer that is a product of smaller positive integers.
Controlled phase
A two-qubit gate that adds a phase depending on the control and target states.
Discrete Gaussian
A probability or amplitude profile that decreases with squared distance on a discrete domain.
Dual lattice
The set of vectors having integer inner product with every vector in the original lattice.
Factor-blind
A method that is not allowed to use the known factorization of N while selecting or recovering.
Fiber
The set of exponent vectors that produce the same modular-exponentiation output.
gcd
The greatest common divisor of two integers.
Hard-box state
A state assigning equal amplitude to every exponent vector in a finite Cartesian box.
Held-out modulus
An N value not used while tuning the method and reserved for final evaluation.
HNF
Hermite normal form, an exact canonical form for integer lattices.
L
The exact multiplicative relation lattice of the squared circuit bases.
L0
The sublattice of valid relations whose stored-root product is +1 or -1.
LLL
A polynomial-time lattice-basis reduction algorithm that returns a shorter, better-conditioned basis.
Modulo N
Arithmetic in which values differing by a multiple of N are treated as equivalent.
Non-inferiority
A test asking whether a new method is not worse than a reference by more than a predeclared margin.
QFT
The quantum Fourier transform, which converts phase and periodic structure into measurement structure.
QFT cutoff
The maximum qubit separation whose controlled phase is retained.
Relation
An integer exponent vector whose modular product of circuit bases equals one.
Root of unity
A complex phase that returns to one after an integer power.
Rooted base
The permanently paired values (bi, ai) with ai = bi² mod N.
Semiprime
A composite integer formed from the product of two primes.
Setup factor leak
A factor found classically during root or base selection before quantum sampling.
Shot
One circuit preparation, execution, and measurement.
SNF
Smith normal form, an exact integer tool for quotient-group structure.
Total variation distance
A value from zero to one measuring the difference between two probability distributions.
Unimodular transformation
An invertible integer change of lattice basis with determinant +1 or -1.

Back to contents

35. Primary references

Repository reports


This manual reflects the repository's documented main-branch state when generated in July 2026. The GitHub repository remains the authoritative source for later corrections, new tests, and new results.

Back to contents

Back to DREU Research Log