From a25ed8a75d036de252cfe74b5fa0788215194b41 Mon Sep 17 00:00:00 2001 From: Marvin Borner Date: Thu, 2 May 2024 21:57:58 +0200 Subject: More math MAATHTHAHHAHA --- std/Number/Ternary.bruijn | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'std/Number/Ternary.bruijn') diff --git a/std/Number/Ternary.bruijn b/std/Number/Ternary.bruijn index 27da643..2ad5059 100644 --- a/std/Number/Ternary.bruijn +++ b/std/Number/Ternary.bruijn @@ -328,7 +328,7 @@ abs [ substitute church numbers apply z [[[rec]]] ⧗ Number → (a → a) → a → a rec =?1 case-end case-apply @@ -382,6 +382,12 @@ log₃ log₃* ∘ strip ⧗ Number → Number :test (log₃ (+5)) ((+3)) :test (log₃ (+42)) ((+5)) +# amount of non-zero trits +hamming-weight [0 (+0) inc inc [0]] ⧗ Number → Number + +:test ((hamming-weight (+5)) =? (+3)) (true) +:test ((hamming-weight (+6)) =? (+2)) (true) + # returns the smallest number in a range such that a predicate is true binary-search z [[[[rec]]]] ⧗ (Number → Boolean) → Number → Number → Number rec (0 =? 1) case-end case-search -- cgit v1.2.3