Skip to content

Commit

Permalink
Added linear logic
Browse files Browse the repository at this point in the history
  • Loading branch information
marvinborner committed Mar 18, 2024
1 parent 41ea5dc commit 8b82e5d
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions std/Logic/Linear.bruijn
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# MIT License, Copyright (c) 2024 Marvin Borner
# binary logic but every abstraction is referred to *exactly once* (linearity)
# originally by "Harry G. Mairson" in "Linear lambda calculus and PTIME-completeness"
# could potentially be used for better visuals/graphs or more efficient reduction

# garbage collection hack
gc [0 [0] [0] [0]] ⧗ LinearBoolean → (a → a)

# true
true [[[0 2 1]]] ⧗ LinearBoolean

# false
false [[[0 1 2]]] ⧗ LinearBoolean

# inverts boolean value
not! [[[2 0 1]]] ⧗ LinearBoolean → LinearBoolean

¬‣ not!

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

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

…⋀?… and?

:test (true ⋀? true) (true)
:test (true ⋀? false) (false)
:test (false ⋀? true) (false)
:test (false ⋀? false) (false)

# true if not both args are true
nand? [[not! (and? 1 0)]] ⧗ LinearBoolean → LinearBoolean → LinearBoolean

:test (nand? true true) (false)
:test (nand? true false) (true)
:test (nand? false true) (true)
:test (nand? false false) (true)

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

…⋁?… or?

:test (true ⋁? true) (true)
:test (true ⋁? false) (true)
:test (false ⋁? true) (true)
:test (false ⋁? false) (false)

# true if both args are false
nor? [[not! (or? 1 0)]] ⧗ LinearBoolean → LinearBoolean → LinearBoolean

:test (nor? true true) (false)
:test (nor? true false) (false)
:test (nor? false true) (false)
:test (nor? false false) (true)

0 comments on commit 8b82e5d

Please sign in to comment.