Metadata-Version: 2.4
Name: ganitsolver
Version: 0.1.0
Summary: Universal Math Solver powered by Sanskrit Resonance Learning & Pāṇini's Grammar
Author: ParamTatva.org
License: MIT
Project-URL: Homepage, https://github.com/samskritam/sanskritlm
Project-URL: Repository, https://github.com/samskritam/sanskritlm
Project-URL: Documentation, https://github.com/samskritam/sanskritlm/tree/main/GanitSolver
Keywords: math,solver,sanskrit,resonance,panini,devanagari,number-theory,algebra,combinatorics,AIME,competition-math
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Science/Research
Classifier: Intended Audience :: Education
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Scientific/Engineering :: Mathematics
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Classifier: Topic :: Text Processing :: Linguistic
Classifier: Natural Language :: English
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: torch>=2.0.0
Requires-Dist: numpy>=1.24.0
Requires-Dist: networkx>=3.0
Provides-Extra: dev
Requires-Dist: pytest>=7.0; extra == "dev"
Requires-Dist: build; extra == "dev"
Requires-Dist: twine; extra == "dev"
Dynamic: license-file

# GanitSolver: Vedic Resonance Learning Model for Mathematics

GanitSolver is a specialized mathematics reasoning engine that combines Sanskrit grammatical structures (Paninian Grammar) with Resonance Learning Models (RLM) to solve complex math problems. It leverages `Vibhakti` decomposition and `Pratyahara` domain classification to resonate towards solutions rather than purely symbolic manipulation.

## Core Architecture

The solver operates via a pipeline:

1.  **Vibhakti Decomposition (`ganitsolver.rlm.karak`)**: Parses the problem into a `KarakFrame` (Agent, Object, Instrument, Action).
2.  **Resonance Propagation (`ganitsolver.rlm.reasoner`)**: Computes answers by propagating energy through a Paramtatva phonemic graph.
3.  **Pratyahara Dispatch (`ganitsolver.solvers.dispatch`)**: Classifies problems into domains (Game Theory/JhaŚ, Counting/aC, Combinatorics/yaN) for specialized solving.
4.  **Beam Search (`ganitsolver.api.solver`)**: Explores candidate solutions using phonemic coherence scoring.

## Key Components

-   **RLM Engine**: Pure neural-symbolic hybrid reasoning.
-   **Ganit Library**: Python implementation of fast Vedic math tricks (digit sums, modular arithmetic, etc.).
-   **Solvers**: Domain-specific strategies for AIME/Olympiad style problems.

## 12 Solver Domains

The system employs 12 specialized solver strategies, routed via the **Pratyahara Dispatcher**. All reasoning happens in Sanskrit:

### A. Specialized Solvers (Tier 1 - Specialized Logic)
1.  **Fingerprint Solver (AIME Comprehensive)**
    *   *English:* "Find the remainder when $2^{100}$ is divided by $7$."
    *   *Sanskrit:* `2^{100} saptabhiḥ vibhajyate cet avaśeṣaḥ kaḥ?`
    *   *Logic:* O(1) pattern matching for recurring competition problems.
2.  **Game Theory Solver (JhaŚ Pratyahara)**
    *   *English:* "Two players remove stones from piles of 3, 5, 7. Who wins?"
    *   *Sanskrit:* `dvau krīḍakau 3, 5, 7 rāśibhyaḥ prastarān apasarataḥ. kaḥ jayati?`
    *   *Logic:* Sprague-Grundy theorem for impartial games.
3.  **Combinatorial Structure Solver (YaN Pratyahara)**
    *   *English:* "How many distinct ways can you color a hexagon with 3 colors under rotation?"
    *   *Sanskrit:* `şaḍbhujaṃ tribhiḥ varṇaiḥ paribhramaṇe kati prakāraiḥ rañjayitum śakyate?`
    *   *Logic:* Burnside's Lemma (symmetry) and Graph Theory.
4.  **Pure RLM Beam Solver**
    *   *English:* "Find the next term in the sequence: 2, 6, 12, 20..."
    *   *Sanskrit:* `2, 6, 12, 20... iti śreṇyāḥ agrimam padaṃ kim?`
    *   *Logic:* Phonemic resonance propagation for pattern completion.

### B. Gaṇit Library Modules (Tier 2 - Tool-Integrated Reasoning)
used for arithmetic-heavy tasks via code generation:

5.  **Sankhya (Number Theory)**
    *   *English:* "Find the number of divisors of $10!$."
    *   *Sanskrit:* `$10!$ ityasya kāryakāṇāṃ saṅkhyā kā?`
6.  **Beeja (Algebra)**
    *   *English:* "Find the sum of roots of $x^3 - 4x + 1 = 0$."
    *   *Sanskrit:* `$x^3 - 4x + 1 = 0$ samīkaraṇasya mūlānāṃ yogaḥ kaḥ?`
