Last active
September 26, 2020 14:43
-
-
Save fschuindt/892d15d57764862b21b3f1be9bc5dd6f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
TRUE = λx. λy. x | |
FALSE = λx. λy. y | |
NOT = λb. b FALSE TRUE | |
AND = λb1. λb2. b1 b2 FALSE | |
OR = λb1. λb2. b1 TRUE b2 | |
XOR = λb1. λb2. b1 (b2 FALSE TRUE) b2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule LogicalOperators do | |
def l_true(x, _y) do | |
x | |
end | |
def l_false(_x, y) do | |
y | |
end | |
def l_not(b) when b == true do | |
l_true(false, true) | |
end | |
def l_not(b) when b == false do | |
l_false(false, true) | |
end | |
def l_and(b1, b2) when b1 == true do | |
l_true(b2, false) | |
end | |
def l_and(b1, b2) when b1 == false do | |
l_false(b2, false) | |
end | |
def l_or(b1, b2) when b1 == true do | |
l_true(true, b2) | |
end | |
def l_or(b1, b2) when b1 == false do | |
l_false(true, b2) | |
end | |
def l_xor(b1, b2) when b1 == true and b2 == true do | |
l_true(l_true(false, true), b2) | |
end | |
def l_xor(b1, b2) when b1 == true and b2 == false do | |
l_true(l_false(false, true), b2) | |
end | |
def l_xor(b1, b2) when b1 == false and b2 == true do | |
l_false(l_true(false, true), b2) | |
end | |
def l_xor(b1, b2) when b1 == false and b2 == false do | |
l_false(l_false(false, true), b2) | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule LogicalOperatorsTest do | |
use ExUnit.Case, async: true | |
doctest LogicalOperators | |
describe "LogicalOperators.l_true/2" do | |
test "returns the first argument" do | |
assert LogicalOperators.l_true(1, 2) == 1 | |
end | |
end | |
describe "LogicalOperators.l_false/2" do | |
test "returns the second argument" do | |
assert LogicalOperators.l_false(1, 2) == 2 | |
end | |
end | |
describe "LogicalOperators.l_not/1" do | |
test "NOT TRUE is FALSE" do | |
assert LogicalOperators.l_not(true) == false | |
end | |
test "NOT FALSE is TRUE" do | |
assert LogicalOperators.l_not(false) == true | |
end | |
end | |
describe "LogicalOperators.l_and/2" do | |
test "TRUE AND TRUE is TRUE" do | |
assert LogicalOperators.l_and(true, true) == true | |
end | |
test "TRUE AND FALSE is FALSE" do | |
assert LogicalOperators.l_and(true, false) == false | |
end | |
test "FALSE AND TRUE is FALSE" do | |
assert LogicalOperators.l_and(false, true) == false | |
end | |
test "FALSE AND FALSE is FALSE" do | |
assert LogicalOperators.l_and(false, false) == false | |
end | |
end | |
describe "LogicalOperators.l_or/2" do | |
test "TRUE AND TRUE is TRUE" do | |
assert LogicalOperators.l_or(true, true) == true | |
end | |
test "TRUE AND FALSE is TRUE" do | |
assert LogicalOperators.l_or(true, false) == true | |
end | |
test "FALSE AND TRUE is TRUE" do | |
assert LogicalOperators.l_or(false, true) == true | |
end | |
test "FALSE AND FALSE is FALSE" do | |
assert LogicalOperators.l_or(false, false) == false | |
end | |
end | |
describe "LogicalOperators.l_xor/2" do | |
test "TRUE AND TRUE is FALSE" do | |
assert LogicalOperators.l_xor(true, true) == false | |
end | |
test "TRUE AND FALSE is TRUE" do | |
assert LogicalOperators.l_xor(true, false) == true | |
end | |
test "FALSE AND TRUE is TRUE" do | |
assert LogicalOperators.l_xor(false, true) == true | |
end | |
test "FALSE AND FALSE is FALSE" do | |
assert LogicalOperators.l_xor(false, false) == false | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment