Introduction to Artificial Intelligence

Programming Project 3
Due: Nov. 17, 1997

Contents

The Story

``Spock, analysis?'' Kirk said, staring curiously at the bridge viewscreen.

``A cloud of energy, highly organized, moving at light speed toward us. I am picking up patterns that would indicate intelligence.''

``Not another cloud-like life form,'' Kirk muttered. ``I hate cloud-like life forms.'' He raised his voice to command level, ``Go to yellow alert. Raise sheilds. Arm photon toredoes. Lock phasers. Full sensor scan. Open hailing frequencies...And have Yeoman Rand meet me in my quarters in an hour.''

``Yes sir,'' was the collective response.

``H-F-O, sir,'' said Lt. Uhura.

``H-F-O?'' Kirk queried.

``Hailing frequencies open, sir. I say it so much I figured I'd shorten it.''

``I see, thank you Lt.'' The captain's command chair on the enterprise is much like Batmans belt, it always contains the appropriate control for any situation. In this case, Kirk leaned over to speak. ``Cloud like creature, this is Captain James T. Kirk of the Federation Starship Enterprise, we come in peace.''

The bridge loudspeaker crackled. ``Captain Kirk. We are the Villamar. We are pleased you speak English. We are in need of your assistance.''

``We would welcome the opportunity to show our good intentions by giving you whatever help we can.''

``Well said, captain. Our alpha six one two nine has developed a problem. The alpha six one two nine is critical to our survival now that we, the Villamar, have assumed a cloud-like form.''

``What is an alpha six one two nine?'' Kirk asked.

There was no response from the loudspeaker, but from Spock. ``Captain, we are being scanned.''

Kirk spun to face Spock. ``By them?'' he asked.

Spock nodded.

The Villamar voice spoke again. ``An alpha six one two nine is, in your dialect, a computer, captain. The problem involves a virus which has struck at the core of our reasoning system. We, the Villamar, have used the alpha six one two nine for so many centuries now there are no longer any of us who understand the internals of the system.''

Kirk smiled. ``Take us to your computer. We have someone here who can fix it for you.'' He grinned at Spock who sat stolidly at his station, and then punched the all-powerful button on his chair arm, indicating he had severed communication with the Villamar. ``Sulu, follow the Villamar. Stand down from Yellow Alert, inform Star Fleet of our situation, disarm photons, keep phasers up in case this is a trick, put defense screens to 50%, and tell Yeoman Rand to make it two hours.''

``Aye sir.''

The familiar swish of the turbolift doors drew Kirk's attention to Doctor McCoy's entrance onto the bridge. Behind him were two people Kirk didn't recognize - they were humans but very oddly dressed.

``Jim, these are the two survivors from that derelict ship we found,'' McCoy said. ``They were in suspended animation for almost 300 years. That's longer than Khan was, and they aren't genetically engineered.''

``Welcome to the 23rd century,'' Kirk said. Before he could continue, Sulu spoke up.

``Captain, we are in orbit around a planet which I assume is the Villamar home world.''

``Captain, '' said Uhura. ``The Villamar have transmitted transporter coordinates.''

``Spock, Bones, Sulu, Chekov, and Scotty, you're with me.''

``But captain, that's the entire command crew!''

Kirk paused and looked at Uhura. ``What's your point, Lt?''

``Captain.'' Spock interjected. ``I believe this will take more than two hours. Perhaps you should stay here while I attempt to determine the Villamar's problem.''

Kirk thought for a moment. ``Good idea Spock. OK, beam the whole crew down to the planet.''

Two hours later, Kirk visited sickbay. McCoy was talking to the two survivors of the 20th century. ``Jim. These people have fascinating stories of life in the 20th century! You should hear some of this!''

``Bones, I need to talk to you about something...In private.''

Before McCoy could speak, the sound of a transporter was heard and Spock materialized on a vacant sickbay bed. They rushed over to him.

``Captain.'' Spock's voice was very weak. ``The conditions on the Villamar planet are barely tolerable. I just need to rest a moment before completing the job.'' Spock weakly attempted to prevent McCoy from probing him with the medical scanner.

``You need more than just rest you hard-headed Vulcan...'' Kirk held up his hand. ``Jim, he needs medical attention. He won't be able to go back there for a while.''

