Skip to content

Add number theoretic transform - #15836

Closed
Robotcell wants to merge 1 commit into
TheAlgorithms:masterfrom
Robotcell:add-number-theoretic-transform
Closed

Robotcell wants to merge 1 commit into
TheAlgorithms:masterfrom
Robotcell:add-number-theoretic-transform

Conversation

@Robotcell

@Robotcell Robotcell commented Dec 1, 2026 •

Copy link
Copy Markdown

Describe your change

  • Add an algorithm?
  • Fix a bug or typo in an existing algorithm?
  • Add or change doctests? -- Note: Please avoid changing both code and tests in a single pull request.
  • Documentation change?

Adds maths/number_theoretic_transform.py: an iterative radix-2 number theoretic transform modulo 998244353 (https://en.wikipedia.org/wiki/Discrete_Fourier_transform_(general)#Number-theoretic_transform) plus an exact integer convolve. The repo has a complex-valued FFT (maths/radix2_fft.py) but no NTT (checked by file name, content search incl. the modulus, and PR search).

Tests run:

  • python -m doctest -v maths/number_theoretic_transform.py: 10 passed
  • pytest --doctest-modules maths/number_theoretic_transform.py: 2 passed
  • ruff check / ruff format / mypy: clean
  • Independent check script (not included): for sizes 1 to 256, compared the transform with the naive O(n^2) DFT built from pow(3, (p-1)/n) and checked that the inverse round-trips; compared convolve with schoolbook multiplication on 500 random pairs. I did not run the full pre-commit suite locally (hook installation hung).

Checklist

  • I have read CONTRIBUTING.md.
  • This pull request is all my own work -- I have not plagiarized.
  • I know that pull requests will not be merged if they fail the automated tests.
  • This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms.
  • All new Python files are placed inside an existing directory.
  • All filenames are in all lowercase characters with no spaces or dashes.
  • All functions and variable names follow Python naming conventions.
  • All function parameters and return values are annotated with Python type hints.
  • All functions have doctests that pass the automated testing.
  • All new algorithms include at least one URL that points to Wikipedia or another similar explanation.
  • If this pull request resolves one or more open issues, then the description above includes the issue number(s) with a closing keyword: "Fixes #ISSUE-NUMBER".

AI assistance: written with Claude (Claude Code); I reviewed it and ran the tests listed above.

Co-Authored-By: Claude <noreply@anthropic.com>
@algorithms-keeper algorithms-keeper Bot added the awaiting reviews This PR is ready to be reviewed label Dec 1, 2026
@algorithms-keeper

Copy link
Copy Markdown

Closing this pull request as invalid

@Robotcell, this pull request is being closed because the description is empty. If you believe that this is being done by mistake, please read our Contributing guidelines before opening a new pull request with our template properly filled out. Thank you for your interest in our project.

@algorithms-keeper algorithms-keeper Bot closed this Dec 1, 2026
@algorithms-keeper algorithms-keeper Bot removed the awaiting reviews This PR is ready to be reviewed label Dec 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant