Skip to content

Instantly share code, notes, and snippets.

@marnix
Created April 20, 2017 18:03
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 marnix/219cdb40a907fe0a88d556d7c722d034 to your computer and use it in GitHub Desktop.
Save marnix/219cdb40a907fe0a88d556d7c722d034 to your computer and use it in GitHub Desktop.
null created by marnix - https://repl.it/HQio/11
-- first let's get the type signatures out of the way
band :: Integer -> Integer -> Integer
bor :: Integer -> Integer -> Integer
bnot :: Integer -> Integer
-- now a special case, to terminate the recursion for 'band';
-- this follows directly from the general definition below
a `band` b | a == a `div` 2 && b == b `div` 2 = - ((a `mod` 2) * (b `mod` 2))
-- the definitions
a `band` b = ((a `div` 2) `band` (b `div` 2)) * 2 + ((a `mod` 2) * (b `mod` 2))
a `bor` b = a + b - (a `band` b)
-- An alternative definition of 'bor' using DeMorgan is the following:
-- @
-- a `bor` b = bnot (bnot a `band` bnot b)
-- @
bnot a = (-a) - 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment