From 964cb1ac830cccf531f565d6d8048de1a0cc6435 Mon Sep 17 00:00:00 2001 From: Marvin Borner Date: Sun, 26 Feb 2023 00:43:43 +0100 Subject: Added more unary functions --- std/Number/Unary.bruijn | 102 +++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 96 insertions(+), 6 deletions(-) (limited to 'std/Number/Unary.bruijn') diff --git a/std/Number/Unary.bruijn b/std/Number/Unary.bruijn index cf72e3b..244eefb 100644 --- a/std/Number/Unary.bruijn +++ b/std/Number/Unary.bruijn @@ -2,11 +2,13 @@ # classic Church style numerals :import std/Logic . +:import std/Combinator . +:import std/Pair . zero [[0]] # returns true if a unary number is zero -zero? [0 [[[0]]] [[1]]] ⧗ Unary → Boolean +zero? [0 [zero] true] ⧗ Unary → Boolean =?‣ zero? @@ -39,19 +41,107 @@ add [[[[3 1 (2 1 0)]]]] ⧗ Unary → Unary → Unary :test ((+0u) + (+2u)) ((+2u)) :test ((+5u) + (+3u)) ((+8u)) +# subs two unary numbers +sub [[0 dec 1]] ⧗ Unary → Unary → Unary + +…-… sub + +:test ((+2u) - (+2u)) ((+0u)) +:test ((+5u) - (+3u)) ((+2u)) + +# returns true if number is less than or equal to other number +leq? [[=?(1 - 0)]] ⧗ Unary → Unary → Boolean + +…≤?… leq? + +:test ((+1u) ≤? (+2u)) (true) +:test ((+2u) ≤? (+2u)) (true) +:test ((+3u) ≤? (+2u)) (false) + +# returns true if number is greater than or equal to other number +geq? \leq? ⧗ Unary → Unary → Boolean + +…≥?… geq? + +:test ((+1u) ≥? (+2u)) (false) +:test ((+2u) ≥? (+2u)) (true) +:test ((+3u) ≥? (+2u)) (true) + +# returns true if number is greater than other number +# larger numbers should be second argument (performance) +gre? [[¬(1 ≤? 0)]] ⧗ Unary → Unary → Boolean + +…>?… gre? + +:test ((+1u) >? (+2u)) (false) +:test ((+2u) >? (+2u)) (false) +:test ((+3u) >? (+2u)) (true) + +# returns true if number is less than other number +# smaller numbers should be second argument (performance) +les? \gre? ⧗ Unary → Unary → Boolean + +…