main.rs

3.0 kB · rust · 105 lines

1mod coprime;2mod design;34use num_bigint::BigUint;5use std::time::Instant;67const COMPLEMENT_N: u32 = 14;8const PASCAL_N: u32 = 12;9const DESIGN_N: usize = 14;10const AFFINE_N: usize = 8;11const ORBIT_N: usize = 2;1213fn verdict(agree: bool) -> &'static str {14    if agree {15        "PASS"16    } else {17        "FAIL"18    }19}2021fn a396934(top: u32) {22    let clock = Instant::now();23    let rows: Vec<u64> = (0..=top).map(coprime::by_rows).collect();24    println!(25        "A396934 row walk n = 0..{} in {:.1}s",26        top,27        clock.elapsed().as_secs_f64()28    );29    let (low, tiny) = (COMPLEMENT_N.min(top), PASCAL_N.min(top));30    let complements: Vec<u64> = (0..=low).map(coprime::by_complement).collect();31    let pascal: Vec<u64> = (0..=tiny).map(coprime::by_pascal).collect();32    println!(33        "A396934 row walk vs complement walk n = 0..{low}: {}",34        verdict(rows[..=low as usize] == complements[..])35    );36    println!(37        "A396934 row walk vs Pascal mod 2 n = 0..{tiny}: {}",38        verdict(rows[..=tiny as usize] == pascal[..])39    );40    for (n, value) in rows.iter().enumerate() {41        println!("A396934 {n} {value}");42    }43    let density = coprime::density(rows[top as usize], top);44    println!("A396934 a({top})/3^{top} = {density:.10} = {density:.7}");45    println!(46        "A396934 16/(3*Pi^2) = {:.10} = {:.7}",47        coprime::limit(),48        coprime::limit()49    );50    println!("A396934 gap = {:.1e}", density - coprime::limit());51}5253fn a398348() {54    let clock = Instant::now();55    let terms: Vec<BigUint> = (1..=DESIGN_N).map(design::by_cycles).collect();56    println!(57        "A398348 cycle walk n = 1..{} in {:.1}s",58        DESIGN_N,59        clock.elapsed().as_secs_f64()60    );61    let clock = Instant::now();62    let affine: Vec<BigUint> = (1..=AFFINE_N).map(design::by_affine).collect();63    println!(64        "A398348 affine powers n = 1..{} in {:.1}s",65        AFFINE_N,66        clock.elapsed().as_secs_f64()67    );68    println!(69        "A398348 cycle walk vs affine powers n = 1..{}: {}",70        AFFINE_N,71        verdict(terms[..AFFINE_N] == affine[..])72    );73    let orbits: Vec<BigUint> = (1..=ORBIT_N)74        .map(|n| BigUint::from(design::by_orbits(n)))75        .collect();76    println!(77        "A398348 cycle walk vs orbit enumeration n = 1..{}: {}",78        ORBIT_N,79        verdict(terms[..ORBIT_N] == orbits[..])80    );81    for (i, value) in terms.iter().enumerate() {82        println!("A398348 {} {}", i + 1, value);83    }84    for n in [7usize, 8] {85        println!(86            "A398348 digits of a({}) = {}",87            n,88            terms[n - 1].to_string().len()89        );90    }91}9293fn main() {94    let top: u32 = std::env::args()95        .nth(1)96        .and_then(|s| s.parse().ok())97        .unwrap_or(20);98    println!(99        "domain A396934 n = 0..{top} on {} threads, complement walk to {COMPLEMENT_N}, Pascal to {PASCAL_N}",100        coprime::THREADS101    );102    println!("domain A398348 n = 1..{DESIGN_N}, affine to {AFFINE_N}, orbits to {ORBIT_N}");103    a396934(top);104    a398348();105}