Skip to main content

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

PyPI version Python 3.9+ License: MIT

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 scored 0.96142 on the Kaggle AIMO Prize leaderboard.


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 of aṣṭ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

  1. Multilingual Tokenizer — Normalizes English, IAST, and Devanagari into unified math tokens
  2. Vibhakti Decomposition — Parses into Kāraka roles (Agent/Object/Instrument/Action)
  3. Paramtatva Resonance Graph — Maps operators to Sanskrit phonemes (42 nodes, 108 flows)
  4. Beam Search Reasoner — 128-beam, 3-horizon search over candidate answers
  5. 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

Competition Results

GaṇitSolver achieved 0.96142 on the Kaggle AIMO Prize leaderboard, competing against systems with 100× more parameters, by combining 12 specialized solvers with a 1.2M-parameter RLM classifier.

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ganitsolver-0.1.1.tar.gz (99.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ganitsolver-0.1.1-py3-none-any.whl (109.1 kB view details)

Uploaded Python 3

File details

Details for the file ganitsolver-0.1.1.tar.gz.

File metadata

  • Download URL: ganitsolver-0.1.1.tar.gz
  • Upload date:
  • Size: 99.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.2

File hashes

Hashes for ganitsolver-0.1.1.tar.gz
Algorithm Hash digest
SHA256 13f8df899ed5f07de0d610bdb791c448dd1c27cacd3d6a9d68cf2cb974b23565
MD5 01a341021f7b38a629d1e3db7fa60f56
BLAKE2b-256 d6fecbe0f93d1122725d2c84ccdb0da4f4a3607f251602e100571a2c109b444d

See more details on using hashes here.

File details

Details for the file ganitsolver-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: ganitsolver-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 109.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.2

File hashes

Hashes for ganitsolver-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 77ed1ae0fa286e197a23efc4dbe85b9203f9d8d5fd9f18c0d5f5e4f520337bd6
MD5 aa81aef3a007485f2b6df2aa962cc7b9
BLAKE2b-256 b66e320d2bf0b01214c38d50bc3d1611925803eb089dd1dc8c64fde6b3ec860c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page