use transfinite::Ordinal;
fn print_step(step: u32, base: u32, value: u32, ordinal: &Ordinal) {
println!(" step {step:2}: base {base}, integer = {value:5}, ordinal = {ordinal}");
}
fn main() {
println!("Goodstein's theorem: the integer sequence terminates because the");
println!("corresponding ordinal sequence strictly decreases, and ordinals");
println!("below ε₀ are well-ordered.\n");
println!("Sequence starting from n = 3:");
println!(" (hereditary base-2: 3 = 2 + 1, so the starting ordinal is ω + 1)\n");
let omega = Ordinal::omega();
let steps: Vec<(u32, u32, u32, Ordinal)> = vec![
(0, 2, 3, omega.clone() + Ordinal::one()), (1, 3, 3, omega), (2, 4, 3, Ordinal::new_finite(3)), (3, 5, 2, Ordinal::new_finite(2)), (4, 6, 1, Ordinal::new_finite(1)), (5, 7, 0, Ordinal::new_finite(0)), ];
for (step, base, value, ordinal) in &steps {
print_step(*step, *base, *value, ordinal);
}
println!("\nVerifying the ordinal sequence is strictly decreasing:");
for window in steps.windows(2) {
let (s_a, _, _, ord_a) = &window[0];
let (s_b, _, _, ord_b) = &window[1];
let strictly_less = ord_b < ord_a;
let marker = if strictly_less { "✓" } else { "✗" };
println!(
" {marker} step {s_a} ({ord_a}) > step {s_b} ({ord_b}) - {}",
if strictly_less { "ok" } else { "VIOLATION" }
);
}
println!("\nThe ordinal sequence ω + 1 > ω > 3 > 2 > 1 > 0 has length 6.");
println!("The integer sequence 3, 3, 3, 2, 1, 0 also has length 6 - they");
println!("happen to coincide here because n is small. For n = 4 the integer");
println!("sequence reaches 0 only after a number of steps that does not fit");
println!("in any reasonable computer (Goodstein numbers grow VERY fast),");
println!("yet the ordinal sequence stays bounded by ω^ω throughout.\n");
println!("This is the headline use case for ordinals up to ε₀: certifying");
println!("termination of processes that vastly exceed primitive recursive");
println!("bounds.");
}