Skip to content

Latest commit

 

History

10 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

𝜎 Sigma Function

An experimental mathematical function based on repeated square-root convergence.

C C++ Python Rust MPFR GMP

A mathematical experiment by Gökhan Taha (gtaha23)


Overview

The Sigma Function (σ) is an experimental mathematical function that measures the number of successive square-root operations required for a positive integer to converge to 1 under a specified decimal precision.

Unlike the classical summation notation (Σ), this project defines σ as a function for measuring repeated square-root convergence.

The project currently provides high-performance implementations across 4 different programming languages.


Mathematical Definition

For a given positive integer $n$ and a decimal precision $p$, the function $\sigma(n, p)$ is rigorously defined as:

$$ \sigma(n, p) = \begin{cases} 0 & \text{if } n \le 1 \ \left\lceil \log_2 \left( \frac{\ln(n)}{\ln(1 + 10^{-p})} \right) \right\rceil & \text{if } n > 1 \end{cases} $$

Step-by-Step Derivation

  1. Repeated Square Roots: After $k$ iterations of applying square roots to $n$, the value becomes: $$v_k = n^{\frac{1}{2^k}}$$

  2. Convergence Condition: The loop terminates immediately when this value drops below or equal to the precision threshold ($1 + 10^{-p}$): $$n^{\frac{1}{2^k}} \le 1 + 10^{-p}$$

  3. Isolating $k$: Taking the natural logarithm ($\ln$) on both sides yields: $$\frac{1}{2^k} \ln(n) \le \ln(1 + 10^{-p}) \implies \frac{\ln(n)}{\ln(1 + 10^{-p})} \le 2^k$$

  4. Applying Base-2 Logarithm: Solving for $k$ using $\log_2$ gives: $$\log_2 \left( \frac{\ln(n)}{\ln(1 + 10^{-p})} \right) \le k$$

Since $k$ must be a discrete iteration count (an integer), we apply the ceiling function ($\lceil \dots \rceil$) to find the smallest valid number of steps.

The Fast-Path Optimization (Maclaurin Approximation)

To bypass thousands of redundant loop iterations, this project utilizes a highly efficient analytical estimate before running verification checks:

$$\text{estimate} = \left\lceil \log_2(\ln(n)) + p \cdot \log_2(10) \right\rceil = \left\lceil \log_2 \left( \frac{\ln(n)}{10^{-p}} \right) \right\rceil$$

Why it works: According to the Maclaurin series expansion, for extremely small values of $x$, $\ln(1 + x) \approx x$. Since $10^{-p}$ is microscopically small at high precisions, $\ln(1 + 10^{-p}) \approx 10^{-p}$, making the analytical shortcut incredibly precise.


Example Walkthrough

Suppose we evaluate σ(100, 10), meaning n = 100 and precision = 10. Repeated square roots produce the following sequence:

Iteration 0: 100
Iteration 1: 10
Iteration 2: 3.162277660
Iteration 3: 1.778279410
Iteration 4: 1.333521432
Iteration 5: 1.154781985
Iteration 6: 1.074607828
Iteration 7: 1.036632928
...

Eventually, the value becomes indistinguishable from 1 at 10 decimal places (≤ 1 + 10⁻¹⁰). The total count of these steps yields the final value of σ(100).


Features

  • 🚀 High-performance C/C++ implementations bypassing heavy loops via logarithmic fast-paths.
  • 🐍 Pure Python implementation out of the box with zero setup.
  • 🦀 Pure Rust alternative utilizing type-safe arbitrary precision.
  • 🔢 Arbitrary Precision Arithmetic preventing data loss during infinite-like convergence.
  • 📐 Novel Mathematical Framework modeling square-root decay boundaries.
  • 💻 Cross-Platform Compatibility across Linux, macOS, and Windows.

Project Structure

Sigma-Function/
│
├── C/                  # Core high-speed C implementation
│   ├── sigma.h
│   ├── sigma.c
│   └── test.c
│
├── C++/                # Object-oriented C++ layer
│   ├── sigmacpp.cpp
│   └── test.cpp
│
├── Python/             # Scripting and prototyping build
│   ├── sigma.py
│   └── test.py     
│
├── Rust/               # Modern memory-safe port
│   ├── src/
│        ├── lib.rs
│   │    └── main.rs 
|   ├── tests/
│   │    └── test.rs
│   ├── Cargo.lock
│   ├── Cargo.toml
│   └── rust-toolchain
│
├── .gitignore
└── README.md

Requirements & Installation

🔹 C / C++ Version

Requires the GNU Multi-Precision (GMP) and GNU MPFR libraries.

  • Ubuntu / Debian:
    sudo apt update && sudo apt install libgmp-dev libmpfr-dev gcc g++
  • Compilation:
    gcc sigma.c -o sigma -lmpfr -lgmp
    g++ sigmacpp.cpp -o sigmacpp -lmpfr -lgmp
  • Execution:
    ./sigma

🔹 Python Version

Requires Python 3.9+. No external dependencies are needed.

python Python/sigma.py

🔹 Rust Version

Utilizes high-precision crates (astro-float, astro-float-macro, astro-float-num).

cd Rust
cargo build --release
cargo run

Benchmark & Implementations Matrix

Language Precision Backend Performance Rating Status
C GNU MPFR + GMP 🚀 Ultra Fast (Baseline) ✅ Stable
C++ GNU MPFR + GMP 🚀 Ultra Fast ✅ Stable
Rust astro-float + std 🛡️ Safe / Moderate ✅ Stable
Python decimal.Decimal 🐢 Slower / Portable ✅ Stable

Why Arbitrary Precision?

Standard IEEE 754 floating-point numbers (double, float) quickly return under repeated square roots because numbers converge to $1$ so fast that needed information gets destroyed. To maintain exact mathematical results across platforms, explicit arbitrary-precision libraries are mandatory.


Roadmap

  • Pure Python prototype
  • High-performance C core port
  • Safe Rust port
  • Native C++ port
  • Detailed mathematical description paper
  • Comprehensive performance benchmarks
  • Basic Testing

Contributing

Contributions are heavily welcome! Whether you have ideas for vectorization (AVX/SIMD) optimizations, new language ports (Go, Zig, Julia), or unique mathematical insights about the behavior of $\sigma(n, p)$, feel free to open an Issue or submit a Pull Request.


Author

gtaha


"Exploring mathematics through computation."

⭐ If you find this project interesting or educational, consider giving it a star!

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages