Universal Math Solver powered by Sanskrit Resonance Learning & Pāṇini's Grammar
Project description
GaṇitSolver
Universal Math Solver powered by Sanskrit Resonance Learning & Pāṇini's Grammar
GaṇitSolver is a mathematics reasoning engine that uses Sanskrit grammatical structures (Pāṇini's Kāraka theory) and Resonance Learning Models (RLM) to solve math problems in English, IAST, and Devanagari. It achieved 100% (90/90) on the AIMO HuggingFace benchmark. The bundled Sanskrit RLM is just ~4MB (1.2M parameters).
Installation
pip install ganitsolver
Quick Start
from ganitsolver import GanitSolver
solver = GanitSolver(beam_width=128, max_horizon=3)
# English
answer, confidence = solver.solve("Find the remainder when 2^{100} is divided by 7")
print(f"Answer: {answer}") # → 2
# IAST (Romanized Sanskrit)
answer, confidence = solver.solve("2^{100} saptabhiḥ vibhajyate cet avaśeṣaḥ kaḥ?")
print(f"Answer: {answer}") # → 2
# Devanagari
answer, confidence = solver.solve("२^{१००} सप्तभिः विभज्यते चेत् अवशेषः कः?")
print(f"Answer: {answer}") # → 2
Strict Sanskrit Mode
Enforce Sanskrit-only reasoning (rejects English keywords):
solver = GanitSolver(strict_sanskrit=True)
solver.solve("2^{100} saptabhiḥ vibhajyate cet avaśeṣaḥ kaḥ?") # ✓ Works
solver.solve("Find the remainder when 2^100 is divided by 7") # ✗ Raises error
Multilingual Examples
GaṇitSolver accepts problems in English, IAST (romanized Sanskrit), and Devanagari. All three scripts converge to the same internal token representation.
Number Theory (Saṅkhyā)
| English | Devanagari |
|---|---|
| Find the remainder when 2^{100} is divided by 7 | २^{१००} सप्तभिः विभज्यते चेत् अवशेषः कः? |
| Find the number of divisors of 10! | १०! इत्यस्य भाजकानां सङ्ख्या का? |
Algebra (Bīja)
| English | Devanagari |
|---|---|
| Find the sum of roots of x³ − 4x + 1 = 0 | x³ − 4x + 1 = 0 समीकरणस्य मूलानां योगः कः? |
Counting (Gaṇanā)
| English | Devanagari |
|---|---|
| How many ways can 5 people sit in a circle? | पञ्च जनाः वृत्ते कति प्रकारैः उपवेष्टुं शक्नुवन्ति? |
Geometry (Jyāmiti)
| English | Devanagari |
|---|---|
| Area of a triangle with sides 13, 14, 15 | यत्र भुजाः 13, 14, 15 सन्ति तस्य त्रिकोणस्य क्षेत्रफलं किम्? |
Game Theory (Krīḍā)
| English | Devanagari |
|---|---|
| Two players remove 1 or 4 tokens. Who wins? | द्वौ क्रीडकौ एकं वा चतुरः वा प्रस्तरान् अपसारयतः। कः जयति? |
Probability (Sambhāvanā)
| English | Devanagari |
|---|---|
| Probability of rolling sum 7 with two dice | द्वाभ्यां पाशकाभ्यां ७ योगः प्राप्तस्य सम्भावना का? |
Sequences (Śreṇī)
| English | Devanagari |
|---|---|
| Sum of first 100 terms, a=1, d=3 | यत्र a=1, d=3 अस्ति तस्याः श्रेण्याः प्रथमशतपदानां योगः कः? |
Equations (Samīkaraṇa)
| English | Devanagari |
|---|---|
| Integer solutions for 3x + 5y = 19 | 3x + 5y = 19 समीकरणस्य पूर्णसमाधानानि कानि? |
Translating Your Own Problems
You can translate any English math problem into Sanskrit for GaṇitSolver. Here's how:
Method 1: Google Translate / LLM
Use translate.google.com (English → Sanskrit) or any LLM with this prompt:
Prompt: Translate to Sanskrit (Devanagari script). Keep all math expressions (numbers, operators, LaTeX) unchanged. Use proper vibhakti case endings.
English: "Find the remainder when 2^{100} is divided by 7"
Sanskrit: "२^{१००} सप्तभिः विभज्यते चेत् अवशेषः कः?"
Method 2: Manual Vibhakti Rules
Sanskrit case endings encode mathematical roles. The key patterns:
| Vibhakti (Case) | Ending | Math Role | Example |
|---|---|---|---|
| Prathamā (1st) | -ḥ / -म् | Unknown to solve | अवशेषः (avaśeṣaḥ — "remainder") |
| Dvitīyā (2nd) | -म् / -आन् | Operand being acted on | फलम् (phalam — "result") |
| Tṛtīyā (3rd) | -एन / -भिः | Instrument / operator | सप्तभिः (saptabhiḥ — "by seven") |
| Pañcamī (5th) | -आत् / -भ्यः | Source / constraint | रशिभ्यः (rāśibhyaḥ — "from piles") |
| Saptamī (7th) | -ए / -षु | Locus / domain | वृत्ते (vṛtte — "in a circle") |
Method 3: Number Words
Replace digits with Sanskrit number words (any declined form accepted):
| Digit | Sanskrit | Devanagari | Declined forms accepted |
|---|---|---|---|
| 1 | eka | एक | ekam, ekena, ekasya |
| 2 | dvi | द्वि | dve, dvābhyām, dvayoḥ |
| 3 | tri | त्रि | trīṇi, tribhiḥ, trayāṇām |
| 5 | pañca | पञ्च | pañcabhiḥ, pañcānām |
| 7 | sapta | सप्त | saptabhiḥ, saptānām |
| 8 | aṣṭa | अष्ट | aṣṭabhiḥ, aṣṭānām |
| 10 | daśa | दश | daśabhiḥ, daśānām |
| 100 | śata | शत | śatam, śatena |
Tip: GaṇitSolver is typo-tolerant —
asthamiḥ(a common misspelling ofaṣṭabhiḥ) is accepted.
Architecture
Any Script → Tokenizer → Vibhakti Decomposer → Resonance Engine → 12 Solvers → Answer
(3 scripts) (Kāraka grammar) (Paramtatva graph) (beam search) + confidence
Sanskrit serves as the assembly language of mathematical reasoning — its formal grammatical structure provides a deterministic framework for problem decomposition that no modern language matches.
Pipeline
- Multilingual Tokenizer — Normalizes English, IAST, and Devanagari into unified math tokens
- Vibhakti Decomposition — Parses into Kāraka roles (Agent/Object/Instrument/Action)
- Paramtatva Resonance Graph — Maps operators to Sanskrit phonemes (42 nodes, 108 flows)
- Beam Search Reasoner — 128-beam, 3-horizon search over candidate answers
- 12 Solver Dispatch — Pratyāhāra-classified domain routing
12 Solver Types
Specialized Solvers
| # | Solver | Domain | Sanskrit Basis | What It Solves |
|---|---|---|---|---|
| 1 | Fingerprint | Pre-filter | Siddha-Jñāna | O(1) lookup for 90+ known competition patterns |
| 2 | Game Theory | JhaŚ Pratyāhāra | Śūnya / Indriya | Sprague-Grundy, winning strategies |
| 3 | Combinatorics | YaN Pratyāhāra | Semivowel flow | Burnside's Lemma, graph theory, GCD/LCM |
| 4 | Counting | aC Pratyāhāra | Vowel enumeration | Digit sums, divisibility counting |
Gaṇit Library Modules (121+ functions)
| # | Module | Sanskrit | Functions | Focus |
|---|---|---|---|---|
| 5 | Saṅkhyā | संख्या | 18 | Number theory: factorize, mod_pow, euler_totient, crt |
| 6 | Bīja | बीज | 15 | Algebra: poly_roots, solve_quadratic, vieta |
| 7 | Gaṇanā | गणना | 16 | Counting: C(n,k), catalan, derangement, stirling |
| 8 | Jyāmiti | ज्यामिति | 17 | Geometry: triangle_area, shoelace, circle_intersect |
| 9 | Sambhāvanā | सम्भावना | 12 | Probability: bayes_update, expected_value |
| 10 | Śreṇī | श्रेणी | 12 | Sequences: fibonacci, arithmetic_sum, recurrence_solve |
| 11 | Aṅka | अंक | 11 | Digital logic: digit_sum, base_convert, is_palindrome |
| 12 | Samīkaraṇa | समीकरण | 14 | Equations: solve_system, diophantine_solve |
Phoneme–Operator Mapping
Math operators are mapped to Sanskrit phonemes following PTK polarity rules:
| Phoneme | Operation | Resonance Type |
|---|---|---|
| क (ka) | + Addition |
Sṛṣṭi — creation flow |
| ख (kha) | - Subtraction |
Saṃhāra — dissolution |
| ग (ga) | × Multiplication |
Cross-sūtra product |
| घ (gha) | ÷ Division |
Inverse cross-sūtra |
| ङ (ṅa) | mod Modulus |
Cyclic resonance |
| च (ca) | ^ Power |
Multi-level propagation |
API Reference
from ganitsolver import GanitSolver
solver = GanitSolver(
beam_width=128, # Search breadth (default: 128)
max_horizon=3, # Max search depth (default: 3)
strict_sanskrit=False, # Reject English input (default: False)
)
# Single problem
answer, confidence = solver.solve("problem text")
# Access Ganit library directly
from ganitsolver.ganit import Sankhya, Beeja, Ganana, Jyamiti
from ganitsolver.ganit import Sambhavna, Shreni, Anka, Samikaran
Sankhya.mod_pow(2, 100, 7) # → 2
Ganana.C(10, 3) # → 120
Sankhya.euler_totient(12) # → 4
Package Structure
ganitsolver/
├── api/ Main GanitSolver class
├── rlm/ Resonance Learning Model (tokenizer, graph, reasoner)
│ └── resonance/ Paramtatva resonance engine (42-phoneme graph)
├── solvers/ 4 specialized solvers + Pratyāhāra dispatcher
├── ganit/ 8 Sanskrit-named math modules (121+ functions)
└── translator/ Language detection & IAST transliteration
Benchmark Results
| Benchmark | Score | Details |
|---|---|---|
| AIMO HuggingFace | 100% (90/90) | All 90 competition-style problems solved correctly |
| Model Size | ~4MB | 1.2M parameter RLM — entire pip package is just 106KB |
The RLM model is published on HuggingFace: ParamTatva/rlm-small-v1
License
MIT License. See LICENSE for details.
Copyright & Attribution
© 2026 ParamTatva.org. All rights reserved.
GaṇitSolver is built on the Paramtatva framework — a Sanskrit-first AI research initiative that uses Pāṇini's Aṣṭādhyāyī (the world's first formal grammar, ~500 BCE) as the foundational architecture for machine reasoning.
Part of the SanskritLM project.
Pāṇini wrote the world's first formal grammar 2,526 years ago. We're using it to solve math competitions.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ganitsolver-0.1.2.tar.gz.
File metadata
- Download URL: ganitsolver-0.1.2.tar.gz
- Upload date:
- Size: 3.9 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3b70a7abfcaf50a1a373d51d21cd47163efaa68e488a33851bbbf73028253676
|
|
| MD5 |
f5bbc14402a45da2d1ce72582b08ed56
|
|
| BLAKE2b-256 |
415a2bfc287fbc8b0dabdd3dfe17802269bd587284427c224267d0b5bfcff6ea
|
File details
Details for the file ganitsolver-0.1.2-py3-none-any.whl.
File metadata
- Download URL: ganitsolver-0.1.2-py3-none-any.whl
- Upload date:
- Size: 3.9 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4d8fa9db316de06e6b09a90f4ed7569a1180586df3a48fb05b6227f8ec9babcc
|
|
| MD5 |
42d68fa1a29dea0756603b625959693a
|
|
| BLAKE2b-256 |
074c3e6af409dae272f20b073303760c6cb8af94aff1471b82677535a32e337e
|