CS 4100 Artificial Intelligence, Assignments  2 and 3
Spring 2012, Prof. Hafner
Assignment 2: Due Thursday, Jan. 26 in class (hard copy)
 
A. Use a truth table to show that the following sentences of propositional logic are equivalent
     (A ^ B) v C   
      ~ ( ( ~A v ~B) ^ ~C)

B. Exercise 7.20 modified: convert the sentences S1-S6 to clause form and identify which of the resulting clauses are Horn clauses
(Note: there will be more than 6 resulting clauses).  There are several different versions of Exercise 7.20 in different printings of your textbook.  Here are the sentences S1-S6 you should use in problems B and C:
S1	A <==> (B v E)
S2	E  ==> D
S3	C ^ F ==> ~B
S4	E ==> B
S5	B ==> F
S6	B ==> C

C. Exercise 7.12 in your textbook. Use resolution to prove that  ~A ^ ~B from the clauses in exercise 7.20
D. Exercise 7.13a.  .

Assignment 3: Due Thursday, Feb 2, 10:00 p.m.,  using the same submission process as for assignment 1 (see below).
Purpose: Continue to learn python and implement your first significant automated reasoning system.

For this assignment, you will create a knowledge-based agent program that reacts to new percepts (atomic propositions), using a knowledge base of prior world knowledge, represented as a set of definite clauses. For each new percept in its input, the program will expand its knowledge base by adding that percept and ALSO adding any new beliefs that logically follow from combining the new percept with the agent's prior knowledge. For example, if the agent's prior knowledge includes:
	apple  -->  fruit
	apple  -->  sweet
	ripe
	fruit  ^  sweet  ^ ripe --> delicious
and the percept is "apple", then apple, fruit, sweet and delicious would be added to the agent's knowledge base.  

We will use "logic programming" notation in the assignment so the KB shown above will actually look like this in your percepts file:
	fruit IF apple
	ripe
	sweet IF apple
	delicious IF fruit sweet ripe
Note: since the input consists of definite clauses, two or more propositions following the "IF" are understood to represent a conjunction.

You may assume the initial KB does not contain implicit knowledge.  However, for EXTRA CREDIT: you may submit a program that does handle an initial KB containing implicit knowledge.  For example: the KB:
	b IF a
	c IF b
	r IF c  d
	a
implicitly contains the knowledge that b and c are true.  If the percept d is found in the input,
the simple forward chaining algorithm defined in class will NOT be able to infer r even though logically 
it follows from d + KB.  The more complicated forward chaining algorithm shown in your textbook
overcomes this limitation.
--------------------------------------------------------------------------------------------------------------
SOURCE AND INPUT FILES:
The name of your source file MUST be ForwardChainPL.py. (note upper case letters in this name)
At the top level, there must be two functions provided:
	loadInitialKB('name of text file containing one definite clause per line, in logic programming notation')
            processPercepts('name of text file containing one atomic proposition per line')

BEHAVIOR:
You must design a data structure for a propositional logic knowledge base.  The loadInitialKB function must populate this structure.  When new knowledge is added to the KB, the data structure expands but the file containing the initial world knowledge is NOT modified.

OUTPUT:
Each time a new percept is processed or a new proposition is added to the KB, your program must produce printed output documenting what is being added, and the justification is for adding it.  For example, given the fruit KB above, and the percept "apple",  typical output might be:
Getting a  percept: apple  ---- added to knowledge base
    New conclusion from forward chaining is:  fruit
	justified by apple and apple --> fruit
    New conclusion from forward chaining is:  sweet
	justified by apple and apple --> sweet
    New conclusion from forward chaining is: delicious
	justified by fruit, sweet, ripe, and fruit ^ sweet ^ ripe --> delicious

If the next percept were: ripe, typical output might be: Getting a new percept: ripe ---- already contained in knowledge base

SUBMISSION:
Send email to saber@ccs.neu.edu with a zipped or tar'ed folder attached called <your name>A2,  containing a file ForwardChainPL.py.
GRADING:
   Most of your grade will be based on following the specifications and correctly implementing the forward chaining reasoning agent.
   Failure to document your program using comments will result in a deduction between 10% and 20% of the maximum grade.
   Readability of both your source code and your printed output will be considered in grading.