aboutsummaryrefslogtreecommitdiffhomepage
path: root/std/Number
diff options
context:
space:
mode:
authorMarvin Borner2024-03-13 15:22:05 +0100
committerMarvin Borner2024-03-13 15:22:05 +0100
commit004f853f260d321753af32318ecdeb2c585af7b0 (patch)
tree9910e17715c0a94325d3e79014cb5b5368af46a2 /std/Number
parent7fc946443adcef9224a3c672b5929a93489c8c93 (diff)
Better string comparison using prefixed spaceship operator
Co-authored-by: JoJoBarthold2 <valentin.j.schmidt@web.de>
Diffstat (limited to 'std/Number')
-rw-r--r--std/Number/Binary.bruijn9
-rw-r--r--std/Number/Bruijn.bruijn2
-rw-r--r--std/Number/Ternary.bruijn15
-rw-r--r--std/Number/Unary.bruijn2
4 files changed, 21 insertions, 7 deletions
diff --git a/std/Number/Binary.bruijn b/std/Number/Binary.bruijn
index 77ce09c..064889d 100644
--- a/std/Number/Binary.bruijn
+++ b/std/Number/Binary.bruijn
@@ -359,7 +359,7 @@ geq? \leq? ⧗ Binary → Binary → Boolean
:test ((+2b) ≥? (+2b)) (true)
:test ((+3b) ≥? (+2b)) (true)
-# returns eq, lt, gt depending on comparison of two numbers
+# returns eq, gt, lt depending on comparison of two numbers
# TODO: remove ternary conversion
compare-case [[[(T.compare-case 2 1 0) ⋔ binary→ternary]]] ⧗ a → b → c → Binary → Binary → d
@@ -367,12 +367,15 @@ compare-case [[[(T.compare-case 2 1 0) ⋔ binary→ternary]]] ⧗ a → b → c
# also: spaceship operator
compare compare-case (+0) (+1) (-1) ⧗ Binary → Binary → Number
+…<=>… compare
+
+<=>‣ &compare
+
:test (compare (+2b) (+2b)) ((+0))
:test (compare (+2b) (+1b)) ((+1))
:test (compare (+1b) (+2b)) ((-1))
-…<=>… compare
-
+# prefix for comparing functions
# returns max number of two
max [[(1 ≤? 0) 0 1]] ⧗ Binary → Binary → Binary
diff --git a/std/Number/Bruijn.bruijn b/std/Number/Bruijn.bruijn
index 744d9a1..131a1a3 100644
--- a/std/Number/Bruijn.bruijn
+++ b/std/Number/Bruijn.bruijn
@@ -4,8 +4,6 @@
# Wadsworth, Christopher. "Some unusual λ-calculus numeral systems."
# very sad indeed
-:import std/Combinator .
-
# increments De Bruijn numeral
inc [[[2 1]]]
diff --git a/std/Number/Ternary.bruijn b/std/Number/Ternary.bruijn
index 8cf891f..5e93c66 100644
--- a/std/Number/Ternary.bruijn
+++ b/std/Number/Ternary.bruijn
@@ -348,7 +348,7 @@ geq? \leq? ⧗ Number → Number → Boolean
:test ((+2) ≥? (+2)) (true)
:test ((+3) ≥? (+2)) (true)
-# returns eq, lt, gt depending on comparison of two numbers
+# returns eq, gt, lt depending on comparison of two numbers
compare-case [[[[[go (1 - 0)]]]]] ⧗ a → b → c → Number → Number → d
go [=?0 5 (>?0 4 3)]
@@ -356,11 +356,22 @@ compare-case [[[[[go (1 - 0)]]]]] ⧗ a → b → c → Number → Number → d
# also: spaceship operator
compare compare-case (+0) (+1) (-1) ⧗ Number → Number → Number
+…<=>… compare
+
+<=>‣ &compare
+
:test (compare (+2) (+2)) ((+0))
:test (compare (+2) (+1)) ((+1))
:test (compare (+1) (+2)) ((-1))
-…<=>… compare
+# returns true if comparison result is equal (EQ)
+c-eq? eq? (+0) ⧗ Number → Number
+
+# returns true if comparison result is less than (LT)
+c-les? eq? (-1) ⧗ Number → Number
+
+# returns true if comparison result is greater than (GT)
+c-gre? eq? (+1) ⧗ Number → Number
# negates a balanced ternary number if <0
abs [<?0 -0 0] ⧗ Number → Number
diff --git a/std/Number/Unary.bruijn b/std/Number/Unary.bruijn
index 81af007..5041614 100644
--- a/std/Number/Unary.bruijn
+++ b/std/Number/Unary.bruijn
@@ -136,6 +136,8 @@ compare compare-case (+0) (+1) (-1) ⧗ Unary → Unary → Number
…<=>… compare
+<=>‣ &compare
+
# muls two unary numbers
mul …∘… ⧗ Unary → Unary → Unary