Skip to content

Instantly share code, notes, and snippets.

@mlhaufe
Created January 8, 2019 06:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mlhaufe/03730b09c1d50255f123140d2cde6f7e to your computer and use it in GitHub Desktop.
Save mlhaufe/03730b09c1d50255f123140d2cde6f7e to your computer and use it in GitHub Desktop.
Booleans with arithmetic
// x, y :: {0,1}
var and = (x,y) => x * y,
not = (x) => 1 - x,
or = (x,y) => 1 - (1 - x) * (1 - y)
and(0,0) // 0
and(0,1) // 0
and(1,0) // 0
and(1,1) // 1
not(0) // 1
not(1) // 0
or(0,0) // 0
or(0,1) // 1
or(1,0) // 1
or(1,1) // 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment