Despite what you've been told, you don't necessarily need a fancy expert system shelf to enjoy the advantages of rule-based programming, one of the most useful and widely used ideas to come out of AI. In this article, we'll learn how to write rules in plain vanilla C, look at some programming examples, and discuss forward chaining and simple control structures. By the time we're done, you should have a clear idea of how to use rule-based programming techniques in a conventional programming language.
Rules allow us to represent certain kinds of knowledge that are difficult to employ a conventional procedural program. Rule-based programs also separate the knowledge from the rest of the program in such a way that a change in the knowledge base is not propagated throughout the program like a change in a procedural program can be.
This flexibility allows you to defer some kinds of decisions or reconsider them halfway through the program without completely rebuilding it. Rules are ideal for expert systems, where the process the program is to perform is very imperfectly understood, at least at the outset.
Rule-based programs can be written several ways. Some languages, such as OPS-5, are intended for this purpose. There are also expert systems shells of many kinds, prices, and capabilities. Either approach can offer a great deal of power in rule-based programming and should be considered for an expert system or any program that will have a great many rules. However, in some cases these approaches sacrifice the capability of the procedural programming on such prosaic areas as I/O and screen control.
In any case, you are required to learn new ways to do old things. For a program with just a few rules or for experimenting, you might consider writing a rule-based program in C.
In a rule-based program, the function is embodied in a set of rules written in something resembling English. A rule has a condition or set of conditions called the IF part and a result or set of results called the THEN part. The THEN part of the rule usually consists of actions to be performed. If the IF part of the rule is satisfied the rule can fire. If the rule fires, actions in the THEN part are performed
IF there is rain AND you must walk THEN umbrella is necessary
In this case the THEN portion doesn't look like an action. It could also be written umbrella = necessary , and in either case could have the effect of assigning the string necessary to the variable umbrella or giving the Boolean umbrella a value of TRUE or whatever your program requires. The IF part could also be rewritten as IF rain is true, which would look more like a normal program.