Gauss Int
A Rust library for Gaussian integer arithmetic and number theory.
What is a Gaussian Integer?
A Gaussian integer is a complex number a + bi where both a and b are integers. Gaussian integers form a Euclidean domain, supporting division with remainder and greatest common divisors via the Euclidean algorithm.
Features
Gaussian Integer (GaussInt)
- Arithmetic: addition, subtraction, multiplication, negation
- Division with remainder — correct Gaussian integer division using nearest-integer rounding, guaranteeing
N(remainder) < N(divisor) - GCD — Euclidean algorithm with canonicalization to the first quadrant
- Exponentiation by squaring (
pow_u32) - Norm, conjugate, unit detection
Number Theory
- Prime testing — Baillie-PSW approach (deterministic for 64-bit, multiple Miller-Rabin bases for larger numbers)
- Factorization — trial division by small primes + Pollard's Rho
- Euler's totient φ(n) via prime factorization
- Jacobi symbol (a/n) via quadratic reciprocity
- Chinese Remainder Theorem — solve x ≡ a_i (mod m_i) for pairwise coprime moduli
- Gaussian prime detection — full classification in ℤ[i]
CLI
A command-line tool exposing all functionality:
# Gaussian integer operations
# Number theory
Library Usage
use ;
use number_theory;
// Gaussian integer arithmetic
let z = from_i64;
let conj = z.conjugate;
let = z.div_rem.unwrap;
// GCD
let g = from_i64.gcd;
// Primality testing
assert!;
// Factorization
let factors = factorize;
// Euler's totient
assert_eq!;
// Chinese Remainder Theorem
let congruences = vec!;
let x = crt.unwrap;
// Gaussian prime detection
assert!;
assert!;
Testing
Project Structure
src/
├── lib.rs # Module exports
├── big_int.rs # BigInt wrapper around num-bigint
├── gauss_int.rs # Gaussian integer implementation
├── number_theory.rs # Primality, factorization, totient, Jacobi, CRT
└── main.rs # CLI binary
tests/
└── integration_tests.rs
Dependencies
num-bigint— arbitrary precision integersnum-traits— numerical traits (Zero, One, Signed)num-integer— integer operations (gcd, is_even)clap— CLI argument parsing