``Captain, the problem is simple. If I could just...'' Spock tried to get up but then collapsed on the table. ``Hmmmm. Perhaps you are right doctor.''

``Spock, what's the problem with their computer?''

``It seems a sub-space temporal anomaly caused a momentary rift in the fabric of space near the core of the Villimar computer. The main loss was data, which I was able to restore from backups. However, a small, simple part of the core functionality was also affected and will need to be replaced. As soon as I....'' Spock attempted to rise again, faltered, and fell back onto the sickbay bed.

``Spock, what is the core functionality that needs to be replaced?'' Kirk asked.

Spock was clearly on the verge of unconciousness. ``Ba....kward...chae.....'' his eyes closed. Finally he blurted out, ``ner!'' and his body went limp. Kirk look at McCoy.

``It's serious, Jim. It will take time.'' McCoy said without looking up.

``Baa kward chae ner? Is that Vulcan? I wonder what that means,'' Kirk asked rhetorically.

``Backward chainer,'' said one of the 20th century stowaways.

Kirk, who had almost forgotten their presence, looked quizzicle.

``I think I may be able to help you, captain. When I was at school, our AI teacher, Chris Welty, taught us all about backward chaining. I think I should be able to help the Villamar computer.''

``Chris Welty was your teacher?'' Kirk seemed surprised. ``Chris Welty the father of modern computer science?''

``Errr, I doubt it was the same guy.''

``Oh. Well, get down there anyway.''

The Project

Further inspection of the Villimar systems reveals that their backward chaining systems are fairly simple, and consist of three main elements: the rules, the facts, and the inference engine. Each fact will be a simple list. Each rule, as shown in class, will have the form:
(name IF (fact)* THEN (fact)*)
Note Change: Where facts within rules are simply lists of atoms.

Using these two simple types (facts and rules), you should maintain a fact-base and a rule-base, using the following functions:

initialize &rest facts [Function]

Inititalizes the system by clearing the fact-base and adding to it all the facts in the list facts. An example of a valid call to initialize is:

(initialize '(stretch has hair) '(stretch is a mammal))

show-facts [Function]

This function should display all the currently known facts (the contents of the fact-base) in a readable form.

add-rule rule [Function]

This function should add rule to the rule-base. If a rule with the same name already exists in the rule-base then rule should not be added, and nil should be returned, otherwise t should be returned. An example of a valid call to add-rule is:

(add-rule '(rule-1 IF (animal is a mammal) 
                      (animal eats meat)
                   THEN (animal is carnivore)))

delete-rule rule-name [Function]

This function should delete the rule named rule-name from the rule-base. If no such rule exists, nil should be returned, and t should be returned if the rule is removed. An example of a valid call to delete-rule is:

(delete-rule 'rule-1)
prove fact &key verbose [Function]

This function returns t if it is able to prove fact, and nil if it is unable to.

The optional keyword variable verbose is used to turn on printing of the activities of the backward chainer. When non-nil, every time a rule fires (a rule fires when all of its antecedants have been proved) a message indicating the rule name and the resulting facts being added should be displayed. In addition, a message indicating the number of the current pass through the rulebase should be displayed at the start of each pass.

You are not required to check for cycles in the rulebase.

If the prover must ask whether some fact is true, and the user does not know, it is false.

Deliverables

Note major change as indicated in bold above. You are no longer required to handle variables in rules.

Test data is provided for this project:

Note that your functions must work exactly as described above for the sample data to work.

Once again, submit your code and write-up by email to me. Your grade will be based on the correctness (50%) and readability/documentation (20%) of the code, and the write-up (30%).

The write-up should specifiy how you store facts and rules, how you handled variable binding, how you find named rules, any design decisions you made in particular anything you did for efficiency (or lack of it), etc. In addition, answer these questions in your writeup:

  1. In Test #2, Does the question "(PATIENT HAS STIFFNESS IN FEET)" get asked twice? If so, why, and how might you fix this? If not, why not?
  2. Examine the test file, and look at the code for the third test. Did your prover prove anything on this test? If so, did it ask any questions? Explain.
  3. Consider the state of the factbase at the end, as displayed. Explain any oddities, in particular any contradictions you see. Why are they there, and name at least two ways they could be avoided.