In lab 1, you made a simple rule based system. In this lab you're going
to make a more complex system where a series of rules fires based on
a single fact. You will also explore the printout facility, the
agenda command and stepping. Finally, you will make rules that have
complex left hand sides where multiple facts are combined.
- Load up clips again
- You might want to check your lab1 file by loading it in, but
you may want to clear the rule after.
- We want two rules to fire. Make two rules, one that is of the form
if A then B, and another if B then C. Assert A and run.
- That's a chain of reasoning. If you know A, then you derive B,
then C. An example of this would be I know A Fred is an Ape,
I know the rules that Apes are Primate(B), and Primates are Mammals(C),
so I know Fred is a Primate and a Mammal. Remember it is important
how you define your facts.
- Now add another rule if A then D; (Apes have thumbs(D)). This is not
a chain of reasoning, but multiple rules being applied from the same
fact (Fred is an ape).
- Reset and assert the fact A.
- Now two rules should be applicable: A->B and A->D.
- Which one is going to applied? If you run both will be applied,
but which is applied first.
- The agenda command shows you which rule runs first
- You can step (Ctrl-T) on the menu to make the rules go one at a
time
- For me AB was first. I also used the watch menu item and selected
rules and facts. When I used run I got to see the order of application
- So far all that is happening is the facts are being asserted. You
can also print things to the screen.
- add a rule df that has as its right hand side (RHS):
(printout t "hey" crlf)
(crlf is carriage return line feed)
- run it and hey and a new line will be printed
- If you run it again why don't you get hey?
- Add a new rule DF that prints out heyF and a line feed, and
assert the fact F
- If you reset and run, what will happen?
- After the reset, if you assert A and run, what will happen? What
will be the new facts?
- Now add a new rule AD-G that has two clauses on the left hand
side if A and D then G. (You don't have to use any sign)
- If you reset, assert A and run what rules will run? What will
the output be? What order will the rules run in? What will
the facts be?
- Now add a rule AD-H that says A or D then H. Here you have to
use the or operator and pass it D and H on the LHS.
- When I run it H gets added twice (step through or use printout).
Does it for you?
- Now add a rule notAD-I: if not(A or D) then I
- When you reset and run is there anything odd?
- Now reset and make your own system. This should have a
chain of reasoning that is at least 4 rules long. It should
derive some fact that seems contradictory.
- Try a rule that will run once for each of 3 different assertions