aboutsummaryrefslogtreecommitdiffhomepage
path: root/std/Number/Wadsworth.bruijn
diff options
context:
space:
mode:
authorMarvin Borner2024-05-02 21:57:58 +0200
committerMarvin Borner2024-05-02 21:57:58 +0200
commita25ed8a75d036de252cfe74b5fa0788215194b41 (patch)
tree65ab549fe20b719535113a4af40bd4c784765cbb /std/Number/Wadsworth.bruijn
parent349e8574c67bf575ed39694c8085eab00473bfaa (diff)
More math
MAATHTHAHHAHA
Diffstat (limited to 'std/Number/Wadsworth.bruijn')
-rw-r--r--std/Number/Wadsworth.bruijn23
1 files changed, 23 insertions, 0 deletions
diff --git a/std/Number/Wadsworth.bruijn b/std/Number/Wadsworth.bruijn
new file mode 100644
index 0000000..00bd3c3
--- /dev/null
+++ b/std/Number/Wadsworth.bruijn
@@ -0,0 +1,23 @@
+# MIT License, Copyright (c) 2023 Marvin Borner
+# from Wadsworth's "some unusual numeral systems" (p224, see refs in README)
+
+:import std/Combinator .
+
+zero [0 [k]] ⧗ Wadsworth
+
+# increment Wadsworth number
+inc [[[2 [2 (1 0) 1]]]] ⧗ Wadsworth → Wadsworth
+
+:test (inc (inc zero)) ([[[2 (1 (0 (k [[1]]))) 1 0]]])
+
+# decrement Wadsworth number
+dec [[1 [k (1 0)] i]] ⧗ Wadsworth → Wadsworth
+
+:test (dec (dec (inc (inc zero)))) (zero)
+
+# returns true if Wadsworth number is zero
+zero? [0 i (k (k [[0]]))] ⧗ Wadsworth → Bool
+
+:test (zero? zero) ([[1]])
+:test (zero? (inc zero)) ([[0]])
+:test (zero? (inc (inc zero))) ([[0]])