Skip to content

Commit

Permalink
Optimized boolean logic
Browse files Browse the repository at this point in the history
  • Loading branch information
marvinborner committed Oct 19, 2023
1 parent 0546c89 commit bafbcc6
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions std/Logic.bruijn
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ false ki ⧗ Boolean

# inverts boolean value
# equivalent of [0 ⇒ false]
not! [0 false true] ⧗ Boolean → Boolean
not! c ⧗ Boolean → Boolean

¬‣ not!

:test (¬true) (false)
:test (¬false) (true)

# true if both args are true
and? [[1 0 false]] ⧗ Boolean → Boolean → Boolean
and? [[0 1 0]] ⧗ Boolean → Boolean → Boolean

…⋀?… and?

Expand All @@ -36,7 +36,7 @@ nand? [[1 0 1 false true]] ⧗ Boolean → Boolean → Boolean
:test (nand? false false) (true)

# true if one of the args is true
or? [[1 true 0]] ⧗ Boolean → Boolean → Boolean
or? m ⧗ Boolean → Boolean → Boolean

…⋁?… or?

Expand All @@ -54,15 +54,15 @@ nor? [[1 1 0 false true]] ⧗ Boolean → Boolean → Boolean
:test (nor? false false) (true)

# true if args are not same bools
xor? [[1 ¬0 0]] ⧗ Boolean → Boolean → Boolean
xor? [[0 (1 false 0) 1]] ⧗ Boolean → Boolean → Boolean

:test (xor? true true) (false)
:test (xor? true false) (true)
:test (xor? false true) (true)
:test (xor? false false) (false)

# true if both args are same bools
xnor? [[1 0 ¬0]] ⧗ Boolean → Boolean → Boolean
xnor? [[0 1 (1 0 true)]] ⧗ Boolean → Boolean → Boolean

:test (xnor? true true) (true)
:test (xnor? true false) (false)
Expand All @@ -82,7 +82,7 @@ if [[[2 1 0]]] ⧗ Boolean → a → b → c
:test (false ? true : false) (false)

# mathematical implies definition
implies [[¬1 ⋁? 0]] ⧗ Boolean → Boolean → Boolean
implies [[1 0 true]] ⧗ Boolean → Boolean → Boolean

…⇒?… implies

Expand All @@ -92,7 +92,7 @@ implies [[¬1 ⋁? 0]] ⧗ Boolean → Boolean → Boolean
:test (false ⇒? false) (true)

# mathematical iff (if and only if) definition
iff [[(1 ⇒? 0) ⋀? (0 ⇒? 1)]] ⧗ Boolean → Boolean → Boolean
iff xnor? ⧗ Boolean → Boolean → Boolean

…⇔?… iff

Expand Down

0 comments on commit bafbcc6

Please sign in to comment.