[Tutor] How different is math logic from computer logic? [prop-0.7 released]

Danny Yoo dyoo@hkn.eecs.berkeley.edu
Sun Dec 8 00:36:01 2002


On Sat, 7 Dec 2002, James M Lang wrote:

> Unfortunately, it seems to me that the logic my math book is talking
> about has nothing (well, almost) to do with computer logic.  Exactly how
> different are they anyway?
>
> For example: If I work, I cannot study. Either I work or I pass Math. I
> pass Math. Therfore, I studied.

Hi James,


Let's pretend, for a moment, that this was some kind of program request.
The statements above are in English, and English is a highly charged
language.


Just as we'd translate a process into Python statements to keep from
getting confused, we can translate English sentences into logic statements
that we can manipulate without confusion.

Let's say that we have the following variables:

    work
    study
    pass_math

There are a few statements I saw in there, along with a conclusion:

    1.  If I work, I cannot study.
    2.  Either I work or I pass math
    3.  I pass math.
    4.  Therefore, I studied.


Let's pretend that we had a parser that can take these and turn them into
formal logic statements.

###
>>> import prop
>>> s1 = prop.parse('work implies not study')
>>> s2 = prop.parse('work or pass_math')
>>> s3 = prop.parse('pass_math')
>>> s1
implication[work, not[study]]
>>> s2
or[work, pass_math]
>>> s3
pass_math
>>> whole = prop.ImplicationNode(prop.AndNode(s1, s2, s3),
...                              prop.parse('study'))
>>> whole
implication[and[implication[work, not[study]],
                or[work, pass_math],
                pass_math],
            study]
###



> After calling my friend, we agreed that it would be that it was a true
> statement.

There are many cases where it will hold, so that's why you might feel the
whole statement is always true.  But, just as in programs, there can be
bugs in our reasoning where we don't see everything.

What if you passed math, and worked, but didn't study?  What does our
whole statement evaluate to?



I've written a tool that may help you explore logic a little more; it's a
propositional parser in Python:

    http://hkn.eecs.berkeley.edu/~dyoo/python/propositions/prop-0.7.tar.gz

It is not linked up on my web page yet, because I'm still not certain if I
ironed out all the bugs yet; it's been such a long time since I dusted it
off!  *grin* I want to double check it a bit more before announcing it
formally again.