home *** CD-ROM | disk | FTP | other *** search
/ Power Programming / powerprogramming1994.iso / progtool / educaton / inf_src.arc / INFER.DOC < prev    next >
Text File  |  1986-03-14  |  45KB  |  1,041 lines

  1. SHAR_EOF
  2. sed 's/^X//' << 'SHAR_EOF' > inference.doc
  3.  
  4.         INFERENCE          -- SOFTMAN ENTERPRIZES --        Dec. 30, 1985
  5.  
  6.  
  7.         INTRODUCTION: 
  8.  
  9.         The  software contained in this distribution is copyright (C)  by 
  10.         George   Hageman   1985   and  is  released   into   the   public               
  11.         domain with the following restrictions:                         
  12.  
  13.              (1)   This  software  is intended  for  non-commertial usage.                                              
  14.              (2)    I   am   held  save  from  damages   resulting   from               
  15.              its use, and
  16.              (3)   The following concepts and legal jargon are agreed  to 
  17.              by the user of this software.
  18.  
  19.              User-supported software concept:
  20.  
  21.                   IF          you find use for this software
  22.                   ANDIF       it saves you some development time
  23.                   THEN            send me $10.00
  24.                   ANDTHENHYP      you will feel good!
  25.  
  26.         This source code is provided on an "as is" basis without warranty 
  27.         of any kind,  expressed or implied,  including but not limited to 
  28.         the  implied  warranties  of merchantability and  fitness  for  a 
  29.         particular   purpose.    The  entire  risk  as  to  quality   and 
  30.         performance  of this software is with you.   Should the  software 
  31.         prove  defective,  you  assume the entire cost of  all  necessary 
  32.         repair, servicing, or correction.  In no event will the author be 
  33.         liable to you for any damages,  including any lost profits,  lost 
  34.         savings, or other incidental or consequential damages arising out 
  35.         of  the   use  of inability to use this software.   In  short  my 
  36.         friends,  I  have done  a reasonable amount of work in  debugging 
  37.         this  software and I think it is pretty good but,  as  you  know, 
  38.         there  is always some chance that a bug is still lurking  around. 
  39.         If you should happen to be lucky enough to  find one,  please let 
  40.         me know so I    can make an attempt to fix it.          
  41.  
  42.              The  following  is  a short description of how  to  use  the 
  43.         inference  engine  and rule-compiler contained in  this  software 
  44.         release.    The source and object files for the rule compiler and 
  45.         the inference engine are contained in the rcomp.lbr and infer.lbr 
  46.         respectively.   There are common files contained in each library.  
  47.         These  common  files  are header files which are used  to  define 
  48.         common terms between the different sources.    The most important 
  49.         header file is the file named "expert.h" which not only  contains 
  50.         common  definitions  used  between  the  rule  compiler  and  the 
  51.         inference  engine,  but has a short description of their usage as 
  52.         well.    This inference engine, and its associated rule compiler, 
  53.         represents  a  significant  time investment for  me,  so  if  you 
  54.         believe in the  shareware concept please remember my address.
  55.  
  56.                             George W. Hageman
  57.                             P.O. Box 11234
  58.                             Boulder, Colorado  80301
  59.  
  60.  
  61.  
  62.  
  63.  
  64.         George W. Hageman            --1--
  65.  
  66.  
  67.  
  68.  
  69.  
  70.         INFERENCE          -- SOFTMAN ENTERPRIZES --        Dec. 30, 1985
  71.  
  72.  
  73.              This  software compiles using the Microsoft C  Compiler  Rev 
  74.         3.0  using the make function which comes with the Microsoft Macro 
  75.         Assembler Rev.  4.0.  I have nothing but good things to say about 
  76.         these  two products and suggest that you consider their  purchase 
  77.         if  you are into serious software development for the  PC.   This 
  78.         software  also compiles and runs under UNIX system  V.   Use  the 
  79.         UNIXSV  flag  in the makefile or use a -DUNIXSV when you  compile 
  80.         it.
  81.  
  82.  
  83.  
  84.  
  85.  
  86.         George W. Hageman            --2--
  87.  
  88.  
  89.  
  90.  
  91.  
  92.         INFERENCE          -- SOFTMAN ENTERPRIZES --        Dec. 30, 1985
  93.  
  94.  
  95.         INFERENCE ENGINES:
  96.  
  97.              An  inference engine is merely a program which  attempts  to 
  98.         prove consequents given a certain set of antecedents and a set of 
  99.         rules  which define the TRUTH or FALSEness of each consequent  in 
  100.         terms  of the antecedents.     The consequents,  antecedents  and 
  101.         rules  for  this  inference engine are contained in a  text  file 
  102.         which is compiled by the rule-compiler into a form the  inference 
  103.         engine  can understand.   Often these two functions are contained 
  104.         in the same executeable,  but I have decided to split them up  to 
  105.         make the inference engine as small as possible.
  106.  
  107.              Rules  are collections of ANTECEDENTS and CONSEQUENTS formed 
  108.         into  TRUTH statements.   Each rule is an attempt state that  "If 
  109.         all of the antecedents for this particular RULE are  TRUE,   then 
  110.         all  of the consequents connected to this rule are TRUE.   If one 
  111.         or  more  of the antecedents for a RULE are  FALSE,  then  it  is 
  112.         assumed that this rule cannot prove the TRUTH of the consequents, 
  113.         but  this does not necessarily prove the consequents FALSE  since 
  114.         some  other rule may prove them TRUE."  Rules must have at  least 
  115.         one  ANTECEDENT  and  at least one CONSEQUENT  to  be  considered 
  116.         valid. 
  117.  
  118.              Each   ANTECEDENT  and  CONSEQUENT  is  a  simple  statement 
  119.         consisting  of  a  leading  KEYWORD,   and  a  FOLLOWING  STRING.  
  120.         KEYWORDS tell the inference engine what the FOLLOWING STRING will 
  121.         mean or what is to be done with it.  The FOLLOWING STRINGs may be 
  122.         either  in upper or lower case and are either statements such  as 
  123.         "THE  ANIMAL IS A BAT",  or,  a pathname to an executeable  which 
  124.         will  be loaded and executed depending on what is defined by  the 
  125.         KEYWORD. Strings, except for the number of leading blanks, can be 
  126.         considered equal only if they are identical.  The reason for this 
  127.         rule  will  become  apparent later.   An example  of  a  pathname 
  128.         FOLLOWING STRING is "/b1/hageman/expert/storm/gt_3200  data.fil".  
  129.         Note  that  the strings denoting pathnames should be  exactly  as 
  130.         they  would  be if the pathname were to be given at  a  terminal, 
  131.         also,  you  may  include  parameters with  any  pathname.   These 
  132.         parameters  are no different than the parameters that  you  would 
  133.         use  if  you  were initiating the executeable from  the  terminal 
  134.         rather than via the inference engine.    Under MS_DOS these  path 
  135.         names  can  either  be  upper or lower case,  and  for  the  UNIX 
  136.         operating system, they must correspond to the exact path name.
  137.  
  138.  
  139.  
  140.  
  141.  
  142.  
  143.  
  144.         George W. Hageman            --3--
  145.  
  146.  
  147.  
  148.  
  149.  
  150.         INFERENCE          -- SOFTMAN ENTERPRIZES --        Dec. 30, 1985
  151.  
  152.  
  153.         QUICK AND DIRTY:
  154.  
  155.              Impatient?   Well  here  are some quick ways to get  started 
  156.         with the inference engine,  leave all that reading till later!
  157.  
  158.         ONE:
  159.  
  160.              Use  your  text  editor (WS in the  Non-document  mode  only 
  161.         Please) to create a quick rule file,  or use the animals  example 
  162.         contained in this release.   Skip to the next page if you want to 
  163.         find out what the KEYWORDS are and how to use them.
  164.  
  165.         TWO:
  166.  
  167.              Compile the rules with the rule-compiler by typing..
  168.  
  169.              rulecomp inputfile outputfile 
  170.  
  171.              where  the inputfile is the filename of the file  containing 
  172.         your  rules,  and the outputfile is the file inwhich you want the 
  173.         compiled rules to be written to.  Caution, the rule compiler does 
  174.         not  check  for the equivalence of the inputfile  and  outputfile 
  175.         filenames,   if they are identical you will probably have to type 
  176.         in your rules again.
  177.  
  178.         THREE:
  179.  
  180.              Run the inference engine by typing ..
  181.  
  182.              inference outputfile
  183.  
  184.              answer the questions and go back to step ONE if you found an 
  185.         error with your rules or you want to expand them.
  186.  
  187.  
  188.  
  189.  
  190.         George W. Hageman            --4--
  191.  
  192.  
  193.  
  194.  
  195.  
  196.         INFERENCE          -- SOFTMAN ENTERPRIZES --        Dec. 30, 1985
  197.  
  198.  
  199.         KEYWORDS:
  200.  
  201.              The  following are the KEYWORDS which the rule compiler  can 
  202.         recognize,  and  a short description of what each means  and  how 
  203.         each  would be used.    Note that the members of each group  have 
  204.         identical meaning and can therefore be substituted for each other 
  205.         without  effecting the sense of the rule.   Latter examples  will 
  206.         attempt to demonstrate this fact.
  207.  
  208.  
  209.  
  210.         IF, AND, ANDIF:
  211.  
  212.              These KEYWORDS define the FOLLOWING STRING as an ANTECEDENT, 
  213.              and  the TRUTH sense of the string is TRUE if the string  is 
  214.              TRUE.    These  KEYWORDS can be used interchangeable without 
  215.              effecting the sense of the rule being expressed.
  216.  
  217.                   Example:
  218.  
  219.                        IF the animal is a mammal
  220.                        ANDIF the animal has hooves
  221.                        AND the animal has horns         
  222.  
  223.                   This is equivalent to:
  224.  
  225.                        AND the animal is a mammal
  226.                        IF the animal has hooves
  227.                        ANDIF the animal has horns
  228.  
  229.              Note that since the antecedent part of a rule is essentially 
  230.              a  large AND statement,  the order in which  the  individual 
  231.              statements  are  arranged  is a matter  of  esthetics  only.  
  232.              However,  it may be more readable to the human, if a certain 
  233.              order is maintained.
  234.  
  235.         IFNOT, ANDNOT
  236.  
  237.              These  KEYWORDS  are  essentially  identical  to  the  above 
  238.              KEYWORDS except that the sense of the statement is reversed.   
  239.              That is to say that if the following string is TRUE then the 
  240.              truth   value   of   the  statement  is  FALSE.              
  241.  
  242.                   Example:
  243.  
  244.                        IFNOT the animal is a mammal
  245.                        ANDNOT the animal has smooth skin
  246.                        ANDNOT the animal breaths air
  247.                        THEN animal is a fish 
  248.  
  249.  
  250.  
  251.  
  252.  
  253.  
  254.  
  255.  
  256.         George W. Hageman            --5--
  257.  
  258.  
  259.  
  260.  
  261.  
  262.         INFERENCE          -- SOFTMAN ENTERPRIZES --        Dec. 30, 1985
  263.  
  264.  
  265.         IFRUN, ANDRUN, ANDIFRUN
  266.  
  267.              These KEYWORDS tell the inference engine that the  FOLLOWING 
  268.              STRING is to be used as a pathname to an executeable.   This 
  269.              executeable  is to be loaded and run and the resultant TRUTH 
  270.              value returned when the routine exits is the TRUTH value  of 
  271.              the ANTECEDENT statement.   Like the AND, IF, ANDIF KEYWORDS 
  272.              above,  each  of  these  may be substituted for any  of  the 
  273.              others  without effecting the sense of the  rule  statement.   
  274.              Note  that  the  full path name of the  executeable  is  not 
  275.              needed  if  the  executeable  file resides  in  the  working 
  276.              directory from which the inference engine was initiated.
  277.  
  278.                   Example:
  279.  
  280.                        IFRUN /b1/hageman/expert/gt3000
  281.                        ANDRUN /b1/hageman/expert/sedir direction.dat
  282.                        ANDIFRUN falling barompress
  283.                        THEN sorry about the picnic
  284.                
  285.         IFNOTRUN, ANDNOTRUN     
  286.  
  287.              These are used as the KEYWORDS above are used -- to initiate 
  288.              the execution of an ANTECEDENT executeable file, except that 
  289.              the truth value of the result is reversed as with the IFNOT, 
  290.              ANDNOT and the ANDIFNOT KEYWORDS.
  291.  
  292.                   Example:
  293.                        
  294.                        IFNOTRUN gt3000
  295.                        ANDNOTRUN sedir direction.dat
  296.                        ANDNOTRUN falling barompress
  297.                        THEN how about a picnic?
  298.          
  299.         THEN, ANDTHEN, THENHYP, ANDTHENHYP    
  300.  
  301.              These KEYWORDS tell the inference engine that the  FOLLOWING 
  302.              STRING  is  a  CONSEQUENT.     If  all  of  the  immediately 
  303.              proceeding ANTECEDENTS have a truth value of TRUE,  then the 
  304.              inference  engine INFERS that the CONSEQUENT is  TRUE.   The 
  305.              THEN KEYWORDS ending in "HYP" tell the inference engine that 
  306.              the  FOLLOWING STRING is an ending CONCLUSION and no further 
  307.              processing  or inferencing is required.   The  routine  will 
  308.              exit  when one of the THENHYP or ANDTHENHYP CONSEQUENTS  are 
  309.              proven   TRUE.     Therefore,   one  should  use  the  "HYP" 
  310.              CONSEQUENT KEYWORDS with care. 
  311.  
  312.                   Examples:
  313.  
  314.                        IF you have an aunt
  315.                        ANDIF your aunt has a child
  316.                        THEN you have a cousin
  317.  
  318.                        IF you have a cousin
  319.                        THENHYP you have at least two relatives
  320.  
  321.  
  322.         George W. Hageman            --6--
  323.  
  324.  
  325.  
  326.  
  327.  
  328.         INFERENCE          -- SOFTMAN ENTERPRIZES --        Dec. 30, 1985
  329.  
  330.  
  331.         THENRUN, ANDTHENRUN, THENRUNHYP, ANDTHENRUNHYP 
  332.  
  333.              These are similar to the THEN,  ANDTHEN etc. KEYWORDS except 
  334.              they  perform  the  loading and execution of  the  FOLLOWING 
  335.              STRING  path  name  if they  are  proven  TRUE.   The  value 
  336.              returned  by  the executeable file loaded becomes the  value 
  337.              remembered  for  the  CONSEQUENT.   The truth  value  for  a 
  338.              CONSEQUENT proceeded with the KEYWORDS of THEN or ANDTHEN is 
  339.              only remembered if it is proven TRUE.  However, with the RUN 
  340.              type of CONSEQUENT since it is initiated only when found  to 
  341.              be proven, the predicate value it returns is remembered even 
  342.              if  it is FALSE.  This prevents the rerunning of  CONSEQUENT 
  343.              routines.  
  344.  
  345.              In this manner one can use rules to determine weather or not 
  346.              a particular routine should be executed,  then use the truth 
  347.              value  returned  by the routine upon its exit in other  rule 
  348.              statements.   An obvious use for such a function would be in 
  349.              the field of diagnostics.   Through a set of rules it  could 
  350.              be  determined  that a particular diagnostic should be  run,  
  351.              once  the diagnostic has been run,  further rules could  use 
  352.              the  fact  of whether the diagnostic test passed  (TRUE)  or 
  353.              failed (FALSE) to make decisions about the further isolation 
  354.              of the hardware failure.
  355.  
  356.                   Example:
  357.                        
  358.                        !
  359.                        IFNOTRUN isdev1
  360.                        IFNOTRUN isdev2
  361.                        IFNOTRUN isdev3
  362.                        THENHYP there are no devices to run diagnostics on
  363.                        !     
  364.                        ! see note below for the following rule
  365.                        !
  366.                        IF isdev1
  367.                        ANDIFRUN dev1diag
  368.                        THENHYP device one is faulty
  369.                        !
  370.                        IFRUN isdev2
  371.                        ANDIFRUN dev2diag
  372.                        THENHYP device two is faulty
  373.                        !
  374.                        IFRUN isdev3
  375.                        ANDIFRUN dev3diag
  376.                        THENHYP device three is faulty
  377.                        !
  378.                        IFNOTRUN dev1diag
  379.                        IFNOTRUN dev2diag
  380.                        IFNOTRUN dev3diag
  381.                        IFRUN isdev1
  382.                        ANDRUN isdev2
  383.                        THENRUN diag12
  384.                        !
  385.                        !
  386.  
  387.  
  388.         George W. Hageman            --7--
  389.  
  390.  
  391.  
  392.  
  393.  
  394.         INFERENCE          -- SOFTMAN ENTERPRIZES --        Dec. 30, 1985
  395.  
  396.  
  397.                        !
  398.                        IFRUN diag12
  399.                        THENHYP device two is suspect remove and re-run test
  400.                        !
  401.                        IFNOTRUN diag12
  402.                        THENHYP device one is suspect, remove and re-run test 
  403.                        !
  404.  
  405.              Note:
  406.  
  407.              You   have  probably  noticed  that  the  FOLLOWING  STRINGS 
  408.              associated  with  the  RUN KEYWORDS and  the  IF,  AND  etc. 
  409.              KEYWORDS are interchangeable.   This is due to fact that the 
  410.              TRUTH  of  a  string is kept as a pointer  into  the  string 
  411.              buffer,  and therefore have no information concerning  their 
  412.              nature and only have meaning when used in conjunction with a 
  413.              KEYWORD.  If you are sure that the string "isdev1" will have 
  414.              its   truth  determined  earlier  by  running  the   routine 
  415.              "isdev1",   Then you may use it as a regular string in later 
  416.              rules,  however,  if its truth has not been determined  then 
  417.              the  inference  engine  will ask you for the  truth  of  the 
  418.              statement  "isdev1" rather than running the routine.   To be 
  419.              sure  use  the "RUN" form for the strings  which  relate  to 
  420.              executeables,   they will only be run once as it is,  so you 
  421.              don't really have to keep them straight.
  422.  
  423.                   Notice also that if the first rule is not proved by the 
  424.              fact  that  isdev1  turns up being TRUE  and  therefore  the 
  425.              antecedent  statement  is FALSE due to the reverse sense  of 
  426.              the IFNOTRUN KEYWORD,  then the others will not be run until 
  427.              they are encountered in other rules containing them.   So be 
  428.              safe and use the RUN forms of the KEYWORDS if you intend the 
  429.              execution of an object.
  430.          
  431.  
  432.  
  433.  
  434.  
  435.  
  436.  
  437.  
  438.  
  439.         George W. Hageman            --8--
  440.  
  441.  
  442.  
  443.  
  444.  
  445.         INFERENCE          -- SOFTMAN ENTERPRIZES --        Dec. 30, 1985
  446.  
  447.  
  448.         USAGE:
  449.  
  450.              Ok,  now  that we know what all the key words are,  how does 
  451.         one go about using an inference engine, and more specifically how 
  452.         does one use this inference engine and what for?  
  453.              
  454.              People  usually use inference engines  as part of  what  are 
  455.         known  as expert systems.   Expert systems are a study associated 
  456.         with  a  branch  of  software  engineering  known  as  Artificial 
  457.         Intelligence (AI).    (I am probably going to get some heat  from 
  458.         that  statement).    Expert systems are supposed to mimic the way 
  459.         in which human experts deal with a particular physical or  mental 
  460.         problem.    A  clear  example  is an expert  system  which  could 
  461.         isolate  a  fault within a complex computer system as well as  or 
  462.         almost  as well as its human counterpart.    It is apparent  that 
  463.         the  computer  expert  system  would lack  much  of  the  tactile 
  464.         resources  the human expert would have,  but the computer  expert 
  465.         could still be of great value when coupled with a novice computer 
  466.         user.    In  this way the computer expert would rely on the human 
  467.         to  perform  actions  and observations  the  computer  expert  is 
  468.         incapable  of  doing.   The computer expert and the  novice  then 
  469.         could form a team which might perform as well as the human expert 
  470.         alone and at a probably much lower per/hour labor rate.
  471.  
  472.              Unfortunately,  in  order to develop an expert  system,  one 
  473.         must  either  be  an expert in the area one wants to  develop  an 
  474.         expert system for or have a ready access to one.   Assuming  that 
  475.         you are or have found one,  the following is a description of how 
  476.         one  would  use  the inference engine and the  rule  compiler  to 
  477.         produce an expert system.    Fortunately one of the sticker tasks 
  478.         of  developing  the inference engine has been done,  and all  you 
  479.         have  to do is develop the rule base,  compile it with  the  rule 
  480.         compiler  and  use  the resultant compiled rule-base  file  as  a 
  481.         parameter  when  you initiate the inference engine.   In  reality 
  482.         this is a much tougher job than developing the inference engine.
  483.  
  484.              Expert   systems  generally  consist  of  three  parts,    a 
  485.         KNOWLEDGE BASE,  HUMAN INTERFACE,  and an INFERENCE ENGINE.   The 
  486.         following is a short description of each:
  487.  
  488.         THE RULE or KNOWLEDGE BASE:
  489.  
  490.              The  rules  consisting of ANTECEDENTS  and  CONSEQUENTS  are 
  491.         known  as  the  "KNOWLEDGE  BASE"  of  the  expert  system.    An 
  492.         additional part of the KNOWLEDGE BASE consists of the executeable 
  493.         files  and  their  shared data files.   The  way  the  "knowledge 
  494.         engineer"  puts  these rules together determines how good  and/or 
  495.         effective  the resultant expert system becomes.    The  KNOWLEDGE 
  496.         BASE  is the smarts of the expert system,  and the basic data  on 
  497.         which the inference engine is to operate upon.
  498.  
  499.  
  500.  
  501.  
  502.  
  503.  
  504.         George W. Hageman            --9--
  505.  
  506.  
  507.  
  508.  
  509.  
  510.         INFERENCE          -- SOFTMAN ENTERPRIZES --        Dec. 30, 1985
  511.  
  512.  
  513.         THE HUMAN INTERFACE:
  514.  
  515.              The  expert system needs a way to ask the human  user  about 
  516.         the  TRUTH or FALSENESS of the antecedents contained in the  rule 
  517.         base.   This  is  contained  as a part of  the  inference  engine 
  518.         associated with this release.    These routines will ask the user 
  519.         whether or not FOLLOWING STRINGS are TRUE or FALSE.    Additional 
  520.         human interfaces may be contained in the executeable files.
  521.  
  522.         THE INFERENCE ENGINE:
  523.  
  524.              The inference engine released with this software is known as 
  525.         a backwards chaining inference engine.    It works by identifying 
  526.         consequents  and  attempting  to find rules to  prove  that  each 
  527.         consequent  is TRUE.   Once a consequent is proved  TRUE,  it  is 
  528.         remembered  as being TRUE.    Each antecedent which is determined 
  529.         either TRUE or FALSE is remembered so that the user does not have 
  530.         to  be  asked more than once to verify  a  particular  statement.  
  531.         Remember  that if a consequent is not proved TRUE,  then it  does 
  532.         not  necessarily  mean that it is FALSE.    For more  information 
  533.         consult  the "inference.str" file which is a  preliminary  pseudo 
  534.         code  description  of the inference engine.   It is  not  correct 
  535.         because   I  have  not  gone  back  and  up  dated  it  from  the 
  536.         implementation effort (Tom De Marco please forgive me) but, it is 
  537.         close  enough to provide a basis for understanding the  code.   I 
  538.         suggest  looking  at the code to understand  how  this  inference 
  539.         engine  works.    I have also left in all of the debug statements 
  540.         which I found helpful so by modifying the makefile to include the 
  541.         DEBUG FLAGS, you can observe the inference engine working.
  542.  
  543.              This   inference  engine  attempts  to  prove  all  of   the 
  544.         consequents  from the top of the rule base through to the  bottom 
  545.         in a linear way if possible.  If however, an antecedent is really 
  546.         a  consequent  of a rule,  the inference engine will  attempt  to 
  547.         prove  that consequent even if it occurs later in the rule  base.  
  548.         In  this sense,  the inference engine will exhibit  some  forward 
  549.         chaining characteristics.
  550.  
  551.              There  are  several good books on the development of  expert 
  552.         systems,  inference  engines  and the like.   I have  included  a 
  553.         bibliography  which contain the books I consulted to  build  this 
  554.         one.
  555.  
  556.  
  557.  
  558.  
  559.  
  560.         George W. Hageman            --10--
  561.  
  562.  
  563.  
  564.  
  565.  
  566.         INFERENCE          -- SOFTMAN ENTERPRIZES --        Dec. 30, 1985
  567.  
  568.  
  569.         BUILDING EXPERT SYSTEMS:
  570.  
  571.              The  builders  of  expert systems  are  sometimes  known  as 
  572.         "knowledge engineers".    As the name implies, they deal with the 
  573.         manipulation  and  representation  of knowledge  leading  to  the 
  574.         development  of the Knowledge base the inference engine  operates 
  575.         upon.    In  order  to develop the knowledge base  the  knowledge 
  576.         engineer  needs either to be an expert in the area for which  the 
  577.         expert system is to be developed or, have ready access to a human 
  578.         expert in the field.   
  579.  
  580.              The  inference engine in this distribution accepts knowledge 
  581.         in  many  ways.   The first of which are the rules  as  discussed 
  582.         above which are relatively simple logical or predicate statements 
  583.         about the TRUTH of well defined consequents.    The other is  the 
  584.         somewhat  complex  knowledge representation as contained  in  the 
  585.         executeable files which may be initiated by the inference engine.  
  586.         In  fact,  the inference engine and the rule_compiler each can be 
  587.         one  of these executeable files so you can have recursive  expert 
  588.         systems  if  you  have a mind to!    You  can  even  use  another 
  589.         executeable  to produce a text file of rules,  which then can  be 
  590.         operated  on  by  the  rule-compiler  and  then  fed  to  another 
  591.         inference  engine  producing  self-modifying or  learning  expert 
  592.         system.   So even though the inference engine is only 12K and the 
  593.         rule  compiler 10K these are sufficient enough to produce  rather 
  594.         powerful expert systems.
  595.  
  596.              To  develop the knowledge base the knowledge engineer  first 
  597.         must  under  stand  the limitations which are acceptable  to  the 
  598.         expert  system  user.   For example,  if the user  of  an  animal 
  599.         identification  expert  system is not concerned with whether  the 
  600.         expert  can  differentiate  between a snake and a  lizard  or  is 
  601.         not interested in reptiles at all,  then the expert system can be 
  602.         simplified  by leaving out this knowledge.    Once the boundaries 
  603.         of  an expert system are well known,  the expert system  designer 
  604.         can concentrate on how to define the particulars.   This software 
  605.         release  contains  two examples of simple  expert  systems.   The 
  606.         first is the more or less classical animal identification expert, 
  607.         and  the second is a weather predictor expert which  demonstrates 
  608.         the usage of the IFRUN, ANDTHENRUN, etc. KEYWORDS.
  609.  
  610.  
  611.  
  612.  
  613.  
  614.  
  615.         George W. Hageman            --11--
  616.  
  617.  
  618.  
  619.  
  620.  
  621.         INFERENCE          -- SOFTMAN ENTERPRIZES --        Dec. 30, 1985
  622.  
  623.  
  624.         ANIMALS:
  625.  
  626.              This is a simple expert which can differentiate between only 
  627.         certain  types of animals -- Mammals and Birds.   And among these 
  628.         two groups it can only tell you that the animal you are  thinking 
  629.         about  is  either  a  Giraffe,  Zebra,  Cheeta,  Tiger,  Penguin, 
  630.         albatross,  Duck,  and  so on.   The example has been limited  to 
  631.         these  few  identifications  in  order to  greatly  simplify  the 
  632.         development  effort  and  to help  demonstrate  the  strategy  of 
  633.         developing the rules associated with this simple expert system.
  634.  
  635.              The strategy associated with the development of a consistent 
  636.         set  of  rules  which  will identify a  particular  animal  given 
  637.         certain  physical  characteristics  to work with  is  DIVIDE  AND 
  638.         CONQUER.    The  idea being to use rules which build  a  decision 
  639.         tree  where each branch of the tree is formed by a rule which can 
  640.         decide  which direction to go at that junction.    Since  we  are 
  641.         obviously  dealing  with birds and mammals then we can build  our 
  642.         root  branch  or  the  grossest division  as  a  rule  which  can 
  643.         differentiate between birds and mammals.   Like:
  644.                   
  645.                   !
  646.                   IF animal gives milk
  647.                   ANDIF animal has hair
  648.                   THEN animal is mammal
  649.                   !
  650.                   IFNOT animal is mammal
  651.                   THEN animal is bird
  652.                   !
  653.                   .
  654.                   .
  655.  
  656.              Notice  that if the animal is not a mammal we  automatically 
  657.         assume  that it is a bird since this is the domain of our  expert 
  658.         system  -- it  does not consider any other type of  animal  as  a 
  659.         possibility.   If  we  were to include perhaps reptiles then  the 
  660.         following might be used instead:
  661.  
  662.                   !
  663.                   IF animal gives milk
  664.                   ANDIF animal has hair
  665.                   THEN animal is mammal
  666.                   !
  667.                   IFNOT animal is mammal
  668.                   AND animal has feathers
  669.                   AND animal lays eggs
  670.                   THEN animal is bird
  671.                   !
  672.                   IFNOT animal is mammal
  673.                   IFNOT animal is bird
  674.                   THEN animal is reptile
  675.                   !
  676.  
  677.  
  678.  
  679.  
  680.  
  681.         George W. Hageman            --12--
  682.  
  683.  
  684.  
  685.  
  686.  
  687.         INFERENCE          -- SOFTMAN ENTERPRIZES --        Dec. 30, 1985
  688.  
  689.  
  690.              Again  the last category is the default and needs no further 
  691.         definitions  because it is within the limitations of  the  expert 
  692.         system.
  693.  
  694.  
  695.              Further  refinement of the decision tree associated with the 
  696.         animals  expert should build on the knowledge gained  by  earlier 
  697.         branching.   So  one should use the knowledge that the animal has 
  698.         been  identified  as a bird to further  define  the  animal.   An 
  699.         example of the further definition of the type of mammal follows:
  700.  
  701.                   !
  702.                   IF animal is mammal
  703.                   ANDIF animal eats meat
  704.                   ANDIF animal eats little vegetation
  705.                   THEN animal is carnivore
  706.                   !
  707.                   IFNOT animal is carnivore
  708.                   ANDNOT animal eats little vegetation
  709.                   THEN animal is vegetarian
  710.                   !
  711.  
  712.              Finer  and  finer branching is achieved by this  divide  and 
  713.         conquer strategy until the leaves of the tree are reached,  These 
  714.         leaves  are  the  actual hypothesis which end the  search  for  a 
  715.         particular animal.  
  716.  
  717.                   .
  718.                   .
  719.                   !
  720.                   IF animal is cat
  721.                   AND animal has tan color
  722.                   AND animal has stripes
  723.                   THENHYP animal is tiger
  724.                   !
  725.                   IF animal is cat
  726.                   AND animal has tan color
  727.                   AND animal has spots
  728.                   THENHYP animal is cheeta
  729.                   !
  730.                   .
  731.                   .
  732.  
  733.              Notice  that  "animal  is cat" should be a  THEN  Consequent 
  734.         somewhere or else the inference engine will simply ask you if the 
  735.         "animal  is  cat" statement is TRUE or not -- which  may  not  be 
  736.         construed  as  a  particularly intelligent thing  for  an  expert 
  737.         system to do.   The intelligence represented by the expert system 
  738.         is directly related to the intelligence you give it.  However, it 
  739.         is possible to get very confused when there are a large number of 
  740.         rules for a particular expert system and mistakes in logic or the 
  741.         development  of  circular  logic occurs.   The first  will  cause 
  742.         incorrect  conclusions to be drawn and the second will cause  the 
  743.         inference engine to crash.   Circular logic causes the  inference 
  744.         engine to run out of stack space.  
  745.  
  746.  
  747.         George W. Hageman            --13--
  748.  
  749.  
  750.  
  751.  
  752.  
  753.         INFERENCE          -- SOFTMAN ENTERPRIZES --        Dec. 30, 1985
  754.  
  755.  
  756.              A  circular argument is an argument which cannot be resolved 
  757.         because  its proof relies on another rule which in turn relies on 
  758.         proving the first statement before it can be proved such as in:
  759.  
  760.                        !
  761.                        IF the second one is true
  762.                        THEN the first one is true
  763.                        !
  764.                        IF the first one is true
  765.                        THEN the second one is true
  766.                        !
  767.  
  768.              Or to expand the concept:
  769.  
  770.                        !
  771.                        IF the third one is true
  772.                        THEN the first one is true
  773.                        !
  774.                        IF the first one is true
  775.                        THEN the second one is true
  776.                        !
  777.                        IF the second one is true
  778.                        THEN the third on is true
  779.                        !
  780.  
  781.              Usually,   when  the inference engine tells you that  "Stack 
  782.         overflow" has occurred -- this will be the problem.
  783.  
  784.              Look at the animal file contained in this release,  see  how 
  785.         the  rules are built and as an exercise add another animal to  be 
  786.         differentiated  like a platypus,  and later add a whole class  of 
  787.         animals such as domestic farm animals, or even a division such as 
  788.         reptiles or insects.
  789.  
  790.              You  will soon notice that your knowledge base will increase 
  791.         very  quickly  with each set of animals you want your  expert  to 
  792.         differentiate.   With this growth of the knowledge base come real 
  793.         difficulty  in keeping the rules correct  and  non-circular.    A 
  794.         strategy  for limiting the complexity for these rules is  to  use 
  795.         the IFRUN or THENRUN capability of this inference engine to fire-
  796.         up  a whole new inference engine which is an expert in one of the 
  797.         major branches of animals.   In this manner one only has to  make 
  798.         the  major decisions associated with a class of animals and  then 
  799.         run  the  expert system which knows how to  handle  the  specific 
  800.         class of animals.  
  801.  
  802.  
  803.  
  804.  
  805.  
  806.         George W. Hageman            --14--
  807.  
  808.  
  809.  
  810.  
  811.  
  812.         INFERENCE          -- SOFTMAN ENTERPRIZES --        Dec. 30, 1985
  813.  
  814.  
  815.         For example:
  816.  
  817.                   !
  818.                   IF animal has feathers
  819.                   AND animal lays eggs
  820.                   THEN animal is bird
  821.                   THENRUNHYP  inference.exe birds.cmp
  822.                   !
  823.                   IFNOT animal is bird
  824.                   AND  animal has hair
  825.                   AND  animal gives milk
  826.                   THEN animal is mammal
  827.                   THENRUNHYP inference.exe mammals.cmp
  828.                   !
  829.  
  830.              The  files  "birds.cmp" and "mammals.cmp" are the  resultant 
  831.         compiled  files  from  the  text  knowledge  bases  "birds"   and 
  832.         "mammals"  which  the knowledge engineer would need  to  produce.   
  833.         But,  as stated above, these files would represent expert systems 
  834.         knowing  only the limited area of birds or mammals and  therefore 
  835.         can be greatly simplified.    NOTE:  inference.exe returns a TRUE 
  836.         value  if  it has proved anything while it ran,  and FALSE if  it 
  837.         could  not  prove anything.   With an IBM AT with 512  KBYTES  of 
  838.         memory  I  was able to load four copies of  an  inference  engine 
  839.         simultaneously.   A good way to see how many your system can deal 
  840.         with at the same time compile the following test:
  841.  
  842.                        !
  843.                        IFRUN INFERENCE.EXE TEST.CMP
  844.                        THENHYP I am done
  845.                        ! 
  846.  
  847.  
  848.         If this file is named TEST, then compile it using the following:
  849.  
  850.                   rulecomp test test.cmp
  851.  
  852.         Then, run the inference engine with the test.cmp file as follows:
  853.  
  854.                   inference test.cmp
  855.  
  856.  
  857.              Notice  that when any routine cannot be run for some  reason 
  858.         or another, an attempt is made to tell you what went wrong -- out 
  859.         of memory,  can't find it,  or some other reason, and the routine 
  860.         will  be assumed to have returned normally with a TRUE  predicate 
  861.         value.   This  is done so that the inference engine won't  simply 
  862.         die at some mysterious point.   The "I infer that : I am done" at 
  863.         the top was the last inference engine which could be loaded which 
  864.         could run but could not spawn a new process, the next one down is 
  865.         the  last one which could spawn one,  and any others  below  this 
  866.         line  plus  this  one will tell you the number of levels  of  the 
  867.         inference engine you can run on your system.  
  868.  
  869.  
  870.  
  871.  
  872.         George W. Hageman            --15--
  873.  
  874.  
  875.  
  876.  
  877.  
  878.         INFERENCE          -- SOFTMAN ENTERPRIZES --        Dec. 30, 1985
  879.  
  880.  
  881.         THE WEATHER EXPERT:
  882.  
  883.              The  other  expert system knowledge base included with  this 
  884.         release  is  a weather predicting  expert.   This  expert  system 
  885.         demonstrates   the   use  of  executeable  files  to  expand  the 
  886.         abilities  of  the inference engine to deal with other  forms  of 
  887.         knowledge.   Look  a  the source files for  the  weather  expert, 
  888.         notice how each member of this set of routines uses a common file 
  889.         for  the  transfer of needed data.   The need of a file for  this 
  890.         transfer of data is done because it was the only standard form of 
  891.         data  transmission  which was not machine dependent according  to 
  892.         MS-DOS and UNIX operating systems.   Specific methods for dealing 
  893.         with this problem can be found for your machine which can greatly 
  894.         speed up this cumbersome data transfer method -- but it works.   
  895.  
  896.              UNIX  and the Microsoft C compiler allows a routine to  exit 
  897.         with a value which will be returned to the parent process.   This 
  898.         method  is  used to allow each executeable to return  its  TRUTH-
  899.         VALUE  or  PREDICATE-VALUE back to  the  inference  engine.   The 
  900.         routine  runRoutine(consequent) performs this task.   If you look 
  901.         at  the  file runrouti.c you can see that this is done  with  the 
  902.         "exit(value) ;" statement.  The values used to indicate the TRUTH 
  903.         and  FALSEness  of  the  routine  are  "RETURN_ROUTINE_TRUE"  and 
  904.         "RETURN_ROUTINE_FALSE"   as   contained  in   the   header   file 
  905.         "routine.h".   This header file should be included in any routine 
  906.         which returns a TRUE/FALSE value to the inference engine.
  907.  
  908.              The   strategy  for  using  this  method  of  expanding  the 
  909.         knowledge  base  is essentially the same as that for  the  animal 
  910.         type  expert  system,  except that it is noticed that the  simple 
  911.         form  of  the  knowledge base does not  have  the  capability  to 
  912.         perform  some  of  the functions  needed.   Cases  where  complex 
  913.         questions  or the manipulation of data are necessary must  resort 
  914.         to  the use of executeable files which can deal with them.   Such 
  915.         is the case for the weather predicting expert system.
  916.  
  917.              The  weather expert must deal with such data  as  barometric 
  918.         pressure,  wind direction,  and the current rate of change of the 
  919.         barometric  pressure.    Additional data such as cloud conditions 
  920.         can  be  handled  by the predicate  functions  of  the  inference 
  921.         engine.     Again  the  strategy  is  to divide  and  conquer  by 
  922.         determining  which  information  needs  to  be  gathered  by  the 
  923.         executeable portion of the expert system,  what routines must  be 
  924.         used  to  convert  this data into a form which is usable  by  the 
  925.         inference engine i.e.  TRUE or FALSE,  and,  what information can 
  926.         be  gathered  directly  by the  inference  engine.    Once  these 
  927.         decisions are made then a decision tree can be built in a similar 
  928.         manner  to  the  one  built  for  the  animal  expert  but   also 
  929.         incorporating the executeable files where appropriate.    Look at 
  930.         the  file  "weather"  and  at each of the source  files  for  the 
  931.         executeable portion of the weather expert.  
  932.  
  933.  
  934.  
  935.  
  936.  
  937.  
  938.         George W. Hageman            --16--
  939.  
  940.  
  941.  
  942.  
  943.  
  944.         INFERENCE          -- SOFTMAN ENTERPRIZES --        Dec. 30, 1985
  945.  
  946.  
  947.              Notice  that there is a "main" routine (even though  all  of 
  948.         the  programs  are  stand-a-lone programs and are have  the  name 
  949.         "main").   This routine is in the file "MESSAGE1.C", and provides 
  950.         the  data entry for all of the data needed by the expert  system.  
  951.         The  routine  explains to the user what  is  needed,  checks  for 
  952.         reasonable  responses,  and  writes the data to a disk  file  for 
  953.         later  use  by  the other routines associated with  this  system.  
  954.         These other routines,  when initiated,  have the task of  reading 
  955.         the  disk file produced by the "MESSAGE1.EXE" executeable,  check 
  956.         for  some conditions,  and return "ROUTINE_RETURN_TRUE",  if  the 
  957.         conditions are met and "ROUTINE_RETURN_FALSE" if they are not.
  958.  
  959.              In  this  manner  the knowledge  engineer  can  make  expert 
  960.         systems   of  a  higher  complexity  and  usefulness  than  would 
  961.         otherwise be possible.
  962.  
  963.         CONCLUSION:
  964.  
  965.              I hope that this short definition of the inference engine is 
  966.         enough  to  get  you started into the fascinating  field  of  AI.   
  967.         There are some useful additions the enthusiastic programmer could 
  968.         make  to the inference engine to both enhance its usefulness  and 
  969.         its  ability to assist in the debugging of knowledge  basses.   A 
  970.         "Why"  function which shows the complete logical path which  lead 
  971.         to  the  question being asked,  showing each statement  as  being 
  972.         known or unknown and if known what its predicate value is,  would 
  973.         be very helpful.    Further,  the addition of different  KEYWORDS 
  974.         such  as  an  OR function,  might expand the  usefulness  of  the 
  975.         inference engine.  I may include these in my next release of this 
  976.         software  but If you have made such an addition -- I will include 
  977.         them in the next release and refund your $10.00 if you have  been 
  978.         so good as to send it to me.
  979.  
  980.              Good  luck  and if you have any questions or would  like  to 
  981.         discuss this concept please drop me a line.
  982.  
  983.                                  Thanks,
  984.  
  985.                                       George W. Hageman
  986.  
  987.  
  988.  
  989.  
  990.  
  991.         George W. Hageman            --17--
  992.  
  993.  
  994.  
  995.  
  996.  
  997.         INFERENCE          -- SOFTMAN ENTERPRIZES --        Dec. 30, 1985
  998.  
  999.  
  1000.         BIBLIOGRAPHY:
  1001.  
  1002.              The  following  books  and articles  were  helpful  in  the 
  1003.         development of this inference engine.  
  1004.  
  1005.              MVP-FORTH EXPERT SYSTEM TOOLKIT,  Jack Park,   Mountain View 
  1006.         Press,  Inc.  P.O. Box 4656 Mountain View, CA 94040 Phone: (415)-
  1007.         961-4130.
  1008.  
  1009.              MVP-FORTH EXPERT-2 TUTORIAL,  Mitch Derick and Linda Derick, 
  1010.         Mountain View Press.
  1011.  
  1012.              INSIDE F83, C. H. Ting,  OFFETE ENTERPRISES, INC.  Available 
  1013.         from Moutain View Press. 
  1014.  
  1015.              Expert  Systems  and the Weather,  Jack  Park,   Dr.  Dobb's 
  1016.         Journal, April 1984, pp. 24-28.
  1017.  
  1018.              Programming in Prolog,  William F.  Clocksin and Christopher 
  1019.         S. Mellish, Springer-Verlag 
  1020.  
  1021.              LISP,  Patrick H.  Winston and Berthold Klaus and Paul Horn, 
  1022.         Addison Weseley.
  1023.  
  1024.              A  special  thankyou to Jack Park and the  MVP-FORTH  EXPERT 
  1025.         SYSTEM  TOOLKIT.   Many  of  the ideas in this document  and  the 
  1026.         development environment afforded by FORTH were the starting point 
  1027.         for many of the ideas developed in this inference engine.  If you 
  1028.         are into FORTH this is an excellent source of information on  the 
  1029.        subject.  
  1030.  
  1031.  
  1032.  
  1033.  
  1034.  
  1035.  
  1036.         George W. Hageman            --18--
  1037.  
  1038.  
  1039.  
  1040.  
  1041.