CSE5040: ML Project

Due: Friday, April 30, 1999

Running ML

To invoke the SML of NJ interactive system on the SPARC machines in the Harris Lab, type

/software/sml/bin/sml

To end the session type "control-D". SML prints # when the depth of the expression is more than 5. A # does not signal an error. To see the whole expression type:

Compiler.Control.Print.printDepth := 100;
Some more info about interation with SML can be found at SML Short Reference.

Tautology Checker

In this project you are to write an ML function
checker : form -> bool
to check if a propositional formula is a tautology.

Propositional Logic

Propositional logic deals with propositions constructed from atoms by the connectives "and", "or" and "not". A propositional formula may be

~p       "not p"
p &  q   "p and q"
p \/ q   "p or q"
Propositional formulas resemble boolean expressions and are represented in this project by the datatype form:
datatype form =
  Atom of string | Neg of form | Conj of form * form | Disj of form * form
The implication p->q is equivalent to (~p)\/q.

A propositional formula is either true or false depending on the truth values of the constituent atomic propositions. So if P is true and Q is false, then

P     Q     ~ (P \/ Q)
=====================
T     F          F
A tautology is a propositional formula that is true regardless of the values of the atomic propositions.
P     Q     ~ (P \/ Q) \/ P \/ Q
================================
T     T                T
T     F                T
F     T                T
F     F                T

Negation Normal Form

Any proposition can be converted in negation normal form (NNF), where ~ is only applied to atoms, by pushing negation into conjunctions and disjunctions. Repeatedly replace
~~p       by p
~(p & q)  by (~p) \/ (~q)
~(p \/ q) by (~p) &  (~q)
Such replacements are sometimes called rewrite rules.

Conjunction Normal Form

A literal is an atom or its negation. A proposition is in conjunctive normal form (CNF) if it has the form p1 & ... & pn where each pi is a disjunction of literals. To obtain CNF, start with a propositional formula in negation normal form. Using the the distributive law, push in disjunctions until they apply only to literals. In otherwords, repeadly replace
p \/ (q & r)   by  (p \/ q) & (p \/ r)
(q & r) \/ p   by  (q \/ p) & (r \/ p)

Tautology checking

To check whether a propositional formula p is a tuatology, reduce it to CNF, say p1 & ... & pn. If p is a tautology, then so is each pi. Supppose pi is q1 ... qm where each qi is a literal. If the literals include an atom and its negation, then pi is a tautology.

For example, the propositional formula A \/ B is not a tautology because:

A \/ B
A \/ B    (negation normal form)
A \/ B    (conjunctive normal form, one conjunct)
Since some conjunct, namely A\/B, does not contain any atom and its negation, the proposition A \/ B is not a tautology. So applying the ML program to this propositonal formula
checker (Disj (Atom "A", Atom "B"))
yields false.

For example, the propositional formula ~(A \/ B) is not a tautology because:

~ (A \/ B)
~A & ~B    (negation normal form)
~A & ~B    (conjunctive normal form, two conjuncts)
Since some conjunct (in fact both), does not contain any atom and its negation, the proposition ~(A \/ B) is not a tautology. So applying the ML program to this propositional formula
checker (Neg (Disj (Atom "A", Atom "B")))
yields false.

For example, the proposition A \/ ~((A & ~B) \/ (~C & C)) is a tautology because:

A \/ ~((A & ~B) \/ (~C & C))
A \/ ((~A \/ B) & (C \/ ~C))    (negation normal form)
A \/ ~A \/ B  &  A \/ C \/ ~C   (conjunctive normal form, two conjuncts)
Since all conjuncts contain an atom and its negation, the proposition is a tautology. So applying the ML program to this propositonal formula
checker (
   Disj (
     Atom "A",
     Neg (
       Disj (
          Conj (Atom "A", Neg (Atom "B")),
          Conj (Neg (Atom "C"), Atom "C"))
       )
   )
)
yields true.

References

Ralph P. Gimaldi, Discrete and Combinatorial Mathematics: An Applied Introduction, 3rd edition, Addison Wesley, Reading, Massachusetts, 1992.

Chapter 2. Fundamentals of Logic. Section 2.1. Basic Connective and Truth Tables, pages 51-60. Section 2.2. Logical Implication: The Laws of Logic, pages 60-76.

Information on the net

Turning it in

Write the program as clearly as possible, including reasonable comments. You may work alone or with one or two other students in the class, as long as you did not work with any of them in the previous projects. Be sure to include your name and your partner's names in the comments when you turn in the project, so we will know who should get credit for the work. Please mail me your file (just one copy per group) by midnight of the due date. Use the following command on

~ryan/bin/mfiles ryan@cs "sml" checker.sml
If you get no message at all, then the submission (probably) worked. If you get some message, check carefully the command you are using and resubmit. If you have trouble, please contact me. You can submit the project as often as you wish, as long as it is submitted from the same computer account, only the last one will be graded.

You can test your SML program checker.sml by running the following command on maelstrom or zach:

/software/sml/bin/sml checker.sml < ~ryan/public_html/cse5040/checker-test.sml

A list of submissions for this project is maintained by hand (and so may not be current). Only the last submission from a login counts. All previous submissions are ignored.


Ryan Stansifer <ryan@cs.fit.edu>
Last modified: Tue Apr 20 19:48:29 EDT 1999