| CSC 8310 LISP Assignment: Simplifying Logical Expressions David Matuszek, Villanova University, Summer 2001 |
Your assignment is to write a LISP program that converts a predicate calculus expression into conjunctive normal form and attempts to simplify it. I will provide some test cases for you to use.
Conjunctive normal form (CNF) is a way of writing expressions in the first-order predicate calculus. It uses only the logical operators and, or, and not. It does not use implies or any of the other logical operators.
An expression in CNF is a conjunction (and) of disjunctions (or). The disjuncts may be individual variables or Boolean constants (true or false), and may be negated (with not). More complex expressions are not allowed. That is, if an expression is in CNF,
For example, the following are in CNF:
(a or b) and (b or not c or d) and
(not a or not e)(a or true) and (b or not false or d)(a or b) and c and not d and (a or
not e)a and b and ca or false or cnot anot a and (b or c)The following are not in CNF:
(a and b) or (c and d) -- Cannot use or
at a higher level than and.(a or b) and not(c or d) -- Can only apply
not to single terms.(a or (b or c)) -- Too many levels of parentheses.Any expression in the predicate calculus can be converted to CNF by applying the following rules.
P implies Q with not P or
Q not(P and Q) with not
P or not Q not(P or Q) with not
P and not Q P or (Q and R) with
(P or Q) and (P or R). (P and Q) or (R and
S) with (P or R) and (P or S) and
(Q or R) and (Q or S).Finally, simplify the resulting expression. Here are some simplifications you can use (you may think of some others):
P and P --> PP or P --> Pnot not P --> Pfalse and anything --> falsetrue or anything --> truefalse or P --> Ptrue and P --> PP or not P --> trueP and not P --> falseUse the names TRUE and FALSE as your constants, and
the following operators:
(AND ...) -- takes any number of arguments(OR ...) -- takes any number of arguments(NOT ___ ) -- takes exactly one argument(IMPLIES ___ ___ ) -- takes exactly two argumentsFor example,
(a or true) and (b or not
false or d)
would be written in LISP as
'(AND (OR A TRUE) (OR B (NOT FALSE) D))
You will be using the above constants and operators as data. LISP defines
the constants T and NIL and the functions AND,
OR, and NOT, and you will probably be using them, but don't
get the LISP functions confused with the data that you are processing.
Here are some additional simplifications that are unlikely to occur in the expressions you are given, but may be helpful in writing the base cases in recursive functions:
(OR P) --> P(or of a single value is just that value) (OR) --> FALSE(or with no arguments is false) (AND P) --> P(and of a single value is just that value) (AND) --> TRUE(and with no arguments is true)
There is a sample LISP program that you can look at for ideas. It is more complicated than your program needs to be, because it uses a "database" of rules. I want you to encode your rules directly in your LISP program ("hardwire" them)--this is less general, and your program will probably be longer, but it will be easier to write. Do not use a database of rules.
control-[
repeatedly to extend the match. control-shift-W
repeatedly to extend the match. control-M.
(I don't know of a way to extend the match.)Due date: July 19.
Turn in a floppy containing: Source code and the results of test runs.
Include a readme.txt file only if you have something you
need to tell the grader.