Due: Friday, April 30, 1999
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.
checker : form -> boolto check if a propositional formula is a tautology.
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 * formThe 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 FA 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
~~p by p ~(p & q) by (~p) \/ (~q) ~(p \/ q) by (~p) & (~q)Such replacements are sometimes called rewrite rules.
p \/ (q & r) by (p \/ q) & (p \/ r) (q & r) \/ p by (q \/ p) & (r \/ p)
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.
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.
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.smlIf 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.