### COSC-570: Artificial Intelligence

Project 2
Fall 2022

Due: F 10/7 @ 5 PM ET
9 points

For this project, you will implement a resolution theorem prover for propositional logic.

I have divided the project into three phases:

1. For the first phase, write the classes and methods necessary to read, parse, store, and output propositional well-formed formulas (wffs). Formulas must be stored internally as expression trees.

The following grammar specifies the syntax for wffs.

formula ::= '(' proposition ')'
| '(' 'not' formula-or-proposition ')'
| '(' 'or' formula-or-proposition formula-or-proposition ')'
| '(' 'and' formula-or-proposition formula-or-proposition ')'
| '(' 'cond' formula-or-proposition formula-or-proposition ')'

formula-or-proposition ::= formula | proposition

proposition ::= letter letters-and-digits

letters-and-digits ::= letter-or-digit letters-and-digits | \epsilon

letter-or-digit ::= letter | digit

letter ::= 'a'..'z' | 'A'..'Z'

digit ::= '0'..'9'


Examples of wffs written in this syntax are:

• Wishes are horses provided that horses cannot fly.
• $$\neg\mbox{HF} \rightarrow \mbox{W}$$
• (cond (not hf) w)
• If it is not the case that both beggars ride and wishes are nonequine, then horses can fly.
• $$\neg (\mbox{BRD} \; \& \; \neg\mbox{W}) \rightarrow \mbox{HF}$$
• (cond (not (and brd (not w))) hf)

To support development, I put some starter code on cs-class. To get started, log on to cs-class and copy over the following zip file:

cs-class-1% cd
cs-class-1% cp ~maloofm/cosc570/p2.zip ./
cs-class-1% unzip p2.zip

There is also a copy on Canvas. In the p2 directory, you will find a class implementation for Tokenizer and a partial implementation for Formula. The Tokenizer class demonstrates how to configure Scanner to tokenize propositional logic formulae. The directory also contains files for the two proofs we discussed in lecture, Example 1 and the proof that beggars do not ride horses. As you can see in the files, comments begin with a forward slash, formulas begin with a left parenthesis, and both are confined to a single physical line. By convention, the last formula in the file is the conclusion.

In addition to the these proofs, you must find two additional proofs from reputable sources consisting of at least three formulas and three propositions. Include these proof files with your submission to Autolab. Naturally, I will test your program on my own set of proofs.

For this first phase, you must implement the class Formula with the methods

• public Formula()
• public void set( String s ), which constructs an expression tree from the specified string s
• public String toString(), which returns a string representation of the expression tree

When you submit to Autolab, the autograder will call these three methods. Naturally, you will need to implement additional methods.

2. For the second phase, implement the routines to convert wffs to clausal form. Clauses must be stored internally as expression trees or more precisely a linked list of literals. The following grammar specifies the syntax for clauses.
clause ::= '{' literals '}'

literals ::= literal literals-comma-separated | \epsilon

literals-comma-separated ::= ',' literal literals-comma-separated | \epsilon

literal ::= proposition
| '(' 'not' proposition ')'


You must implement

• public void Formula.cnf(), which converts a formula to conjunctive normal form
• public class Clauses, which must extend ArrayList<Clause>
• public Clauses Formula.getClauses(), which converts a formula to clausal form and returns the resulting clauses
• public String Clause.toString(), which returns the string representation of a clause

The transformations must preserve the order of literals. For example, (cond p q) should be written in CNF as ((not p) q), not as (q (not p)); (cond p q) should be written as the clause {(not p), q}, not as {q, (not p)}.

3. Finally, implement the routines required to conduct proofs using linear resolution. For this final phase, you must implement Main.java so it takes a file name as a command-line argument (e.g., java Main lecture.txt), reads the formulas in the file, negates the conclusion, converts the formulas to clauses, and conducts a proof using linear resolution. Main.main should print the formulas, the converted clauses, and a message indicating whether the conclusion follows from the premises.

You must implement

• public Clause()
• public void Clause.set( String ), which sets the Clause to the clause that the specified String represents
• public boolean Clause.empty(), which returns true if the Clause is empty and returns false otherwise
• public Clause Clause.resolve( Clause clause ), which resolves this Clause with the specified Clause clause and returns the resolvent. If the two clauses do not resolve, then the method sets resolvent's internal state so Clause.failure() returns true
• public Clause Clause.resolve( Clause clause ), which resolves this Clause with the specified Clause clause and returns the resolvent. If the two clauses do not resolve, then the method sets resolvent's internal state so Clause.failure() returns true
• public Clauses()
• public Clauses Clauses.resolve( Clause clause ), which resolves all of the clauses in Clauses with the Clause clause and returns them. If there are no resolvents, then resolve returns an empty clause.
• public static boolean LinearResolution.prove( String filename ), which returns true if the conclusion follows from the premises and returns false otherwise

Include with your submission the proof files and a transcript of your program's execution for the four proofs. The transcript should be a plain ASCII file named README. In a file named HONOR, include the following statement:

In accordance with the class policies and Georgetown's Honor Code,
I certify that, with the exceptions of the class resources and those
items noted below, I have neither given nor received any assistance
on this project.

Name
NetID


When you are ready to submit your project for grading, put your source files, Makefile, proof files, transcript, and honor statement in a zip file named submit.zip. Upload the zip file to Autolab using the assignment p2. Make sure you remove all debugging output before submitting.