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
- 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
- Step 2: Write the Package Code: mathlib/__init__.py
This file makes the mathlib directory a package.
Next Create the python files for various kind of mathematical functions.# 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' ]
- 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.
- Step 4: Set Up the Package Metadata: setup.py
This setup.py file is used to install the package using pip. It includes metadata.# 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', ], )
- Step 5: Testing: To run the tests for this project, use pytest:
This will run the test suite located in the tests directory, ensuring that all functions work as expected.pytest tests/
- Step 6: Installation: You can install MathLib directly from the source code:
go to the cloned directory and then install it using:git clone https://github.com/arunp77/Data-engineering-tools.git
It can also be installed usingpip install -e . -v
pip
and is available at pypi link and at npm link. The docker container is available at docker image. - Github link: Complete python source code is available at: Github.
Some other interesting things to know:
- Visit my website on For Data, Big Data, Data-modeling, Datawarehouse, SQL, cloud-compute.
- Visit my website on Data engineering