Skip to main content

Anvaya (अन्वय) - A comprehensive Python mathematics library inspired by ancient Indian mathematical traditions

Project description

Anvaya Logo

Anvaya (अन्वय)

A Comprehensive Python Mathematics Library

PyPI version License: MIT Python 3.8+ Maintenance


PyPI version License: MIT Python 3.8+ Maintenance

Anvaya (Sanskrit: अन्वय) means "logical connection" or "coherent reasoning." It represents the systematic thread that links mathematical premises to universal truths.

Anvaya is a production-ready, high-performance mathematics library for Python. It bridges the gap between symbolic reasoning and numerical computation, providing a unified interface for 14 different mathematical domains.


📑 Table of Contents


� Detailed Documentation

Since Anvaya covers 14+ mathematical domains, we have detailed guides for each. You can access them directly on GitHub by clicking the links below:

Category Detailed Guide API Reference
Getting Started Installation | Quick Start -
Core domains Algebra | Linear Algebra | Calculus API
Probability & Stats Probability | Statistics API
Advanced Math Complex Analysis | Number Theory | Differential Eqs API
Applied Math Graph Theory | Numerical Methods | Optimization API
Discrete & Others Discrete Math | Vector Calculus | Symbolic Engine API

�📦 Installation

Anvaya requires Python 3.8 or higher. Use pip to install:

pip install anvaya

🚀 Quick Start

Solving a complex problem with Anvaya is intuitive. Here is a 30-second example of symbolic variables, algebra, and calculus working together:

from anvaya import algebra, calculus
from anvaya.symbolic import var

# 1. Define variables
x = var('x')

# 2. Expand a polynomial
polynomial = (x + 3)**2
expanded = algebra.expand_poly(polynomial)
print(f"Expanded: {expanded}")  # x**2 + 6*x + 9

# 3. Find the derivative
derivative = calculus.diff(expanded, x)
print(f"Derivative: {derivative}")  # 2*x + 6

# 4. Solve for roots
roots = algebra.solve_linear(derivative, x)
print(f"Roots: {roots}")  # [-3]

🧮 Domain Guides

1. Algebra

Handle equations, polynomials, and simplifications with ease.

from anvaya import algebra
from anvaya.symbolic import var

x = var('x')

# Solve quadratic equation x^2 - 5x + 6 = 0
roots = algebra.solve_quadratic(x**2 - 5*x + 6, x)
print(roots)  # [2, 3]

# Factorize expression
expr = x**2 + 2*x + 1
print(algebra.factor_poly(expr))  # (x + 1)**2

2. Linear Algebra

Perform matrix operations with high precision and safe error handling.

from anvaya import linear_algebra as la
import numpy as np

# Create a matrix
A = la.matrix([[1, 2], [3, 4]])

# Calculate Determinant
print(la.determinant(A))  # -2.0

# Compute Eigenvalues and Eigenvectors (Structured Result)
result = la.eigenvalues(A)
print(f"Values: {result.values}")
print(f"Vectors:\n{result.vectors}")

# Solve System Ax = b
b = [5, 11]
x = la.solve_linear_system(A, b)
print(f"Solution: {x}") # [1.0, 2.0]

3. Calculus

Perform symbolic differentiation, integration, and limit calculations.

from anvaya import calculus
from anvaya.symbolic import var

x = var('x')

# Differentiation
print(calculus.diff(x**3, x))  # 3*x**2

# Definite Integration (from 0 to 1)
integral = calculus.integrate(x**2, x, 0, 1)
print(integral)  # 1/3

# Limits
print(calculus.limit(1/x, x, 0, direction='+'))  # oo (Infinity)

4. Probability & Statistics

Modern API for distributions and descriptive statistics.

from anvaya import probability as prob
from anvaya import statistics as stats

# Statistics
data = [10, 20, 20, 30, 40, 50]
print(stats.mean(data))    # 28.33
print(stats.median(data))  # 25.0

# Probability Distributions
normal = prob.Normal(mean=0, std=1)
print(normal.pdf(0))  # 0.3989 (Bell curve peak)
print(normal.cdf(0))  # 0.5 (Area to the left)

# Bayes Theorem
# P(A|B) = P(B|A)*P(A) / P(B)
prob_a_given_b = prob.bayes_theorem(p_b_given_a=0.9, p_a=0.01, p_b=0.05)
print(f"Probability: {prob_a_given_b}") # 0.18

5. Number Theory

Prime numbers, modular arithmetic, and ancient algorithms.

from anvaya import number_theory as nt

# Prime factorization
print(nt.prime_factors(360))  # {2: 3, 3: 2, 5: 1}

# Euler's Totient
print(nt.totient(10))  # 4 (Numbers 1, 3, 7, 9 are coprime to 10)

# Modular Inverse
print(nt.mod_inverse(3, 11))  # 4 (3*4 = 12 ≡ 1 mod 11)

# Greatest Common Divisor
print(nt.gcd(48, 18))  # 6

6. Numerical Methods

Root finding and numerical integration when symbolic math isn't enough.

from anvaya import numerical

# Find root of f(x) = x^2 - 2 near x=1.5
def f(x): return x**2 - 2
root = numerical.root_find(f, 1.5)
print(f"Square root of 2 is approx: {root:.6f}") # 1.414214

🛠 Advanced Features

Safe Error Handling

Anvaya doesn't just crash; it tells you why a calculation failed using custom exceptions.

from anvaya import linear_algebra as la
from anvaya import SingularMatrixError

A = [[1, 1], [1, 1]] # Singular matrix (no inverse)

try:
    inv = la.inverse(A)
except SingularMatrixError as e:
    print(f"Math Error: {e}") # Matrix is singular or nearly singular

Type Safety

Full support for Python type hints and PEP 561 compliance, making it perfect for large-scale applications with VS Code or PyCharm.


🧬 Symbolic Engine

The core of Anvaya is its SymbolicEngine. You can use it to parse strings into math or manipulate variables.

from anvaya.symbolic import engine

# Parse from string
my_math = engine.expr("x**2 + 2*x + 1")
print(engine.factor(my_math)) # (x + 1)**2

🤝 Contributing

We welcome contributions to Anvaya! Whether it's adding new modules (like Tensor Calculus or Financial Math) or improving performance.

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

👨‍💻 Author

Akash Rahut

  • GitHub: @Akashrahut100
  • AI & Data Science Engineer
  • Building intelligent, scalable, and data-driven systems at the intersection of mathematics, software architecture, and artificial intelligence.

📜 License

Distributed under the MIT License. See LICENSE for more information.


“स्थानात् स्थानं दशगुणं स्यात्” — Āryabhaṭīya (499 CE)

(The logic of numbers shapes the universe)

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

anvaya-1.0.2.tar.gz (24.6 kB view details)

Uploaded Source

Built Distribution

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

anvaya-1.0.2-py3-none-any.whl (23.5 kB view details)

Uploaded Python 3

File details

Details for the file anvaya-1.0.2.tar.gz.

File metadata

  • Download URL: anvaya-1.0.2.tar.gz
  • Upload date:
  • Size: 24.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for anvaya-1.0.2.tar.gz
Algorithm Hash digest
SHA256 344b7e47247c757f30a432873d37653225cb290d1daa7fdc002860f1125ae546
MD5 3179ffbd66dbf94275914da7bfcdefd1
BLAKE2b-256 e2a6f7406ba58ad9c9514a657acab2828fd177f80784fab4d91a595d53a6a9fb

See more details on using hashes here.

Provenance

The following attestation bundles were made for anvaya-1.0.2.tar.gz:

Publisher: publish.yml on Akashrahut100/anvaya

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file anvaya-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: anvaya-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 23.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for anvaya-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 3447e0283a6d0e4622d2cc6bde15321851e42af455426c0186c5b8ec9e1063b2
MD5 2d3145929324a01cfc25f9dd9823bc27
BLAKE2b-256 c13eeece6b15f18da4c69b2da9103b0e92f78be8ed436ee8db6fb928663eac78

See more details on using hashes here.

Provenance

The following attestation bundles were made for anvaya-1.0.2-py3-none-any.whl:

Publisher: publish.yml on Akashrahut100/anvaya

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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