factorial_engine

Crates.iofactorial_engine
lib.rsfactorial_engine
version0.2.0
created_at2025-08-15 17:52:17.106587+00
updated_at2025-11-15 17:29:31.90808+00
descriptionA library for producing factorials
homepage
repositoryhttps://github.com/Neil-Crago/factorial_engine
max_upload_size
id1797225
size19,516
Neil Crago (Neil-Crago)

documentation

https://docs.rs/factorial_engine

README

Crates.io Docs.rs License: MIT OR Apache-2.0 Rust

Factorial Engine

A high-performance, zero-error Rust crate for computing the prime factorization of factorials (n!).

This engine is designed as a robust, backend computational tool. It uses Legendre's Formula to calculate prime exponents directly, completely avoiding the need to compute or store the immense values of n! itself. This ensures exceptional performance and prevents any possibility of integer overflow, even for very large n.

Features

  • High Performance: Employs Legendre's Formula for direct calculation of prime exponents.
  • Zero Error: Avoids large number arithmetic entirely, making it robust and free from overflow errors.
  • Efficient Prime Generation: Includes an optimized Sieve of Eratosthenes for on-demand prime generation and caching.
  • Clean API: Provides a simple and clear interface for getting the full prime factorization of n!.

Usage

Add this crate to your Cargo.toml:

[dependencies]
factorial_engine = "0.1.8" # Or the latest version

Example

use factorial_engine::FactorialEngine;
use std::collections::HashMap;

fn main() {
    // Initialize the engine. Can optionally pre-sieve primes.
    let mut engine = FactorialEngine::new(Some(100));

    let n = 50;
    let factors: HashMap<u64, u64> = engine.get_factorial_factorization(n);

    // The result is a map of {prime: exponent}.
    println!("Prime factorization of {}!: {:?}", n, factors);

    // Example: The exponent of 2 in 50! is 47.
    assert_eq!(*factors.get(&2).unwrap(), 47);
}

Purpose

This crate serves as a foundational block for applications in number theory, combinatorics, and computational mathematics. It is designed to be a reliable, "black-box" dependency that provides factorial factorization data with maximum efficiency and correctness.

Author

Neil Crago — experimental mathematician

Related Crates

This crate is part of a collection of crates by the same author: These include:-

  • MOMA
  • MOMA_simulation_engine
  • Fractal_Algebra
  • tma_engine
  • fa_slow_ai
Commit count: 4

cargo fmt