aboutsummaryrefslogtreecommitdiffhomepage
path: root/std/Logic/Ternary.bruijn
diff options
context:
space:
mode:
authorMarvin Borner2024-03-10 20:15:20 +0100
committerMarvin Borner2024-03-10 20:15:20 +0100
commit4e680c5523218fb2a5359dae351a692e2d13d2e8 (patch)
treea70ecd3fb73fc5decf3f2606d39464de9d73db11 /std/Logic/Ternary.bruijn
parent6ff75104e28d00535392ebeaf66e2e50c57d0d64 (diff)
Added ternary logic
Diffstat (limited to 'std/Logic/Ternary.bruijn')
-rw-r--r--std/Logic/Ternary.bruijn62
1 files changed, 62 insertions, 0 deletions
diff --git a/std/Logic/Ternary.bruijn b/std/Logic/Ternary.bruijn
new file mode 100644
index 0000000..71fb5ac
--- /dev/null
+++ b/std/Logic/Ternary.bruijn
@@ -0,0 +1,62 @@
+# MIT License, Copyright (c) 2023 Marvin Borner
+
+# true
+true [[[0]]]
+
+# maybe (true-ish)
+maybe [[[1]]]
+
+# false
+false [[[2]]]
+
+# inverts trit value
+¬‣ [0 true maybe false] ⧗ Trit → Trit
+
+:test (¬true) (false)
+:test (¬maybe) (maybe)
+:test (¬false) (true)
+
+# true if both args are true-ish
+and? [[1 (0 1 1 1) (0 0 0 1) (0 0 0 0)]] ⧗ Trit → Trit → Trit
+
+…⋀?… and?
+
+:test (true ⋀? true) (true)
+:test (true ⋀? maybe) (maybe)
+:test (true ⋀? false) (false)
+:test (maybe ⋀? true) (maybe)
+:test (maybe ⋀? maybe) (maybe)
+:test (maybe ⋀? false) (false)
+:test (false ⋀? true) (false)
+:test (false ⋀? maybe) (false)
+:test (false ⋀? false) (false)
+
+# true if one of the args is true-ish
+or? [[1 (0 0 0 0) (0 1 0 0) (0 1 1 1)]] ⧗ Trit → Trit → Trit
+
+…⋁?… or?
+
+:test (true ⋁? true) (true)
+:test (true ⋁? maybe) (true)
+:test (true ⋁? false) (true)
+:test (maybe ⋁? true) (true)
+:test (maybe ⋁? maybe) (maybe)
+:test (maybe ⋁? false) (maybe)
+:test (false ⋁? true) (true)
+:test (false ⋁? maybe) (maybe)
+:test (false ⋁? false) (false)
+
+# mathematical iff (if and only if) definition
+iff [[1 (0 true 0 1) (0 1 1 1) (0 0 0 0)]] ⧗ Trit → Trit → Trit
+
+…⇔?… iff
+
+:test (true ⇔? true) (true)
+:test (true ⇔? maybe) (maybe)
+:test (true ⇔? false) (false)
+:test (maybe ⇔? true) (maybe)
+:test (maybe ⇔? maybe) (maybe)
+:test (maybe ⇔? false) (maybe)
+:test (false ⇔? true) (false)
+:test (false ⇔? maybe) (maybe)
+:test (false ⇔? false) (true)