Skip to main content

Python helpers for learning and applying Vedic mathematics techniques.

Project description

Vedic Mathematics

Python helpers for learning and applying Vedic mathematics techniques. The library focuses on two things:

  • returning correct arithmetic results as simple Python values
  • exposing step-by-step workings that teachers, students, notebooks, and apps can display

This project is early-stage and intended to grow into an open-source package of well-tested Vedic mathematics methods.

The first implementation pass is guided by the parsed source chunks in the larger Mr Rishi project, especially data/processed/Vedic_mathematics_chunks.jsonl.

Install for Development

git clone https://github.com/ksriniv2/vedicmaths.git
cd vedicmaths
python -m pip install -e ".[dev]"

If you are working from this local starter folder:

cd C:\Users\KARTH\OneDrive\Documents\vedicmathematics
python -m pip install -e ".[dev]"

Quick Start

from vedicmathematics import (
    nikhilam_multiply,
    nikhilam_steps,
    square_ending_in_5,
    urdhva_tiryagbhyam_multiply,
)

print(nikhilam_multiply(98, 97))
# 9506

print(urdhva_tiryagbhyam_multiply(123, 456))
# 56088

print(square_ending_in_5(35))
# 1225

trace = nikhilam_steps(98, 97)
for step in trace.steps:
    print(step.title, step.expression, "=>", step.value)

You can also use the shorter package alias:

from vedicmaths import nikhilam_multiply

Available Functions

Function Purpose
digit_sum(number) Sums the decimal digits of a number.
sum_digits_until_single(number) Repeated digit sum, equivalent to digital root.
nikhilam_multiply(a, b, base=None) Multiplies numbers using a nearby base, commonly a power of ten.
nikhilam_steps(a, b, base=None) Returns the worked steps for Nikhilam multiplication.
anurupyena_multiply(a, b, working_base, theoretical_base=None) Proportionate-base multiplication when a multiple or sub-multiple is more convenient.
anurupyena_steps(a, b, working_base, theoretical_base=None) Worked steps for proportionate-base multiplication.
urdhva_tiryagbhyam_multiply(a, b) General multiplication using the vertically-and-crosswise digit method.
urdhva_tiryagbhyam_steps(a, b) Returns the worked steps for vertically-and-crosswise multiplication.
left_to_right_add(a, b) Addition with a trace-friendly column process.
left_to_right_add_steps(a, b) Worked steps for addition.
subtract_using_complement(a, b) Subtraction by complementing the subtrahend from a power of ten.
subtract_using_complement_steps(a, b) Worked steps for complement subtraction.
complement(number, base=None) Complement from a supplied base or next power of ten.
all_from_9_last_from_10(number) Nikhilam-style complement helper.
vinculum_digits(number) Signed digit representation for digits above 5.
multiply_by_5(number) Shortcut for multiplication by 5.
multiply_by_9(number) Shortcut for multiplication by 9.
multiply_by_11(number) Adjacent-sum shortcut for multiplication by 11.
multiply_by_11_steps(number) Worked steps for multiplication by 11.
multiply_by_12(number) Shortcut for multiplication by 12.
multiply_by_15(number) Shortcut for multiplication by 15.
multiply_by_25(number) Shortcut for multiplication by 25.
multiply_by_50(number) Shortcut for multiplication by 50.
multiply_by_75(number) Shortcut for multiplication by 75.
multiply_by_99(number) Shortcut for multiplication by 99.
multiply_by_125(number) Shortcut for multiplication by 125.
multiply_by_999(number) Shortcut for multiplication by 999.
multiply_by_repeated_9(number, count) Multiply by 9, 99, 999, etc.
square_ending_in_5(number) Squares numbers ending in 5 using the "one more than the previous" pattern.
square_ending_in_5_steps(number) Returns the worked steps for squaring a number ending in 5.
square_near_base(number, base=None) Squares numbers close to a power-of-ten base.
square_near_base_steps(number, base=None) Worked steps for near-base squaring.
square_near_50(number) Shortcut for squaring values near 50.
cube_ending_in_5(number) Cubes numbers ending in 5.
divide_by_5(number) Division by 5 as doubling then dividing by 10.
divide_by_25(number) Division by 25 as multiplying by 4 then dividing by 100.
recurring_decimal_unit_fraction(denominator, limit=None) Decimal expansion of 1 / denominator, with repeating cycles in parentheses.
osculator_for_ending_9(divisor) Ekadhika-style osculator for divisors ending in 9.
fraction_to_percent(numerator, denominator) Converts fractions to percentages.
percent_of(percent, number) Calculates percent of a number.
transpose_percent(percent, number) Uses a% of b = b% of a.
is_divisible_by_3(number) Divisibility by 3 using digit sum.
is_divisible_by_9(number) Divisibility by 9 using digit sum.
is_divisible_by_11(number) Divisibility by 11 using alternating digit sums.
square_root_if_perfect(number) Returns the integer square root for perfect squares, otherwise None.
cube_root_if_perfect(number) Returns the integer cube root for perfect cubes, otherwise None.
digital_root(number) Computes a number's digital root.
casting_out_nines_check(a, b, result, operator="*") Verifies +, -, or * results using digital roots.

Example Step Trace

from vedicmathematics import nikhilam_steps

trace = nikhilam_steps(98, 97)
print(trace.result)
# 9506

for step in trace.steps:
    print(f"{step.title}: {step.expression} = {step.value}")

Output:

Choose base: base = 100 = 100
Find deviations: 98 - 100, 97 - 100 = -2, -3
Cross subtract: 98 + (-3) = 95
Multiply deviations: (-2) * (-3) = 6
Combine: (95 * 100) + (6) = 9506

Roadmap

Good next functions to add:

  • division using Paravartya Yojayet
  • multiplication by 9, 99, 999, and related bases
  • straight division and auxiliary fractions
  • simple and complex oscillators for divisibility
  • cube-root techniques
  • fraction simplification and recurring decimal patterns
  • richer renderers for traces, such as Markdown and HTML

Development

Run tests:

python -m pytest

Project structure:

vedicmathematics/
  vedicmathematics/
    __init__.py
    arithmetic.py
  tests/
    test_arithmetic.py
  pyproject.toml
  README.md

Contributing

Contributions are welcome. Please include:

  • a clear function name and docstring
  • tests for regular cases and edge cases
  • a *_steps variant when the method is teachable step by step
  • examples in the README when adding a major new method

License

MIT

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

vedicmaths-0.1.0.tar.gz (14.2 kB view details)

Uploaded Source

Built Distribution

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

vedicmaths-0.1.0-py3-none-any.whl (11.2 kB view details)

Uploaded Python 3

File details

Details for the file vedicmaths-0.1.0.tar.gz.

File metadata

  • Download URL: vedicmaths-0.1.0.tar.gz
  • Upload date:
  • Size: 14.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.11

File hashes

Hashes for vedicmaths-0.1.0.tar.gz
Algorithm Hash digest
SHA256 292532041fbfb3c7a6c328b7748c24f57a15b5361134c1df28a3ab3fb3eaf1ec
MD5 1840a819089d6f4b13dd469b0a748b8f
BLAKE2b-256 6d041c57f8915df936eb82c8408e94595f2345d43b9300b8d0a28359a1c1245a

See more details on using hashes here.

File details

Details for the file vedicmaths-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: vedicmaths-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 11.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.11

File hashes

Hashes for vedicmaths-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d6217b34af41c6ed2a2da4c1b67a3fb6ba2e417fdde50ba2b42ac73ea31b2e61
MD5 86194a1428e7958feb1c05deb2ed1180
BLAKE2b-256 c9f997244adaceeb5d60abc6186e38ec487d0808a0caf99012e3f88ea620bceb

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