Skip to content

feat(Maths): add Tonelli-Shanks modular square root - #1913

Open
felipeofdev-ai wants to merge 2 commits into
TheAlgorithms:masterfrom
felipeofdev-ai:feat/tonelli-shanks
Open

feat(Maths): add Tonelli-Shanks modular square root#1913
felipeofdev-ai wants to merge 2 commits into
TheAlgorithms:masterfrom
felipeofdev-ai:feat/tonelli-shanks

Conversation

@felipeofdev-ai

Copy link
Copy Markdown

Description

Adds Maths/TonelliShanks.js implementing the Tonelli–Shanks algorithm for modular square roots modulo an odd prime.

  • Legendre symbol residue check
  • Fast path when p ≡ 3 (mod 4)
  • Full Tonelli–Shanks loop otherwise
  • Returns the smaller non-negative root

Reference: https://en.wikipedia.org/wiki/Tonelli%E2%80%93Shanks_algorithm

Checklist

  • I have read CONTRIBUTING.md
  • Tests added (Vitest)
  • DIRECTORY.md updated

— Felipe Fernandes · Systems & Agentic AI Engineer
https://github.com/felipeofdev-ai · https://felipeofdev-ai.github.io/

Implements Tonelli–Shanks for odd prime moduli with Legendre check,
p≡3 (mod 4) fast path, and Vitest coverage.
Signed-off-by: Felipe Fernandes <felipe.of.dev@gmail.com>
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 93.51852% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 85.95%. Comparing base (5c39e87) to head (200108a).

Files with missing linesPatch %Lines
Maths/TonelliShanks.js93.51%7 Missing ⚠️
Additional details and impacted files
@@ Coverage Diff @@## master #1913 +/- ##
==========================================
+ Coverage 85.91% 85.95% +0.04% 
==========================================
Files 379 380 +1 Lines 19778 19886 +108 Branches 3016 3042 +26 ==========================================
+ Hits 16993 17094 +101 - Misses 2785 2792 +7 

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for freeto 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.

2 participants

@felipeofdev-ai@codecov-commenter