7.  **Ganana (Counting)**
    *   *English:* "How many ways can 5 people sit in a circle?"
    *   *Sanskrit:* `pañca janāḥ vṛtte kati prakāraiḥ upaveṣṭuṃ śaknuvanti?`
8.  **Jyamiti (Geometry)**
    *   *English:* "Area of a triangle with side lengths 13, 14, 15."
    *   *Sanskrit:* `yatra bhujaḥ 13, 14, 15 santi, tasya trikoṇasya kṣetraphalaṃ kim?`
9.  **Sambhavna (Probability)**
    *   *English:* "Probability of rolling sum 7 with two dice."
    *   *Sanskrit:* `dvābhyāṃ pāśakābhyāṃ 7 yogaḥ prāptasya sambhāvanā kā?`
10. **Shreni (Sequences)**
    *   *English:* "Sum of the first 100 terms of an AP with $a=1, d=3$."
    *   *Sanskrit:* `yatra $a=1, d=3$ asti, tasyāḥ samāntara-śreṇyāḥ prathama-śata-padānāṃ yogaḥ kaḥ?`
11. **Anka (Digital Logic)**
    *   *English:* "Convert $101_2$ to base 10."
    *   *Sanskrit:* `$101_2$ daśamika-paddhatau parivartaya.`
12. **Samikaran (Equations)**
    *   *English:* "Integer solutions for $3x + 5y = 19$."
    *   *Sanskrit:* `$3x + 5y = 19$ samīkaraṇasya pūrṇa-samādhānāni kāni?`

## Sanskrit Translation Mechanism (The Pivot Language)

The system is designed with **Sanskrit as the mandatory intermediate reasoning language**. All non-Sanskrit inputs must be translated before processing.

### Architecture: `Any Language → Sanskrit → RLM`

1.  **Input Translation (The "Bridge")**:
    *   **Indic Languages**: Uses `IndicTrans2` (Meta) to translating Hindi, Tamil, Telugu, etc., directly into Sanskrit.
    *   **Global Languages**: Uses `NLLB-200` (No Language Left Behind) to translate English, Chinese, French, etc., into Sanskrit.
    *   *Why?* Sanskrit's diverse case system (Vibhakti) eliminates ambiguity in mathematical relationships that exists in English (e.g., "divided by" vs "dividing").

2.  **Karak Decomposition (Grammar Parsing)**:
    Once the text is in Sanskrit, the `KarakParser` decomposes the sentence using **Target-Action-Object (so-called "Vibhakti")** rules:
    *   **2nd Case (Karma)**: The numbers/objects being operated on.
    *   **3rd Case (Karana)**: The operator/instrument ($+$, $\times$, $\div$).
    *   **1st Case (Karta)**: The variable to solve for.

3.  **Universal Mathematical Graph**: 
    The RLM processes *only* the Sanskrit phonemes. It does not understand "remainder" or "integral" — it matches the *phonemic signature* of `avaśeṣa` (remainder) or `samākalana` (integral).

### Example Pipeline
*Input (English):* "Find the remainder when 2^100 is divided by 7"
1.  **Translate**: `2^{100} saptabhiḥ vibhajyate cet avaśeṣaḥ kaḥ?` (Sanskrit)
2.  **Decompose**: 
    *   Kartā: `avaśeṣaḥ` (Remainder)
    *   Karaṇa: `saptabhiḥ` (By seven - 3rd case)
    *   Kriyā: `vibhajyate` (Is divided)
3.  **Resonate**: RLM solves based on the phonemic path of `vibhajyate` + `saptabhiḥ`.

## Installation

1.  Navigate to the package directory:
    ```bash
    cd GanitSolver
    ```

2.  Install dependencies:
    ```bash
    pip install -r requirements.txt
    ```

## Usage

```python
from ganitsolver import GanitSolver

# Initialize the solver (beam_width controls search breadth)
solver = GanitSolver(
    beam_width=128,             # Controls search breadth
    max_horizon=3,              # Max depth for RLM search
    model="rlm-small-v1",       # RLM model for classification
    llm="deepseek-r1-14b",      # LLM for TIR (optional, GPU)
    device="auto",              # auto-detect GPU/CPU
    strict_sanskrit=True,       # Enforce Sanskrit-only input (Production Mode)
)

# Solve a problem (Sanskrit Input)
problem_text = "2^{100} saptabhiḥ vibhajyate cet avaśeṣaḥ kaḥ?"
answer, confidence = solver.solve(problem_text)

print(f"Answer: {answer} (Confidence: {confidence:.2f})")
```

## Structure

-   `ganitsolver/api`: Main user-facing API.
-   `ganitsolver/rlm`: Core RLM logic, grammar parsing, and graph models.
-   `ganitsolver/solvers`: Problem-specific solving strategies.
-   `ganitsolver/ganit`: Mathematical utility library.

## License

[Add License Here]
