CSSE 413 Artificial Intelligence Winter 2003 – 2004 Programming Homework 4 – Knowledge Representation (Please put in your turning folder, labeled as HW4, then we’ll play the game) Due Tues, Jan 13, 11:59 PM Worth at least 90 points, total

The two very basic goals of this assignment are as follows:

1. Add Allegro to your resume.

2. Understand how some of the basic knowledge representation works. This is the basis for Expert Systems and many other types which you will encounter (and possibly build) over your CS-related career. If you really get into the problem, there’s a challenge problem at the end of the description of this goal.

Here are the “basic details” for each of the above goals.

Goal 1. There are two parts to the Lisp side of this:

a. The required part (40 points) – Download our new Lisp from tibia and do the first chapter of the built-in tutorial, so you can see roughly what everything is all about in that development environment. More detailed instructions for this are below. Basically, this is a fancy development environment like Java Beans or Visual Basic. It pops up 5 windows when you first open it! The tutorial will give you a little familiarity with how some of the basics work.

b. The optional part (extra points) – You can do as many more of the sections of the tutorial as you want, each of which tells you more about using the “widgets” of the GUI with Lisp. Each “chapter” of Ch 2 – 6 is worth 10 points.

Detailed details for each of these parts is below the description of goal 2.

Goal 2. There is only one thing to do for this, and the design is up to you. And it’s worth 50 points. The only catch is, do it in Lisp, so as to familiarize yourself with actually slinging a little code in the language. Here’s what you need to do:

a. Define a language of “ands and ors and nots” which looks like it would be easy to implement in Lisp. For example, perhaps

(A and B) means A ∧ B in your language, and

(A or B) means A ∨ B in your language.

(not A) means ¬ A. That’s all we’ll worry about defining, nothing fancier like ⇒ or ⇔ .

b. Now, suppose we define a bunch of “atoms” to be true or false. E.g.,

(setq A ) -- i.e., A is true

(setq B nil) -- nil is “false” in Lisp

(setq t)

Then define a function called “is-it-true” which will accept any arbitrary expression with defined variables like A, B, and C, above, and tell whether the whole expression evaluates to t or nil.

For example,

(is-it-true ‘(A and (B or (not C))) ) -- which should come up “nil”. Only binary operands need be handled by and and or. E.g., (something and something), not (something and something and something).

That’s it! – Put your solution in a folder called something like HW4.cl, so I’ll recognize it.

Big hint: There are functions built into Lisp called And and Or and Not. Of course, this doesn’t get you past all the silly parentheses in something like the expression (A and (B or (not C))). You’re still going to have to figure out the recursion.

Challenge problem: (10 Points extra) In expert systems and others using logical knowledge representation, we often have a problem that some things are not known, or not yet known, or perhaps never even defined. As Ch. 7 suggests, we really have to deal with a “3-valued logic” where the third possibility for each expression is “unknown.” Now, it would be nice to extend what you just did so it also would deal with things that were “unknown.” In some cases, we can do logic around those. For example, in (A and (B or (not C))), with the values given, above, the fact is that the answer is still nil even if A is unknown. So, it’s interesting to see how much you can “know” about an expression, even if some of its pieces might, say, be undefined. For extra credit (we’ll agree on how much after several people try this and discover how hard it is) – Extend your answer, above, so it still works if atoms like A, B, or C are either undefined or defined to be “unknown.”

1 a – Getting started with Lisp – The “detailed details”:

(1) Download the from \\tibia\public\Apps\Allegro CL 6.2.

The installation can be done without being having system administrator privileges. There is a ReadMe.txt file that describes the installation process (which is really very straightforward).

There are two license files in the folder, "FacultyLicense 20031219-20040630.txt" and "StudentLicense 20031219-20040226.txt", for faculty and students, respectively. You are to use the student license, which is valid through the Winter quarter (until February 26, 2004). (Note – Because of this, there will be no late work in Lisp at the end of the term!)

(2) After installing this development environment, you will see files you may want to access, under C:\Program Files\acl62. For example, examples of all the tutorial things are under the subdirectory “tutorial” there.

The pure Lisp files have a file extension .cl, and can be viewed using Wordpad, etc. See if you can find some to look at some other people’s code before you try any yourself.

There’s also a built-in emacs editor (which I’ve not used), if you are daring.

(3) To open the whole development environment, view your programs: You should now see “Allegro CL 6.2”, which will point to “Modern ACL Images” (among other things), which will point to “Allegro CL 6.2 (w IDE, Modern)”. Try this one!

A whole bunch of windows pop up. The one across the top is the main control bar. Under “Help” select “-Building Tutorial” and then “Start” on the window which comes up for that. This will get you started on Chapter 1 of the tutorial, which will give you an idea of how all the features of this environment inter-relate, including use of Lisp code to glue the GUI together.

(4) Take a deep breath and try to enter an expression: The Debug Window is also a Lisp Listener (akin to the Scheme Listener). You can directly type-in Lisp expressions you want to try (or copy these in), to see what works and doesn’t in the language.

Try something like:

(setq a ‘(1 2 3 4)) a (car a) (cdr a)

;; Here’s a function duplicating LISP’s list-length function, ;; and is like the problem 1 you did in HW 1:

(defun list-length-2 (l) (cond ((not l) 0) (t (+ 1 (list-length-2 (cdr l))))))

(list-length-2 '(a b c))

A more sophisticated way to do the same thing, which you’ll probably prefer for the homework is as follows:

Type or copy Lisp expressions into the (initially “untitled”) buffer window. This can then be saved as a file (using the File commands on the main bar at the top). To “evaluate” expressions, you go to “Tools” and select “Incremental evaluation” with the cursor resting within the expression you want to evaluate. (Or you can highlight everything to evaluate all of it.) Evaluation results appear in the debug window.

If you go to “Help” and click on “ANSI Common Lisp,” you will see a standard description of the language. It will help you figure out, for example, how some commands work slightly different from Scheme (although a lot is exactly the same, right down to let*). The alphabetical listing of the commands is gotten to by clicking on the “i” symbol at the bottom of the first page. Each command has its own page, with lots of examples of usage.

The most basic difference from Scheme is, Lisp has now “define” command, and instead uses “defun” to define functions, and “setq” to define things like static data. There are plenty of detail differences you’ll discover – like “cond” uses “t” instead of “else”.

There are references on the web comparing Scheme vs. Lisp in more detail. A good intro list is http://www.cs.utexas.edu/users/novak/schemevscl.html.

(5) To see what these differences are for yourself, try doing one of the problems from HW 1 in Lisp (like the example we did on Monday, Jan 5 in class). If you did these in Java, there are Scheme “solutions” out on the assignment page.

Æ This is the required part for part 1. Send me an e-mail saying that you got this far. I’ll take your word for it!

1 b – Learning more about Allegro’s development environment:

Do as many more Tutorial Chapters as you like – They are worth 10 points each. When you get to where you are “done,” bring your laptop into my office and show me how it works. The appropriate amount of extra credit will be awarded immediately!

That’s all of HW 4!