Compile-time construction of Peano axioms-based natural numbers and addition, multiplication, and exponentiation defined through them within Rust. (Mirrored from Codeberg)

impl geq based on leq

+19
+15
src/lib.rs
··· 26 26 eq::Eq, 27 27 28 28 leq::Leq, 29 + geq::Geq, 29 30 30 31 add::Add, 31 32 mul::Times, ··· 61 62 // Induction 62 63 // A <= B means S(A) <= S(B) 63 64 impl<A: Nat, B: Nat> Leq<Succ<B>> for Succ<A> 65 + where 66 + A: Leq<B> 67 + {} 68 + } 69 + 70 + pub mod geq { 71 + use super::prelude::*; 72 + 73 + pub trait Geq<A: Nat> { 74 + fn geq() -> () {} 75 + } 76 + 77 + // If A <= B then B => A 78 + impl<A: Nat, B: Nat> Geq<A> for B 64 79 where 65 80 A: Leq<B> 66 81 {}
+4
src/main.rs
··· 1 + #![recursion_limit = "132"] 2 + 1 3 use rspeano::prelude::*; 2 4 3 5 fn five_plus_five_is_ten() { ··· 70 72 // _5::even(); 71 73 72 74 <_3 as Leq<_4>>::leq(); 75 + <_4 as Geq<_4>>::geq(); 76 + <_10 as Geq<_5>>::geq(); 73 77 // fails: 74 78 // <_3 as Leq<_2>>::leq(); 75 79 }