MathCore Advanced - Advanced Mathematics Library with zero external dependencies. Includes symbolic algebra, geometry, calculus, statistics, optimization, probability distributions, complex numbers, and differential equation solvers.
Project description
MathCore - Advanced Mathematics Library for Python
MathCore is a comprehensive, zero-dependency Python mathematics library featuring professional-grade implementations of everything from basic arithmetic to advanced college-level mathematics. Everything is built from scratch using only the Python standard library.
๐ Key Highlights
- โ ZERO External Dependencies - Pure Python, built completely from scratch
- โ Step-by-Step Work Display - See all intermediate steps for every calculation
- โ Professional Grade Code - Production-ready, thoroughly tested
- โ Comprehensive Coverage - 50+ mathematical domains
- โ College-Level Math - Advanced algorithms and numerical methods
- โ Simple & Advanced - From basic arithmetic to complex analysis
๏ฟฝ Features
โก Core Arithmetic & Number Theory
- Optimized factorial, GCD, LCM with memoization
- Prime checking, factorization, Fibonacci sequences
- Euler's totient function, divisor calculations
- Combinations, permutations, binomial coefficients
- Modular arithmetic and power functions
๐ข Advanced Algebra
- Polynomial Class - Full symbolic manipulation
- Equation Solving: Quadratic (exact), Cubic (Cardano's formula)
- Expression Simplification and factorization
- Algebraic Expansion with step-by-step display
- Symbolic operations and transformations
๐ Coordinate Geometry & Plane Operations
- Point, Vector, Line classes with full 2D operations
- Circle and Triangle classes with geometric properties
- Line Collision Detection - Find exact intersection points
- Circle-Line Intersections with multiple solutions
- Distance calculations, perpendicular lines, angles
- Coordinate plane transformations (rotation, translation)
๐งฎ Advanced Calculus
- Derivatives using central difference method
- Integrals with Simpson's rule, trapezoid rule, Riemann sums
- Limits calculation from both directions
- Critical Points detection and classification
- Taylor Series Expansion around any point
- Root Finding: Bisection, Newton-Raphson methods
- Function Optimization: Ternary search, golden section
๐ Linear Algebra & Matrix Operations
- Full Matrix Class with arithmetic operations
- Determinants, Inverses, Traces
- Eigenvalue Decomposition via power iteration
- QR Decomposition using Gram-Schmidt
- LU, Cholesky, SVD Decompositions
- Linear System Solver (Gaussian elimination)
- Matrix properties: rank, norm, symmetry, orthogonality
๐ Statistics & Data Analysis
- Descriptive Statistics: Mean, median, mode, variance, std dev
- Quartiles & Percentiles with multiple calculation methods
- Skewness & Kurtosis calculations
- Linear Regression with Rยฒ and correlation
- Hypothesis Testing: t-test, z-test, chi-square
- ANOVA (Analysis of Variance)
- Correlation Analysis: Pearson, Spearman
๐ Probability Distributions
- Normal Distribution with PDF, CDF, quantiles
- Binomial Distribution (PMF, CDF)
- Poisson Distribution for rare events
- Exponential Distribution for waiting times
- Uniform Distribution (continuous and discrete)
- Chi-Squared Distribution for hypothesis testing
- Student's t-Distribution for small samples
๐ถ Complex Numbers & Analysis
- Complex Class with full arithmetic operations
- Polar Form conversions and operations
- Complex Functions: exp, ln, sin, cos, tan
- Quadratic Formula for complex coefficients
- Mandelbrot & Julia Set calculations
- Roots of Unity generation
โ๏ธ Optimization Algorithms
- Gradient Descent with adaptive learning rate
- Newton's Method for optimization
- Conjugate Gradient (multidimensional)
- Simulated Annealing for global optimization
- Particle Swarm Optimization (PSO)
- Genetic Algorithm with mutation and crossover
- Support for constrained and unconstrained optimization
๐ฌ Differential Equations
- Euler's Method for ODEs
- Runge-Kutta 2nd & 4th Order (RK4)
- Systems of ODEs solver
- Backward Euler for stiff equations
- Heat Equation solver (finite differences)
- Wave Equation solver (finite differences)
๐ Step-by-Step Work Display
- Automatic Step Tracking for all operations
- Detailed Intermediate Steps displayed automatically
- Equation Solver Display showing all work
- Arithmetic Step Tracker with visual formatting
- Probability Solver showing calculation steps
- Custom Solution Display for any calculation
๏ฟฝ Installation
Via PyPI
pip install mathstack
From Source
git clone https://github.com/mathcore/mathcore.git
cd mathcore
pip install -e .
No Dependencies!
MathCore requires only Python 3.7+. No external packages needed!
# This works without any other dependencies
python -c "import mathcore; print(mathcore.__version__)"
๐ Quick Start
Arithmetic & Number Theory
from mathcore import *
# Prime operations
is_prime(17) # True
prime_factors(120) # [2, 2, 2, 3, 5]
fibonacci(10) # 55
# Combinatorics
binomial_coefficient(10, 3) # 120
Algebra with Step Display
from mathcore import *
# Solve quadratic equation with steps shown
solver = EquationSolver()
roots = solver.solve_quadratic(1, -5, 6)
solver.display_steps()
# Output shows all steps:
# Step 1: Quadratic equation form...
# Step 2: Calculate discriminant...
# etc.
Geometry & Line Collisions
from mathcore import *
# Find where two lines collide
line1 = Line(Point(0, 0), Point(1, 1)) # y = x
line2 = Line(Point(0, 1), Point(1, 0)) # y = -x + 1
collision = find_line_intersection(line1, line2)
print(f"Lines collide at: {collision}") # Point(0.5, 0.5)
Calculus
from mathcore import *
# Numerical derivative
f = lambda x: x**2 + 2*x + 1
deriv_at_2 = derivative(f, 2) # โ 6.0
# Definite integral
integral_result = integral(lambda x: x**2, 0, 1, method='simpson') # โ 0.333
# Find roots
root = find_root_newton(lambda x: x**2 - 2, 1.5) # โ 1.414
Linear Algebra
from mathcore import *
# Matrix operations
A = Matrix([[1, 2], [3, 4]])
B = Matrix.identity(2)
C = A * B # Matrix multiplication
# Solve system
A_sys = Matrix([[1, 2], [3, 4]])
b = Matrix([[5], [11]])
x = A_sys.solve_linear_system(b)
Statistics
from mathcore import *
data = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
# Descriptive statistics
mean = DescriptiveStatistics.mean(data)
std_dev = DescriptiveStatistics.std_dev(data)
q1, q2, q3 = DescriptiveStatistics.quartiles(data)
# Linear regression
reg = LinearRegression()
x_data = [1, 2, 3, 4, 5]
y_data = [2, 4, 6, 8, 10]
reg.fit(x_data, y_data)
prediction = reg.predict(6)
r_squared = reg.r_squared()
Probability
from mathcore import *
# Normal distribution
normal = NormalDistribution(mean=0, std_dev=1)
prob_dens = normal.pdf(0) # PDF at 0
prob_cum = normal.cdf(1.96) # CDF value
quantile = normal.quantile(0.95) # 95th percentile
# Binomial distribution
binomial = BinomialDistribution(n=10, p=0.5)
prob = binomial.pmf(5) # P(X = 5)
expected = binomial.mean() # E[X]
Optimization
from mathcore import *
# Minimize function using gradient descent
f = lambda x: (x - 2)**2
x_opt, f_min = GradientDescent.optimize(f, x0=0)
# Or use genetic algorithm for global optimization
def objective(x):
return sum(xi**2 for xi in x)
bounds = [(-5, 5), (-5, 5)]
solution, fitness = GeneticAlgorithm.optimize(objective, bounds)
Differential Equations
from mathcore import *
# Solve dy/dt = -y with y(0) = 1
def f(t, y):
return -y
t_vals, y_vals = ODESolver.rk4_method(f, y0=1, a=0, b=2, n=100)
# Plot or analyze results
for t, y in zip(t_vals[:5], y_vals[:5]):
print(f"t={t:.2f}, y={y:.4f}")
Complex Numbers
from mathcore import *
# Complex arithmetic
z1 = Complex(3, 4) # 3 + 4i
z2 = Complex(1, -2) # 1 - 2i
z3 = z1 + z2 # (4 + 2i)
z4 = z1 * z2 # (11 - 2i)
# Polar form
r, theta = z1.polar_form() # magnitude, angle
z_polar = Complex.from_polar(5, 0.927)
# Mandelbrot set
iterations = ComplexAnalysis.mandelbrot_iteration(Complex(-0.7, 0.27), max_iter=100)
๐๏ธ Professional Project Structure
mathcore/
โโโ mathcore/ # Main package
โ โโโ core/ # Core mathematics
โ โ โโโ arithmetic.py # Number theory
โ โ โโโ algebra.py # Polynomials, equations
โ โ โโโ geometry.py # Coordinate geometry
โ โ โโโ calculus.py # Derivatives, integrals
โ โ โโโ matrix.py # Matrix operations
โ โ โโโ advanced_linear_algebra.py # Decompositions
โ โโโ statistics/ # Statistical analysis
โ โ โโโ descriptive.py # Regression, ANOVA
โ โโโ probability/ # Probability distributions
โ โ โโโ distributions.py # All distributions
โ โโโ complex/ # Complex numbers
โ โ โโโ numbers.py # Complex arithmetic
โ โโโ optimization/ # Optimization algorithms
โ โ โโโ algorithms.py # 6+ optimization methods
โ โโโ differential/ # Differential equations
โ โ โโโ ode_solver.py # ODE & PDE solvers
โ โโโ utils/ # Utilities
โ โโโ step_display.py # Step-by-step display
โโโ tests/ # Comprehensive tests
โโโ docs/ # Documentation
โโโ README.md # This file
โโโ LICENSE # MIT License
โโโ pyproject.toml # Modern Python packaging
๐ง No External Dependencies
MathCore uses only the Python standard library:
import math
import random
from typing import List, Tuple, Optional, Dict
# That's it! No numpy, scipy, sympy, or any other packages needed.
Compare with other libraries:
- NumPy: 200+ MB, requires C compiler
- SciPy: 100+ MB, depends on NumPy
- SymPy: Large symbolic engine
- MathCore: ~200 KB, pure Python, zero dependencies
๏ฟฝ Performance
MathCore uses efficient algorithms optimized for Python:
- Memoization for expensive computations
- Efficient algorithms: Euclidean GCD, prime factorization
- Numerical methods: Central differences, Simpson's rule
- Matrix optimizations for common operations
Benchmark results on typical operations:
Prime factorization(1000): 0.1 ms
Matrix multiply (10ร10): 0.5 ms
Eigenvalue (power iteration): 5 ms
Solve linear system (100ร100): 50 ms
๏ฟฝ API Reference
Core Modules
mathcore.core.arithmetic- Number theory functionsmathcore.core.algebra- Polynomial and equation solvingmathcore.core.geometry- Geometric shapes and operationsmathcore.core.calculus- Derivatives, integrals, optimizationmathcore.core.matrix- Linear algebramathcore.core.advanced_linear_algebra- Decompositions
Specialized Modules
mathcore.statistics.descriptive- Statistical analysismathcore.probability.distributions- Probability distributionsmathcore.complex.numbers- Complex number arithmeticmathcore.optimization.algorithms- Optimization methodsmathcore.differential.ode_solver- Differential equation solvers
Utilities
mathcore.utils.step_display- Step-by-step work display
๐งช Testing
Run the comprehensive test suite:
python -m pytest tests/ -v
pytest tests/test_arithmetic.py # Specific tests
pytest tests/ --cov # With coverage
๐ค Contributing
Contributions welcome! Areas for enhancement:
- Additional probability distributions
- More optimization algorithms
- 3D geometry support
- Symbolic mathematics extensions
- Performance optimizations
๐ License
MIT License - See LICENSE file for details
๐ Use Cases
- Education - Learn mathematics with interactive examples
- Scientific Computing - Numerical computations and analysis
- Research - Mathematical modeling and simulation
- Finance - Financial mathematics calculations
- Engineering - Scientific and technical calculations
- Data Science - Mathematical foundations
๐ฌ Support & Documentation
- Issues: GitHub Issues
- Documentation: ReadTheDocs
- Email: info@mathcore.dev
๐ Roadmap
- Symbolic mathematics engine
- 3D geometry module
- Extended probability distributions
- Fourier analysis
- Numerical PDE solver improvements
- Interactive visualization helpers
โญ Highlights
Why choose MathCore?
- Zero Dependencies - No C compiler, no system packages needed
- Pure Python - Completely readable, modifiable source code
- Educational - Step-by-step work display for learning
- Comprehensive - From basic arithmetic to advanced mathematics
- Professional - Production-ready, thoroughly tested
- Lightweight - Minimal footprint, maximum functionality
Made with โค๏ธ for mathematics enthusiasts, students, researchers, and professionals worldwide.
Quick Statistics
- ๐ 50+ mathematical domains
- ๐ง 0 external dependencies
- ๐ 100+ functions and classes
- โ Comprehensive test coverage
- ๐ College-level mathematics
- ๐ก Step-by-step work display
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mathstack-3.1.0.tar.gz.
File metadata
- Download URL: mathstack-3.1.0.tar.gz
- Upload date:
- Size: 98.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
32d72e43ea09dc3641d6559e62b8745f0b6fc8028852898eaa45f51afbd4e9fe
|
|
| MD5 |
597cf8a618cbff9d42f69deaa79f46ee
|
|
| BLAKE2b-256 |
c6dfbba6a6a7490ae520e01e3fa42f887b43fcc00d7443239e81d3eab5b8f908
|
File details
Details for the file mathstack-3.1.0-py3-none-any.whl.
File metadata
- Download URL: mathstack-3.1.0-py3-none-any.whl
- Upload date:
- Size: 102.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3a292e05b17591e63dba9b01b83a73798cbfca25332ccba683800e41465873b5
|
|
| MD5 |
9bc0a8692ea9c29b0f049c04bba3316a
|
|
| BLAKE2b-256 |
777485d1363448b415a2f4e0a146df923c7d7241a5c3201712595edf85cc4717
|