MathLib: A Simple Python Library for Basic Mathematical Operations

Introduction

MathLib is a simple Python library for basic mathematical operations, including arithmetic and algebraic functions. It's designed to be easy to use and extendable for more advanced mathematical operations.

Features

  • Arithmetic Operations: Addition, subtraction, multiplication, and division.
  • Algebraic Operations: Solving simple linear equations.

Important steps

  1. Step 1: Set Up the Project Structure: First, set up your directory structure:
                                MathLib/
                                ├── mathlib/
                                │   ├── __init__.py
                                │   ├── arithmetic.py
                                │   ├── algebra.py
                                │   ├── complex_numbers.py
                                │   ├── logarithmic.py
                                │   ├── matrix_operations.py
                                │   ├── power_roots.py
                                │   ├── random_utils.py
                                │   ├── statistics.py
                                │   ├── trigonometry.py
                                │   └── utility.py
                                ├── tests/
                                │   ├── test_arithmetic.py
                                │   ├── test_algebra.py
                                │   ├── test_complex_numbers.py
                                │   ├── test_logarithmic.py
                                │   ├── test_matrix_operations.py
                                │   ├── test_power_roots.py
                                │   ├── test_random_utils.py
                                │   ├── test_statistics.py
                                │   ├── test_trigonometry.py
                                │   └── test_utility.py
                                ├── setup.py
                                ├── README.md
                                └── LICENSE
                            
  2. Step 2: Write the Package Code: mathlib/__init__.py This file makes the mathlib directory a package.
    
                                    # mathlib/__init__.py
    
                                    from .arithmetic import add, subtract, multiply, divide, power
                                    from .algebra import solve_linear, solve_quadratic
                                    from .trigonometry import sin, cos, tan, arcsin, arccos, arctan
                                    from .statistics import mean, median, variance, standard_deviation
                                    from .matrix_operations import matrix_addition, matrix_multiplication, matrix_determinant, matrix_inverse
                                    from .complex_numbers import complex_addition, complex_subtraction, complex_multiplication, complex_division, complex_magnitude, complex_phase
                                    from .random_utils import random_integer, random_float
                                    from .utility import factorial, gcd, lcm
                                    
                                    __all__ = [
                                        'add', 'subtract', 'multiply', 'divide', 'power',
                                        'solve_linear', 'solve_quadratic',
                                        'sin', 'cos', 'tan', 'arcsin', 'arccos', 'arctan',
                                        'mean', 'median', 'variance', 'standard_deviation',
                                        'matrix_addition', 'matrix_multiplication', 'matrix_determinant', 'matrix_inverse',
                                        'complex_addition', 'complex_subtraction', 'complex_multiplication', 'complex_division', 'complex_magnitude', 'complex_phase',
                                        'random_integer', 'random_float',
                                        'factorial', 'gcd', 'lcm'
                                    ]
                                
    Next Create the python files for various kind of mathematical functions.
  3. Step 3: Write Tests: To ensure your package functions as expected, it's essential to write some basic tests. Pytest is a powerful tool for this purpose and is widely recommended for Python projects. It helps you write simple and scalable test cases to validate your code.
  4. Step 4: Set Up the Package Metadata: setup.py
    
                                    # setup.py
    
                                    from setuptools import setup, find_packages
                                    
                                    setup(
                                        name='mathlib',
                                        version='0.1',
                                        packages=find_packages(),
                                        description='A simple math library with basic operations',
                                        long_description=open('README.md').read(),
                                        long_description_content_type='text/markdown',
                                        author='Arun Kumar Pandey',
                                        author_email='arunp77@gmail.com',
                                        url='https://github.com/arunp77/mathlib-package.git',
                                        license='MIT',
                                        install_requires=[],
                                        classifiers=[
                                            'Programming Language :: Python :: 3',
                                            'License :: OSI Approved :: MIT License',
                                            'Operating System :: OS Independent',
                                        ],
                                    )                                
                                
    This setup.py file is used to install the package using pip. It includes metadata.
  5. Step 5: Testing: To run the tests for this project, use pytest:
    pytest tests/
    This will run the test suite located in the tests directory, ensuring that all functions work as expected.
  6. Step 6: Installation: You can install MathLib directly from the source code:
    git clone https://github.com/arunp77/Data-engineering-tools.git
    go to the cloned directory and then install it using:
    pip install -e . -v
    It can also be installed using pip and is available at pypi link and at npm link. The docker container is available at docker image.
  7. Github link: Complete python source code is available at: Github.

Some other interesting things to know: