About Forward Chainer
Forward Chainer is a simple program which can work through small examples to demonstrate a type of algorithm used in artificial intelligence (AI) known as forward chaining. A few examples are provided, but you can also write your own.
What is artificial intelligence (AI)?
The short answer is, probably not what most people think. A slightly longer answer (probably one of many) is that it is the science of building computer algorithms to mimic, in some limited capacity, different ways in which a person might try to solve a problem.
A better question is, "what is intelligence?" I don't have the answer to the question. Is something intelligent because it can beat a world-champion chess player or help make a correct medical diagnosis? Computers can do all of that, but I am not sure if that truly defines intelligence.
What is forward chaining?
Forward chaining basically allows one to give a computer some pre-defined knowledge about the world and some rules with which to use, or "reason", with that knowledge. The computer can then use the rules to come up with new knowledge or conclusions. All of this "knowledge" is stored in a type of database, so as the computer works through its knowledge using the rules, it adds new knowledge to the database and thus can accumulate knowledge over time. In a sense, the computer gets "smarter" over time as it accumulates more knowledge. Here is an example:
Suppose you have some rules about how the world works. In this case you have rules that define family relations. For example, you know that if person A is a parent of person B, then person B must be the child of person A. These are basically IF-THEN rules.
IF X is the parent of Y, THEN Y is the child of X
IF X is the parent of Y, AND Z is the parent of X, THEN Z is the grandparent of Y
IF X is the parent of Y, AND X is married to Z, THEN Z is the parent of Y
IF X is the sister of Y ,AND Y is the parent of Z, THEN X is the aunt of Z
Then you supply some knowledge (also known as "assertions") to the computer about the world. In this case suppose you supply this knowledge:
Steve is married to Donna
Steve is the parent of Tom
Joe is the parent of Steve
Amy is the parent of Donna
Mary is the sister of Donna
You can then provide this information to the forward chaining program, and it works through the rules using what it now knows about the world. The program tries to match appropriate variables on the IF side of the statement to see if it can make any new conclusions based on the THEN side of the statement. In the example above, one thing it will be able to match up is:
IF X is the parent of Y, AND X is married to Z, THEN Z is the parent of Y
Steve parent Tom Steve married Donna Donna parent Tom
You can see that this rule matches those two assertions perfectly, meaning that if you plugged in those names into the variables, it would all fit properly. Thus, the program has now learned that Donna is the parent of Tom.
In essence, from the knowledge and rules you gave it, the program now knows something new.
It adds this new knowledge to the knowledge list and looks for other potential matches. Another rule that now matches (but would not have matched until the newly gained knowledge above was discovered) is:
IF X is the sister of Y, AND Y is the parent of Z, THEN X is the aunt of Z
Mary sister Donna Donna parent Tom Mary aunt Tom
The program has now learned that Mary is Tom's aunt. The program was not told this, but rather discovered it using the rules. It should also be evident that it could only come to this conclusion based on other new knowledge it learned from one of the previous rules matching (which resulted in the knowledge that Donna is the parent of Tom).
Thus, the program cycles through all of the rules and assertions, continuously adding new knowledge until it can learn no more. Once it can't extract any new information the program stops.
How do I use the program?
You can use the program in several ways. The easiest way to see how it works is to use some of the pre-made examples included in the application.
After launching the program you will see three text boxes and some buttons (see Figure):
1. The "assertions" text box is where the knowledge about the world goes.
2. The "rules" text box is where the rules can be pasted or written.
3. The "conclusions" text box is where the program shows information it has added to its database of knowledge, although the way the program was written it will occasionally show some information in the "conclusions" box that is already in the "assertions box." You don't need to paste anything in this box since that is where the program puts new information it finds on its own.
Figure. The Forward Chainer window. After pasting or typing in appropriate rules and assertions, press the "Start" button to watch the program forward chain and come up with new conclusions based on the rules and assertions.
Once you have information in the "assertions" box and in the "rules" box, press the "Start" button". When you press the "Start" button, it becomes inactive and the "Stop" button becomes active. The "Stop" button is important because sometimes the program might be taking too long to work through a set of rules and assertions. There is also a start time and a stop time displayed, including how long it took the program to complete its task. The program should always stop on its own once it has determined that nothing new can be learned from the information it has, but this can sometimes take a long time.
While the program is working, it will show any new conclusions in the "Conclusions" window as they are found, and these will remain there after it has finished forward chaining.
That is how to use the program in a nutshell. If you want to get more adventurous you can try to write your own assertions and rules.
Making your own rules and assertions[>
Assertions must always be written in the form of a triple:
Each of these three items must be separated by a space (or multiple spaces).
You can be creative with how you want to form these triples. For example, if you want to represent that "John bought a Macintosh computer" You could write it as:
Notice in the second example that there are dashes joining some of the words. Words with dashes are considered by the program to be only one word, so the program still sees this as the three-word triple of
It is important, though, to make sure that all of your assertions are written in the same form because the program basically pattern matches when it tries to work through the problem. Thus, if you write "Macintosh-computer" and "computer" in two different assertions, the computer will not know they are the same and treat them as if they are Apples and oranges.
The rules must be written in one of two ways, which is similar to the assertions. They are:
IF subject predicate object THEN subject predicate object
IF subject predicate object AND subject predicate object THEN subject predicate object
Notice that the first rule has only one antecedent (the part before the THEN clause) and the second rule has two antecedents combined with an AND. Also, both rules have only one consequent (the part after the THEN clause). This is the only way to write the rules and the computer won't understand any other format. Once again, space(s) must be between each "word" of the statement for it to work properly.
In the rules, you can denote either variables or non-variables for the subject and object. Variables are denoted by a single character, such as "X", "Y", or "Z", and non-variables are anything longer than a single character. In other words, you can form a statement such as:
IF X gives-chocolate-to Y AND Z is-a veterinarian THEN Z should-discourage X
Notice what this rule is made of:
X gives-chocolate-to Y
Z is-a veterinarian
Z should-discourage X
When the forward chaining program starts working, it will look through any assertions it has and try to pattern match. In the X gives-chocolate-to Y part, any assertion will match that has gives-chocolate-to as the predicate and two different elements for the subject and object (since the X and Y are different, the subject and object in the assertion must be different from each other).
For the part of the rule that states Z is-a veterinarian, any assertion will match that has is-a as its predicate and veterinarian as its object. In a sense it is a bit more limited in what it can pattern match since it only has one variable.
Then, you just need to write assertions such as:
Joe gives-chocolate-to his-dog
Sue is-a veterinarian
And you will end up with the conclusion that Sue should-discourage Joe (Chocolate can be dangerous for dogs).
Note that when variables are different in a single rule it must contain items that match it that are also different. For example, look at this rule:
IF X is-less-than Y and Y is-less-than Z THEN X is-less-than Z
This rule will only match assertions where there are two different elements on either side of the is-less-than statement. So, the assertion 5 is-less-than 5 will not work, and this should make intuitive sense. The statement 5 is-less-than 7 will work since they are different. Do note, however, that the program does not know the mean of is-less-than, so you could just as easily write 7 is-less-than 5 and it would work since the two elements are different.
Note that the variables in a given rule must be self-consistent, but each rule is considered separately. In other words something that matches Y in a rule must be the same Y throughout that rule, but can be completely different from a Y that is in another rule.
Basically, the best way to try to learn how to make the rules is to look at the examples and then try some on your own.
Why is the program so slow (and other limitations) ?
The program was made with the intention of using it for small, demonstration examples and not for real tasks. The program can take so long that it may not be worth waiting to see when it finishes. A major reason for the speed limitation is that it does not use the Rete algorithm, which is a technique for making such programs faster. Additionally, this program does not support backward chaining and also does not support production rules, only deduction rules.
Where can I learn more about forward chaining and artificial intelligence?
There are many websites out there as well as books about the subject. I would suggest consulting those sources. I would not consult the author of this program, as he is not an authoritative source on the subject.
How much does Forward Chainer cost?
It is free.
There is no warranty for this program.
Version Historyversion 1.1 (March 06, 2008):
If you have any questions, comments, concerns, etc. please e-mail me.
You can find this program and my e-mail address at:http://www.supermagnus.com/mac/ForwardChainer/