MOMA: Moving Origin Modular Arithmetic
MOMA is a Rust framework for exploring complex systems including cosmology, number theory, algorithmic data analysis and cryptography through the lens of Moving Origin Modular Arithmetic.
It should interest anyone who is interested in a novel, relational framework for analyzing the properties of complex systems.
The Core Idea: A Barycenter for Numbers
The inspiration for this crate comes from the concept of a barycenter in astrophysics. Just as the Earth and Moon orbit a common center of mass that is not the exact center of the Earth, MOMA treats modular arithmetic as a system where the "zero point" or "origin" is not fixed.
This origin shifts dynamically based on a contextual value—typically a prime number p—and the chosen OriginStrategy. This provides a novel relational framework for analyzing the properties of integers, much like understanding the true orbital mechanics of our solar system.
The original inspiration came from this NASA article: What Is a Barycenter?
Core Concepts
The MOMA framework is built on a few simple but powerful concepts:
-
MomaRing: The primary object for all calculations. A ring is defined by amodulusand a chosenOriginStrategy. -
OriginStrategy: A trait that defines how the origin moves. This makes the framework highly extensible. -
Analysis Tools: A suite of modular tools for deeper analysis:
MassField: Maps primes to the "composite mass" in the gap immediately following them.OriginDrift: Measures the volatility or "drift" of MOMA signatures for any given strategy.CompositeInfluence: Models the "gravitational" influence of nearby composite numbers.GoldbachProjector: An efficient tool for finding prime pairs for even numbers.Entropy: A generic calculator for the Shannon entropy of a sequence.
Features
- Flexible Core: A powerful and extensible system based on the
MomaRingandOriginStrategytrait. - Advanced Analysis Tools: A suite of high-level structs for statistical and number-theoretic analysis.
- Cryptographic Primitives: Demonstrates how MOMA can be used to build components like a Key Derivation Function.
- Prime Number Utilities: A helper
primesmodule for primality testing and prime generation. - Pure Rust: Built with safe, idiomatic Rust.
Installation
Add MOMA to your Cargo.toml:
[]
= "0.1.9" # Replace with the latest version
Quick Start
The easiest way to get started is to create a MomaRing and calculate the "signature" of a prime.
use MomaRing;
use primes;
use strategy;
// 1. Create a MOMA ring with modulus 37 and the PrimeGap strategy.
let ring = new;
// 2. Let's analyze the prime p = 29.
let p = 29;
// 3. Calculate the MOMA signature.
// The origin for p=29 is (29 - 23) = 6.
// The value is p + p_prev = 29 + 23 = 52.
// The residue is (52 + 6) % 37 = 21.
let signature = ring.signature;
println!;
assert_eq!;
Exploring Further
MOMA is more than just a simple calculator; it's a toolkit for exploration.
Example 1: Finding Goldbach Pairs
Use the GoldbachProjector to efficiently find prime pairs for an even number.
use GoldbachProjector;
// Create a projector with a database of primes up to 1000.
let projector = new;
// Find all pairs for the number 96.
let pairs = projector.project;
println!;
// Example pair: (7, 89)
assert!;
Example 2: Measuring Strategy Volatility
Use OriginDrift to compare the stability of different OriginStrategy implementations.
use OriginDrift;
use strategy;
use primes;
// Create a drift analyzer for the PrimeGap strategy.
let mut drift_analyzer = new;
// Feed it a sequence of primes.
let mut p = 3;
for _ in 0..10
// A higher drift magnitude means the strategy is more volatile.
println!;
Contributing
Contributions are welcome! If you have an idea for a new OriginStrategy, an analysis tool, or find a bug, please feel free to open an issue or submit a pull request.
License
This project is licensed under either of:
- Apache License, Version 2.0, (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.