minimath is a lightweight, pure-Python library for performing basic mathematical operations and utilities. It provides essential functions ranging from basic arithmetic to algebra and geometry, all implemented without any external libraries like math or numpy
factorial(n): Calculate the factorial of a numbern.fibonacci(n): Find the nth Fibonacci number.gcd(a, b): Calculate the greatest common divisor (GCD).lcm(a, b): Calculate the least common multiple (LCM).is_prime(n): Check if a numbernis prime.primes_upto(n): Generate all primes ≤n.digit_sum(n): Calculate the sum of the digits ofn.nCr(n, r): Calculate combinations ofnitems takenrat a time.nPr(n, r): Calculate permutations ofnitems takenrat a time.
quadratic_roots(a, b, c): Solve the quadratic equationax² + bx + c = 0.
distance(p1, p2): Calculate the Euclidean distance between pointsp1andp2.triangle_area(a, b, c): Calculate the area of a triangle using Heron's formula.circle_area(r): Calculate the area of a circle with radiusr.
pi(): Returns First 10 Digits of pi.e(): Returns First 10 Digits of e.
pip install git+https://github.com/CYCNO/minimath.git
from minimath import MiniMath
mm = MiniMath()
# Basic Functions
print(mm.factorial(5)) # 120
print(mm.fibonacci(10)) # 55
print(mm.gcd(24, 36)) # 12
print(mm.lcm(4, 6)) # 12
print(mm.is_prime(7)) # True
print(mm.primes_upto(20)) # [2, 3, 5, 7, 11, 13, 17, 19]
# Number Utilities
print(mm.digit_sum(123)) # 6
print(mm.nCr(5, 2)) # 10
print(mm.nPr(5, 2)) # 20
# Algebra / Functions
print(mm.quadratic_roots(1, -3, 2)) # [2.0, 1.0]
# Geometry
print(mm.distance((0, 0), (3, 4))) # 5.0
print(mm.triangle_area(3, 4, 5)) # 6.0
print(mm.circle_area(5)) # 78.53981633974483
print(mm.circle_circumference(5)) # 31.41592653589793Click to view instructions for reporting issues
-
Check Existing Issues: Before creating a new issue, check if it’s already reported by searching through the issues page.
-
Create a New Issue: If the issue isn’t listed, click on New Issue and provide:
- A clear description of the problem.
- Steps to reproduce the issue.
- Expected and actual results.
- Any relevant code snippets or error messages.
We appreciate your help in improving minimath!
Click to view instructions for reporting issues
We welcome contributions to minimath! To add a new function:
-
Create a New Module/Class: If your function doesn’t fit into existing categories (e.g., basic, algebra, geometry), create a new file and class.
Example:
number_theory.py, and aNumberTheoryclass. -
Update
MiniMath: After adding a new class, update theMiniMathclass inminimath.pyto import your new class:from .basic import Basic from .algebra import Algebra from .geometry import Geometry from .your_new_module import YourNewClass class MiniMath(Basic, Algebra, Geometry, YourNewClass): pass ```
-
Create a Pull Request : Fork the repo, create a branch for your changes, and submit a pull request.
- MIT