Primitive Logic

Let's think about logical rules AND and OR as if they are just procedures which "implements" the logical rules.

Let's denote Truth as 1 ans Falsehood as 0

So logical AND is in some sense same as multiplication by 0. Anything multiplied by 0 is zero, anything multiplied by 1 is just whatever it is, except zero.

If there is at least one False, then the whole thing is False, only True AND True is True

0 AND 0 is 0
0 AND 1 is 0
1 AND 0 is 0
1 AND 1 is 1

If there is at least one Truth then the whole thing is True, only False OR False is False

0 OR 0 is 0
0 OR 1 is 1
1 OR 0 is 1
1 OR 1 is 1

There are definitions of such rules, which, by magic, happen to be a procedure definitions:

Something AND True is something, whatever it is, BUT, Something AND False is indeed False (something times 1 is something, except for 0, anything times 0 is 0)

(&&)          :: Bool -> Bool -> Bool     -- let's ignore this clutter for a while.
True  && x    =  x
False && _    =  False

Something OR True is True, only False OR False is False

(||)          :: Bool -> Bool -> Bool
True  || _    =  True
False || x    =  x

What is NOT True is False, what is NOT False is True.

not           :: Bool -> Bool
not True      =  False
not False     =  True

Whole books could be written about the beauty of pattern matching, some day, perhaps.

There are recursive procedures defined for Lists in a beautiful foreign language

and           :: [Bool] -> Bool
and []        =  True
and (x:xs)    =  x && and xs

which must be posted on walls.

or            :: [Bool] -> Bool
or []         =  False
or (x:xs)     =  x || or xs

And there is another two pieces of an incredible beauty

and           =  foldr (&&) True

worth to be printed and framed

or            =  foldr (||) False

OK, let's leave foreign lands and return back to the world of Lisps.

Last modified 7 years ago Last modified on Dec 29, 2013, 12:15:36 PM
Note: See TracWiki for help on using the wiki.