Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Rokurolize/potion_problem

Repository files navigation

Potion Problem: E[τ] = e

A complete formal verification in Lean 4 proving that the expected hitting time equals Euler's number.

🎯 Main Result

Theorem: For the "Potion Problem" (media-yaku mondai, 媚薬問題), the expected hitting time E[τ] equals e.

theorem main_theorem : expected_hitting_time = exp 1

Status: ✅ PROVEN with zero sorries in main theorem chain.

📚 Mathematical Background

Original Problem Statement (媚薬問題)

女騎士「私に何を飲ませた!」
オーク「飲む前の感度を n 倍とした時に、感度を n+m 倍まで引き上げる薬だ。ここで m ∈ [0,1) は毎回の摂取ごとに独立に判定される。一方、通常時の感度を 1 倍として、お前の感度が 2 倍になるまでこれを飲ませる」
女騎士「私が媚薬を飲む回数の期待値はどれくらいになるんだ……?」

Behind this colorful fantasy narrative lies a profound mathematical problem connecting randomness with one of mathematics' most fundamental constants.

Mathematical Formulation

The Potion Problem asks: Given a sequence of independent uniform [0,1) random variables X₁, X₂, ..., what is the expected value of the stopping time τ = min{n : X₁ + X₂ + ... + Xₙ > 1}?

The elegant answer is e ≈ 2.718, proven through:

  1. Establishing the PMF: P(τ = n) = (n-1)/n! for n ≥ 2
  2. Computing expectation: E[τ] = ∑_{n=1}^∞ n · P(τ = n)
  3. Series manipulation showing this equals ∑_{n=0}^∞ 1/n! = e

🏗️ Project Structure

PotionProblem.lean              # Library entry point
PotionProblem/
├── Basic.lean                  # Core definitions and PMF
├── FactorialSeries.lean        # Summability of 1/n!
├── ProbabilityFoundations.lean # PMF properties  
├── SeriesAnalysis.lean         # Telescoping series proofs
├── IrwinHallTheory.lean        # Geometric insights (4 sorries)
├── Main.lean                   # Main theorem (0 sorries)
└── MainWithGeometry.lean       # Extended version with geometry

🚀 Quick Start

Prerequisites

Build Instructions

# Clone the repository
git clone https://github.com/Rokurolize/potion_problem.git
cd potion_problem

# Build the project
lake build

# Expected output:
# ⚠ [...] Warning: 4 sorries in IrwinHallTheory.lean
# Build completed successfully.

Verify Main Theorem

# Build only the main theorem module (zero sorries)
lake build PotionProblem.Main

# Check the main theorem
echo "import PotionProblem.Main
#check main_theorem" | lake env lean --stdin

📋 Module Dependencies

The proof is structured with clear dependencies:

Basic.lean (0 sorries)
├── FactorialSeries.lean (0 sorries)  
├── ProbabilityFoundations.lean (0 sorries)
    └── SeriesAnalysis.lean (0 sorries)
        └── Main.lean (0 sorries) ← **MAIN THEOREM**

Optional:
IrwinHallTheory.lean (4 sorries) → MainWithGeometry.lean

Key Property: Main theorem is completely independent of modules containing sorries.

🔍 Proof Strategy

Core Mathematical Approach

  1. PMF Establishment: Define hitting_time_pmf and prove it satisfies probability mass function axioms
  2. Summability: Prove ∑ 1/n! converges using exponential series theory
  3. Telescoping Identity: Show ∑_{k=0}^{n-1} (1/(k+1)! - 1/(k+2)!) = 1 - 1/(n+1)!
  4. Expectation Calculation: E[τ] = ∑_{n=2}^∞ n · (n-1)/n! = ∑_{n=0}^∞ 1/n! = e

Technical Implementation

  • API Verification: All mathlib4 APIs verified before use
  • Build-Driven Development: Compilation success after every change
  • Strategic Sorry Placement: Working sorries with clear continuation paths

🏆 Achievement

  • Main Theorem: Proven with ZERO sorries
  • Complete Build: All modules compile successfully
  • Clean Architecture: 6 focused modules with clear separation
  • Mathematical Rigor: Full formal verification in Lean 4

📖 Related Work

This formalization connects to several areas of mathematics:

  • Probability Theory: Expected values and infinite series convergence
  • Real Analysis: Exponential function and factorial series
  • Combinatorics: Stirling numbers and inclusion-exclusion (optional module)

🤝 Contributing

This is primarily a research/educational project demonstrating formal verification techniques. The main theorem is complete, but the optional geometric module contains 4 sorries for future work.

📄 License

MIT License

🙏 Acknowledgments

  • Lean 4 and mathlib4 communities
  • Inspired by the elegant mathematical problem known as the "Potion Problem"

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages