Created
April 20, 2017 18:03
-
-
Save marnix/219cdb40a907fe0a88d556d7c722d034 to your computer and use it in GitHub Desktop.
null created by marnix - https://repl.it/HQio/11
This file contains 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
-- 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