Skip to content

nyaks1/Mathematical-Optimization-in-Python

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Mathematical Optimization in Python

Python Version License: MIT

"Don't be the guy digging for gold; be the guy selling the shovel."

This repository serves as an educational framework and optimization sandbox. It documents the evolution of algorithmic problem-solving—specifically covering foundational mathematical challenges (such as Project Euler problems 1–100)—by transforming naive, brute-force iterations into elite, highly optimized, production-ready code.

The core objective here is pedagogy and performance engineering. Instead of presenting static code-dumps, each module focuses on architectural scalability, strict type safety, unit testing, and mathematical shortcuts that drop time complexies from linear $O(n)$ down to constant time $O(1)$.


🚀 Architectural Standards

Every solution in this repository is treated like a critical micro-component of a high-throughput backend system. We enforce:

  • Strict Type Hinting: Utilizing Python's typing module to ensure static analysis compliance.
  • Comprehensive Docstrings: Clearly detailing execution context, edge-case constraints, and Big O complexity analysis.
  • Algorithmic Evolution: Documenting the transition from Naive $\rightarrow$ Idomatic $\rightarrow$ Mathematical Mastery.
  • Robust Testing: Standardized unit tests using pytest to guarantee deterministic results across all optimization rewrites.

Optimization Catalog & Methodology

Below is the index of algorithmic implementations. Each directory contains the source module, optimized variants, and formal analysis.

Problem / Concept Core Mathematical Focus Naive Complexity Optimized Complexity Status
001: Multiples of 3 & 5 Arithmetic Progressions / Inclusion-Exclusion $O(n)$ Time | $O(1)$ Space $O(1)$ Time | $O(1)$ Space 🟢 Complete
002: Even Fibonacci Linear Recurrence / Golden Ratio Matrix $O(n)$ Time | $O(1)$ Space $O(\log n)$ Time | $O(1)$ Space 🟡 In Progress
003: Prime Factorization Trial Division / Sieve of Eratosthenes $O(n)$ Time | $O(1)$ Space $O(\sqrt{n})$ Time | $O(1)$ Space ⏳ Planned

Deep Dive Example: Problem 001 (Multiples of 3 and 5)

To illustrate the methodology of this repository, consider the problem of summing all multiples of 3 or 5 below a given limit $N$.

1. The Naive Approach (Linear Check)

A standard loop evaluates every single integer up to $N$. While readable, this scales poorly as $N \to \infty$.

# Linear Time Optimization (Idiomatic Python)
def sum_multiples_loop(limit: int) -> int:
    return sum(i for i in range(limit) if i % 3 == 0 or i % 5 == 0)

About

A curated gallery of algorithmic efficiency, discrete mathematics, and software engineering principles applied to computational problems (Problems 1–100). Focuses on transitioning from brute-force scripts to production-grade

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages