Skip to content

Reversible arithmetic, point 3 of #336: modular arithmetic - #339

Merged
tatopenn-cell merged 10 commits into
mainfrom
arithmetic-modular
Oct 2, 2026
Merged

tatopenn-cell merged 10 commits into
mainfrom
arithmetic-modular

Conversation

@tatopenn-cell

Copy link
Copy Markdown
Owner

Point 3 of #336. Builds on #337 and #338 (contains their commits until they are merged).

  • add_registers_mod: |a, b⟩ → |a, (a+b) mod N⟩ (Vedral, Barenco, Ekert, quant-ph/9511018, Sect. III.B)
  • add_constant_mod: classical addend, optional controls (Beauregard, quant-ph/0205095, Sect. 2.2, doubly controlled φADD(a)MOD(N))
  • multiply_add_mod: |x, b⟩ → |x, (b + a·x) mod N⟩, optional controls (Beauregard Sect. 2.3 CMULT; Vedral Sect. III.C)
  • multiply_mod: in place x → a·x mod N for gcd(a, N) = 1, optional controls (Vedral Sect. II; Beauregard Fig. 7); N = 2^n with odd a is plain multiplication
  • power_mod: |x, y⟩ → |x, y·a^x mod N⟩, with y = 1 the modular exponentiation of Shor's algorithm (Vedral Eq. 1, Sect. III.D)

Values ≥ N are left unchanged so every map stays a permutation (unitary).

Tests compare each function with the paper's construction built from already-tested blocks and engine gates, on every basis state: Beauregard modular adder (Fig. 5), sum of controlled modular additions (Eq. 2), controlled-U_a with controlled swap (Fig. 7), chain of controlled multiplications (Vedral III.D); plus 7^x mod 15, plain ×odd mod 2^n, norm on random states, coprime check.

Docs: Step 6 (7^x mod 15) on api/arithmetic.md, details, nav label, README line.

@codecov

codecov Bot commented Oct 2, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 99.15966% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
dense_evolution/circuits/arithmetic.py 99.14% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@tatopenn-cell
tatopenn-cell merged commit 3f57bd5 into main Oct 2, 2026
9 checks passed
@tatopenn-cell
tatopenn-cell deleted the arithmetic-modular branch October 2, 2026 13:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant