vedicpy documentation

Logo

A Python Package for Vedic Mathematics

PyPI Python Version License

For humans, through regular mathematical steps, solving problems sometimes are complex and time-consuming. But using Vedic Mathematic’s General Techniques (applicable to all sets of given data) and Specific Techniques (applicable to specific sets of given data), numerical calculations can be done very fast.

This package is a python implementation of Vedic mathematical sutras. It uses the Vedic mathematics for performing basic mathematical operations like multiplication, division, square roots, cube roots etc.

Since Vedic maths sutras work on individual digits in a number as opposed to the whole number, the implementation works slower on small digit numbers but works faster on larger digit numbers and some other operations like finding the square root or the cube root of a number.

Installation

The simplest way to install vedicpy is through the Python Package Index (PyPI). This will ensure that all required dependencies are fulfilled. This can be achieved by executing the following command:

pip install vedicpy

Tutorial

This section covers the fundamentals of developing with vedicpy, including a package overview, basic and advanced usage.

Overview

The vedicpy package is structured as collection of submodules:

  • vedicpy

Quickstart

Before diving into the details, we’ll walk through a brief example program

# Example of calculating the cube of a number
import vedicpy as vedic

# calling cube_2digit_number from vedic.cube
result = vedic.cube.cube_2digit_number(67)

print(result)

In the program we first call the package by using import and by giving a compact syntax to it by using vedic as the name.

Then we simply call the cube_2digit_number function from cube module present in vedicpy.

As the name suggest cube_2digit_number function only cubes 2 digit integer numbers and returns an interger value that is stored in variable result and then we simply print that value of the variable.

Troubleshooting

If you have questions about how to use vedicpy, please email me at utkarsh.um07@gmail.com.

For bug reports and other, more technical issues, consult the github issues.

Important Error

Vedic Mathematics doesn’t provide a way to calculate square root and cube root accurately. So, if it says that the number is a perfect square or a perfect cube there is still some chance that it is not.

Compliment

1) compliment_to_power_of10

The Complement of a number is the difference between that number and the next higher power of 10. 3 is the complement of 7 (as next higher power of 7 is 10). 34 is the complement of 66 (as next higher power of 66 is 100).

Vedic Sutra:

Nikhilam Navatah Charamam Dasatah

which means, All from 9 and last from 10.

Details: We have to get the complement (Nikhilam) for the entire number by using 10 for the digit in the units place and by using 9 for the remaining digits.

Implementation:

import vedicpy as vedic

a= vedic.compliment.compliment_to_power_of10(123)
print(a)
>>> 877

Cube

1) cube_a_number_near_powerof10

Yavadunam Methord

Implementation:

import vedicpy as vedic

a= vedic.cube.cube_a_number_near_powerof10(103)
print(a)
>>> 1092727

2) cube_2digit_number

Cubing 2 digit number Example

Implementation:

import vedicpy as vedic

a= vedic.cube.cube_2digit_number(37)
print(a)
>>> 50653

Cuberoot

1) cuberoot_check

Let’s define something called a Digital root.

It is the sum obtained after iteratively adding the digits of a number, till a single digit remains.

For example,

  • For 345, digital root of 345 => 3 + 4 + 5 =12. Now, 12 => 1+2 = 3.12=1+2=3. So, digital root of 345 = 3.
  • For 12345678, digital root is 1+2+3+4+5+6+7+8 = 36. Now, 3+6 = 9. So, digital root of 12345678 = 9.

Turns out that for all perfect cubes, the digital root will either be 1,8,9. 0 is not included as 0 is a perfect cube of itself.

Anyways, if for a number xx you get a digital root that is not 1,8,9 you can confidently say that xx is NOT a perfect cube.

If the digital root is 1, 8, 9, 0 the number may or may not be a perfect cube.

Implementation:

import vedicpy as vedic

a= vedic.cuberoot.cuberoot_check(123)
print(a)
print(type(a))
>>> False
>>> <class 'bool'>

This function returns a boolean value.

2) cuberoot_under_1000000

cuberoot example

Implementation:

import vedicpy as vedic

a= vedic.cuberoot.cuberoot_under_1000000(175616)
print(a)
>>> 56

Vedic Mathematics doesn’t provide a way to cube root accurately. So, if it says that the number is a perfect cube there is still some chance that it is not.

Divisibility

1) divisibility_under10

divisibility test

Implementation:

import vedicpy as vedic

# divisibility_under10() function takes two arguments,
# first one is dividend and the other one is divisor
vedic.divisibility.divisibility_under10(108, 9)
>>> The number is divisible.

The function doesn’t return any value.

The divisibility test is only applicable for divisor less than 10 excluding 1 and 7.

Division

1) division_by9

division

Implementation:

import vedicpy as vedic

# division_by9() function takes a single argument that is divident.
vedic.division.division_by9(110)
>>> The quotent is: 12
>>> The reminder is: 2

The function doesn’t return any value.

Multiplication

1) multiply_by_9group

Multiply by 9 group

Implementation:

import vedicpy as vedic

a= vedic.multiply.multiply_by_9group(234)
print(a)
>>> 233766

2) multiply_base_near_powerof10

Near power of 10 Near power of 10

Implementation:

import vedicpy as vedic

a= vedic.multiply.multiply_base_near_powerof10(109,91)
print(a)
>>> 9919

3) multiply_equdigit_number

Equal digits Equal digits Equal digits

Implementation:

import vedicpy as vedic

a= vedic.multiply.multiply_equdigit_number(1234, 4567)
print(a)
>>> 5635678

4) multiply_lastdigit_sumto10

Last digit sum to 10 Last digit sum to 10

Implementation:

import vedicpy as vedic

a= vedic.multiply.multiply_lastdigit_sumto10(24, 26)
print(a)
>>> 624

5) multiply_by11

Multiply by 11 Multiply by 11

Implementation:

import vedicpy as vedic

a= vedic.multiply.multiply_by11(103)
print(a)
>>> 1133

6) multiply_by12

Multiply by 12

Implementation:

import vedicpy as vedic

a= vedic.multiply.multiply_by12(103)
print(a)
>>> 1236
Multiply by 13, 14, 15, 16, 17, 18, 19

7) multiply_by13

Implementation:

import vedicpy as vedic

a= vedic.multiply.multiply_by13(103)
print(a)
>>> 1339

8) multiply_by14

Implementation:

import vedicpy as vedic

a= vedic.multiply.multiply_by14(103)
print(a)
>>> 1442

9) multiply_by15

Implementation:

import vedicpy as vedic

a= vedic.multiply.multiply_by15(103)
print(a)
>>> 1545

10) multiply_by16

Implementation:

import vedicpy as vedic

a= vedic.multiply.multiply_by16(103)
print(a)
>>> 1648

11) multiply_by17

Implementation:

import vedicpy as vedic

a= vedic.multiply.multiply_by17(103)
print(a)
>>> 1751

12) multiply_by18

Implementation:

import vedicpy as vedic

a= vedic.multiply.multiply_by18(103)
print(a)
>>> 1854

13) multiply_by19

Implementation:

import vedicpy as vedic

a= vedic.multiply.multiply_by19(103)
print(a)
>>> 1957

Recurring

1) recuring_fractionto_decimal

Recurring numbers Recurring numbers

Implementation:

import vedicpy as vedic

result = vedic.recurring.recuring_fractionto_decimal(11, 19)
print(result)
>>> 0.578947

The functions returns a decimal value with a round off on 6 digits.

Square

1) square_ending5

square of ending with 5

Implementation:

import vedicpy as vedic

a= vedic.square.square_ending5(35)
print(a)
>>> 1225

2) square_near_powerof10

square near power of 10

Implementation:

import vedicpy as vedic

a= vedic.square.square_near_powerof10(98)
print(a)
>>> 9604

3) square_under100

square of 2 digit number square of 2 digit number

Implementation:

import vedicpy as vedic

a= vedic.square.square_under100(69)
print(a)
>>> 4761

4) square_from100_to1000

square of 3 digit number

Implementation:

import vedicpy as vedic

a= vedic.square.square_from100_to1000(983)
print(a)
>>> 966289

Squareroot

1) squareroot_check

squareroot example

If the number passes all the parameter then it can be a perfect square.

Implementation:

import vedicpy as vedic

a= vedic.squareroot.squareroot_check(144)
print(a)
print(type(a))
>>> True
>>> <class 'bool'>

This function returns a boolean value.

2) perfect_sqrt_under_sqof100

squareroot example squareroot example

Implementation:

import vedicpy as vedic

a= vedic.squareroot.perfect_sqrt_under_sqof100(144)
print(a)
>>> 12

Vedic Mathematics doesn’t provide a way to square root accurately. So, if it says that the number is a perfect square there is still some chance that it is not.

BSD 3-Clause License

Copyright (c) 2020, Utkarsh Mishra All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
  3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Help and Contact

Questions or Trouble related to package? Please contact utkarsh.um07@gmail.com.

Contributing

Contributions are welcome, and they are greatly appreciated! Every little bit helps, and credit will always be given.

You can contribute in many ways:

Types of Contributions

Report Bugs

Report bugs at https://github.com/utkarsh0702/vedicpy/issues.

If you are reporting a bug, please include:

  • Your operating system name and version.
  • Any details about your local setup that might be helpful in troubleshooting.
  • Detailed steps to reproduce the bug.

Fix Bugs

Look through the GitHub issues for bugs. Anything tagged with “bug” and “help wanted” is open to whoever wants to implement it.

Implement Features

Look through the GitHub issues for features. Anything tagged with “enhancement” and “help wanted” is open to whoever wants to implement it.

Write Documentation

vedicpy could always use more documentation, whether as part of the official vedicpy docs, in docstrings, or even on the web in blog posts, articles, and such.

Submit Feedback

The best way to send feedback is to file an issue at https://github.com/utkarsh0702/vedicpy/issues.

If you are proposing a feature:

  • Explain in detail how it would work.
  • Keep the scope as narrow as possible, to make it easier to implement.
  • Remember that this is a volunteer-driven project, and that contributions are welcome :)

Get Started!

Ready to contribute? Here’s how to set up vedicpy for local development.

  1. Fork the vedicpy repo on GitHub.

  2. Clone your fork locally:

    $ git clone git@github.com:your_name_here/vedicpy.git
    
  3. Install your local copy into a virtualenv. Assuming you have virtualenvwrapper installed, this is how you set up your fork for local development:

    $ mkvirtualenv other
    $ cd other/
    $ python setup.py develop
    
  4. Create a branch for local development:

    $ git checkout -b name-of-your-bugfix-or-feature
    

    Now you can make your changes locally.

  5. Commit your changes and push your branch to GitHub:

    $ git add .
    $ git commit -m "Your detailed description of your changes."
    $ git push origin name-of-your-bugfix-or-feature
    
  6. Submit a pull request through the GitHub website.

Pull Request Guidelines

Before you submit a pull request, check that it meets these guidelines:

  1. The pull request should include tests.
  2. If the pull request adds functionality, the docs should be updated. Put your new functionality into a function with a docstring, and add the feature to the list in README.rst.

Credits

Contributors

  • Utkarsh Mishra
  • Ashish Kumar