FREE Subscription to Dr. Dobb’s Digest: Same Great Content, New Digital Edition
Site Archive (Complete)
Email
Print
Reprint

add to:
Del.icio.us
Digg
Google
Furl
Slashdot
Y! MyWeb
Blink
TABLE OF CONTENTS
May 26, 2007
Rule-Based Programming in C

(Page 1 of 4)
Lynwood Wilson
You don't need an expert system shell for rule-based programming--you can write rules in plain old vanilla C

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.

1 Introduction | 2 Rules in C | 3 Control | 4 Another Way to Control Execution Next Page
TOP 5 ARTICLES
No Top Articles.
DR. DOBB'S CAREER CENTER
Ready to take that job and shove it? open | close
Search jobs on Dr. Dobb's TechCareers
Function:

Keyword(s):

State:  
  • Post Your Resume
  • Employers Area
  • News & Features
  • Blogs & Forums
  • Career Resources

    Browse By:
    Location | Employer | City
  • Most Recent Posts:
    MEDIA CENTER  more
    NetSeminar
    Reduce Costs, Risks and Resource Constraints with Web Application Security OnDemand
    Not surprisingly, Web application security & compliance continues to be a top priority for companies who rely on their Web site to transact business. But in these challenging economic times, managing costs while reducing risk becomes an added challenge. Join us for this 1-hour webcast and let us share with you the importance of Web application security and our Security as a Service. Date: Tuesday May 26, 2009 Time: 9 am PT/12 pm ET
    Modernize your Development by Moving Build and Code Quality Upstream
    Moderated by Jon Erickson, Editor-in-Chief of Dr. Dobb's, this interactive panel discussion brings industry experts Anders Wallgren, CTO of Electric Cloud and Gwyn Fisher, CTO of Klocwork together for a candid discussion of the cost savings, productivity and quality benefits that can be achieved by stabilizing builds and code quality as early in the development cycle as possible.

    The reality of today's development environment - geographically distributed teams, the use of Agile development practices, increasing application complexity, etc. - is straining the viability of the traditional coding, build and release process. To stay ahead of the curve, development teams are modernizing their approach to dealing with these issues, and as a result are achieving new levels of development productivity. Register for the webcast.
    Date: Wednesday, July 15, 2009
    Time: 11 am PT/2 pm ET
                                   
    CONTEST

    Challenge Winners Announced
    The results are in for Dr. Dobb's Challenge Deuce, and the winners are some of the most innovative Silverlight games out there. Play the winning games.
    INFO-LINK

    Resource Links:




    Techweb
    Informationweek Business Technology Network
    InformationweekInformationweek 500Informationweek 500 ConferenceInformationweek AnalyticsInformationweek Events
    Informationweek MagazineGlobal CIOIWK Government ITbMightyByte and SwitchDark Reading
    Digital LibraryIntelligent EnterpriseInternet EvolutionNetwork ComputingPlug Into The CloudDr. DobbsContentinople
    space
    TechWeb Events Network
    InteropVoiceConWeb 2.0 ExpoWeb 2.0 SummitEnterprise 2.0Mobile Business ExpoNoJitter
    Black HatGTECEnergy CampCloud ConnectGov 2.0 ExpoGov 2.0 Summit
    space
    Light Reading Communications Network
    Light ReadingLight Reading AsiaUnstrungCable Digital NewsInternet EvolutionPyramid Research
    Heavy ReadingLight Reading LiveLight Reading InsiderEthrnet ExpoTelco TVTower Technology Summit
    space
    Financial Technology Network
    Advanced TradingBank Systems and TechnologyInsurance and TechnologyWall Street and TechnologyAccelerating WallstreetBST SummitBuyside Trading SummitIT Summit
    space
    Microsoft Technology Network
    MSDNTechNetTotal IT ProTotal Dev ProNET Total Dev Pro CommunitySQL Total Dev Pro Community
    space