home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / prolog / pdprolog / prolog.doc < prev    next >
Text File  |  1986-05-05  |  87KB  |  3,037 lines

  1.  
  2.          
  3.  
  4.  
  5.  
  6.  
  7.  
  8.  
  9.  
  10.  
  11.  
  12.  
  13.  
  14.  
  15.                            AUTOMATA DESIGN ASSOCIATES
  16.  
  17.  
  18.  
  19.                                                           1570 Arran Way
  20.                                                           Dresher, Pa.
  21.                                                           19025
  22.                                                           (215)-646-4894
  23.                                                           December 14,1985
  24.         Dear PD user:
  25.  
  26.              Here's version 1.8 of PD PROLOG. It's better, of course. And 
  27.         now I must ask a favor of you.
  28.  
  29.              The   AAAI   fifth   national   conference   on   artificial 
  30.         intelligence is on August 11 to 15th, 1986 in Philadelphia. Since 
  31.         I live next to Philly,  I'd love to exhibit there. The problem is 
  32.         that  the rate is $2200 for a 10' x 10' booth,  with a $600  rate 
  33.         for publishers.
  34.  
  35.              I  am  appealing to the coordinator of the  conference,  Ms. 
  36.         Claudia   Mazzetti,   for  a  publishers  rate  break  with   the 
  37.         justification  of my contribution to the public  domain.  I  have 
  38.         sent  to Ms.  Mazzetti a financial statement which shows  clearly 
  39.         that  I  cannot afford the standard rate.  Ms.  Mazzetti was  not 
  40.         particularly   impressed  with  my  request,   but  perhaps  some 
  41.         substantiation of my contribution will change her mind.
  42.  
  43.              I  therefore  request that you  write  Ms.  Mazzetti  before 
  44.         February  at the below address,  and inform her of what I've done 
  45.         for mankind, the Byte readership, etc:
  46.  
  47.                               Ms. Claudia Mazzetti
  48.                               Director, AAAI-86
  49.                               445 Burgess Drive
  50.                               Menlo Park, CA 94025-3496
  51.  
  52.                                 Sincerely yours,
  53.  
  54.  
  55.                                    Bob Morein
  56.                               Author, A.D.A. PROLOG
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.                      A.D.A PROLOG Documentation Version 1.90
  74.                   for the Educational and Public Domain Versions
  75.  
  76.                                   January 5, 1985
  77.  
  78.               Copyright Robert Morein and Automata Design Associates
  79.  
  80.                                  1570 Arran Way
  81.                                Dresher, Pa. 19025
  82.  
  83.                                  (215)-646-4894
  84.  
  85.  
  86.  
  87.  
  88.  
  89.  
  90.  
  91.  
  92.  
  93.  
  94.  
  95.  
  96.  
  97.  
  98.  
  99.  
  100.  
  101.  
  102.  
  103.  
  104.  
  105.  
  106.  
  107.  
  108.  
  109.  
  110.  
  111.  
  112.  
  113.  
  114.  
  115.  
  116.  
  117.  
  118.  
  119.  
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134.                                       News
  135.  
  136.              Release 1.90 of PD PROLOG now accesses all the memory in the 
  137.         machine.  The  space for programs and stack in a PC with 640k  of 
  138.         memory  is about 470 kbytes.  This means that it is equal to  our 
  139.         commercial products in basic power, though without virtual memory 
  140.         and the predicate extensions.
  141.  
  142.              There  is a very interesting natural language parsing system 
  143.         by Lou Schumacher of Future Dimensions in directory "ATN".  Lou's 
  144.         system,  known as an augmented transition network parser, is very 
  145.         well documented,  since the paper he wrote on the subject is also 
  146.         included.  You'll  need  Volkswriter to print it  out,  but  it's 
  147.         readable as is.  The system requires ED PROLOG to run,  since  it 
  148.         makes use of the grammar rule syntax. I challenge a user to write 
  149.         a  grammar  rule  translator to make Lou's program  run  with  PD 
  150.         PROLOG.
  151.  
  152.              Another project worth doing would be a simple editor written 
  153.         in  PROLOG.  It  would  use the  "read"  predicate,  and  display 
  154.         selected clauses for modification or deletion.
  155.  
  156.              Simon   Blackwell's   "PIE"  Truth  Maintenance  System   is 
  157.         presented in revised, debugged, and enlarged form. This system is 
  158.         found  in  the  directory  "expert"  and  augments  the  strictly 
  159.         deductive  capabilities  of raw Prolog with additional  forms  of 
  160.         reasoning.  PIE  has a syntax that resembles colloquial  English. 
  161.         Wait till you see the backwards quote marks!
  162.  
  163.              The predicates "batch" and "nobatch" are introduced to allow 
  164.         execution  of batch files without confusing messages and  prompts 
  165.         appearing on the screen. I've put one in Simon's "KOPS" file.
  166.  
  167.  
  168.  
  169.                                 Copyright Notice
  170.  
  171.              The  public domain PD PROLOG system has been contributed  to 
  172.         the  public domain for unrestricted use with one  exception:  the 
  173.         object  code  may not be  disassembled  or  modified.  Electronic 
  174.         bulletin  boards  and SIG groups are urged to aid in giving  this 
  175.         software the widest possible distribution.
  176.  
  177.              This documentation may be reproduced freely,  but it may not 
  178.         be  included in any other documentation without the permission of 
  179.         the author.
  180.  
  181.  
  182.  
  183.  
  184.  
  185.  
  186.  
  187.  
  188.  
  189.  
  190.  
  191.  
  192.  
  193.  
  194.  
  195.  
  196.  
  197.  
  198.  
  199.  
  200.                                   Introduction
  201.                 
  202.         We  are pleased to present the third major version of PD  PROLOG, 
  203.         version 1.7.  Version 1.7 continues to refine "problems" and adds 
  204.         the  entertaining  feature of IBM PC video  screen  support.  The 
  205.         memory requirements are somewhat greater than the original, since 
  206.         it   is  uses  the  large  memory  model.   It   compensates   in 
  207.         thoroughness.  The memory requirement is about 210K bytes of TPA, 
  208.         and it will benefit from any available memory. 
  209.  
  210.         We  hope  that you'll get some fun out of this  PROLOG.  It  will 
  211.         afford  you exposure to THE fifth generation language at the cost 
  212.         only  of  some  intellectual  effort.  The  motive  is  perfectly 
  213.         explicable:  We  want you to think of Automata Design  Associates 
  214.         for  fifth  generation  software.  It also gives us a  nice  warm 
  215.         feeling.
  216.  
  217.         The  minimum  memory  requirement is 200 k of  transient  program 
  218.         area,  plus  whatever  space is needed to execute  programs  from 
  219.         within PROLOG.  DOS or MSDOS 2.0 are required.  The program  does 
  220.         not  require  IBM PC compatibility to run,  although  the  screen 
  221.         access routines do require compatibility.
  222.  
  223.  
  224.  
  225.  
  226.  
  227.  
  228.  
  229.  
  230.  
  231.  
  232.  
  233.  
  234.  
  235.  
  236.  
  237.  
  238.  
  239.  
  240.  
  241.  
  242.  
  243.  
  244.  
  245.  
  246.  
  247.  
  248.  
  249.  
  250.  
  251.  
  252.  
  253.  
  254.  
  255.  
  256.  
  257.  
  258.  
  259.  
  260.  
  261.  
  262.  
  263.  
  264.  
  265.  
  266.                      Products by Automata Design Associates
  267.  
  268.              Automata  Design  Associates  specializes  in  software  for 
  269.         artificial  intelligence  and  robotic  applications.   A  PROLOG 
  270.         language  system is available in various configurations.  A  LISP  
  271.         interpreter will be introduced in March of 1985.
  272.  
  273.  
  274.              There  are  six versions of PROLOG available  from  Automata 
  275.         Design Associates.  The systems run under the MSDOS or PCDOS. All 
  276.         of them access all available memory up to 1 megabyte.
  277.  
  278.              .Public Domain PROLOG
  279.  
  280.         This  serves to further the general awareness of the public about 
  281.         PROLOG.  It  also is an excellent adjunct to anyone learning  the 
  282.         language.  Most  of  the core PROLOG described  by  Clocksin  and 
  283.         Mellish  in  the book Programming In  PROLOG  is  implemented.  A 
  284.         complete  IBM PC video screen support library is included in this 
  285.         and  all other A.D.A.  prologs.  Trace predicates are  not.  This 
  286.         version is available from us for $10.00 postage paid.
  287.  
  288.  
  289.              .Educational PROLOG
  290.  
  291.         At  extremely modest cost this affords an educational institution 
  292.         or  individual  a  PROLOG  system  which  provides  the   maximum 
  293.         available  programming  area  available  within  the  8086  small 
  294.         programming model.  Tracing,  a debugging aid,  allows monitoring 
  295.         a program as it runs.  User settable spy points selectively allow 
  296.         this.  Exhaustive  tracing  is also  available.  I/O  redirection 
  297.         gives some file ability.
  298.  
  299.              An  "exec"  function allows the execution of  a  program  or 
  300.         editor  from  within  PROLOG,  thus  encouraging  an  interactive 
  301.         environment.
  302.  
  303.              An  "interrupt"   menu is added,  permitting the control  of 
  304.         tracing, toggling the printer, and screen printing.
  305.  
  306.              Definite clause grammar support is now included.
  307.              
  308.              The cost of Educational PROLOG is $29.95.
  309.  
  310.  
  311.  
  312.  
  313.  
  314.  
  315.  
  316.  
  317.  
  318.  
  319.  
  320.  
  321.  
  322.  
  323.  
  324.  
  325.  
  326.  
  327.  
  328.  
  329.  
  330.  
  331.  
  332.              .FS PROLOG
  333.  
  334.              A  small  increment  in price adds full random  access  file 
  335.         capability. Character and structure I/O are allowed.
  336.  
  337.              The  "asserta and "assertz" predicates are expanded and work 
  338.         with a clause indexing ability.  One can assert clauses  anywhere 
  339.         in the database under precise pattern matching control. 
  340.  
  341.              A tree structured lexical scoping system and floating  point 
  342.         arithmetic are other enhancements.
  343.  
  344.              The cost of FSM PROLOG is $49.95
  345.  
  346.  
  347.  
  348.              .VMI PROLOG -- Virtual Memory (Replaces type VMS)
  349.  
  350.  
  351.              At reasonable cost the addition of virtual memory gives  an 
  352.         expansion of capabilities of an order of magnitude. 
  353.  
  354.              The  database on disk is treated transparently.  No  special 
  355.         provisions  need  be  made  by the  user.  Virtual  and  resident 
  356.         databases  may be mixed.  A unique updating algorithim  preserves 
  357.         the format of the database as typed by the user while making only 
  358.         those changes necessary to make it equivalent to the database  in 
  359.         central memory.
  360.  
  361.              The cost of VMI PROLOG is $99.95
  362.  
  363.  
  364.  
  365.  
  366.  
  367.  
  368.  
  369.  
  370.  
  371.  
  372.  
  373.  
  374.  
  375.  
  376.  
  377.  
  378.  
  379.  
  380.  
  381.  
  382.  
  383.  
  384.  
  385.  
  386.  
  387.  
  388.  
  389.  
  390.  
  391.  
  392.  
  393.  
  394.  
  395.  
  396.  
  397.  
  398.              .VML PROLOG Large model Virtual Memory System
  399.  
  400.              A.D.A.  PROLOG is a remarkable fifth generation developement 
  401.         tool  for  the  implementation  of  intelligent  strategies   and 
  402.         optimized  control.  It  is both the kernel for  applications  of 
  403.         virtually  unlimited scope and a sophisticated developement  tool 
  404.         that multiplies the productivity of the programmer many times. 
  405.  
  406.              With  a  cost/performance ratio exceeding that of any  other 
  407.         product  and  a  compatibility  insured  by  compliance  to   the 
  408.         Edinburgh syntax, performance is enhanced by numerous extensions, 
  409.         many of them invisible to the user.
  410.  
  411.              A quick overview of some of the features discloses:
  412.  
  413.              1)  Invisible  compilation  to  a  semantic  network 
  414.              preserves the flexibility of the interpreted mode and 
  415.              the speed of a compiler.
  416.  
  417.              The  programmer can compile and recompile any portion 
  418.              of a module at any time.  The edit/compile/test cycle 
  419.              is short and free of strain. An interface is provided 
  420.              to an editor of choice.
  421.  
  422.  
  423.              2) Floating point arithmetic with a full  complement 
  424.              of  input  and  output  methods,  transcendental  and 
  425.              conversion functions.
  426.  
  427.  
  428.              3)  Virtual  memory.  Module  size  and  number  are 
  429.              unrestricted,   with  a  total  capacity  of  several 
  430.              hundred megabytes.  Resident and virtual modules  may 
  431.              be co-resident. Compilation is incremental. The cache 
  432.              algorithim  is  sophisticated.  Changes made  in  the 
  433.              database can be updated to disk by a single command.
  434.  
  435.  
  436.              4) A powerful exec function and acceptance of  stream 
  437.              input make  integration into  applications practical.
  438.  
  439.  
  440.              5)  Global polymorphic variables  retain  information 
  441.              that  would  otherwise  require  the  "assertion"  of 
  442.              facts.
  443.  
  444.  
  445.              6)  A  quoted  variable class,  borrowed  from  LISP, 
  446.              permits  referencing variables as objects as well  as 
  447.              by value.
  448.  
  449.              7) Multidimensional arrays,  dynamically created  and 
  450.              destroyed,  efficiently  store numeric and nonnumeric 
  451.              structures. Arrays are ideal for representing spatial 
  452.              and ordinal relationships.
  453.              8)  Debugging facilities let you see your program run 
  454.              without any additional generation steps.
  455.  
  456.  
  457.              9)   Totally   invisible  and   incremental   garbage 
  458.  
  459.  
  460.  
  461.  
  462.  
  463.  
  464.              collection.   There   is  NEVER  any  wait  for  this 
  465.              function.
  466.  
  467.  
  468.              10)  A  tree  structured,   dynamically  configurable 
  469.              lexical scoping system. The work of many  programmers 
  470.              can  be coupled together in the form of libraries and 
  471.              nested domains. 
  472.  
  473.              Each lexically scoped domain is a hidden space  which 
  474.              communicates  with the parent domain via exports  and 
  475.              imports. Domains can be linked together under program 
  476.              control to achieve any desired configuration.
  477.  
  478.  
  479.              11) The Grammar Rule Notation is an integral feature.
  480.  
  481.  
  482.              12) Keyword redefinition makes porting code easy.
  483.  
  484.  
  485.         The  cost  of this system is $200 for the MSDOS version.
  486.  
  487.  
  488.  
  489.         .VMA PROLOG Large model Virtual Memory System
  490.  
  491.         This  system  has  additional forms of  virtual  memory.  It  was 
  492.         intended  for  deep  reasoning  problems.  Contact  us  for  more 
  493.         information.
  494.  
  495.  
  496.  
  497.  
  498.  
  499.  
  500.  
  501.  
  502.  
  503.  
  504.  
  505.  
  506.  
  507.  
  508.  
  509.  
  510.  
  511.  
  512.  
  513.  
  514.  
  515.  
  516.  
  517.  
  518.  
  519.  
  520.  
  521.  
  522.  
  523.  
  524.  
  525.  
  526.  
  527.  
  528.  
  529.  
  530.                                  Upgrade Policy
  531.  
  532.              Half the cost of any A.D.A. PROLOG system may be credited to 
  533.         the purchase of a higher level version.      The full cost of VMS 
  534.         prolog  may  be  applied to the purchase of VMI  or  VML  PROLOG. 
  535.         Updates to a particular level product vary from $15.00 to $35.00.
  536.  
  537.  
  538.                                 Run-time Packages
  539.  
  540.              Software  developers wishing to integrate an A.D.A.  product 
  541.         into  their  system  should inquire  about  specialized  run-time 
  542.         packages available at reasonable cost.
  543.  
  544.  
  545.  
  546.                               Technical Information
  547.  
  548.              Technical information may be obtained at (215) - 646- 4894
  549.  
  550.              Perhaps we can answer the following questions in advance:
  551.  
  552.              There is no support for:  APPLE II, Atari, Commodore, or  
  553.         CPM 80 .  Other machines from these manufactures may be supported 
  554.         in the future.
  555.  
  556.              The MSDOS products are available on 5" and 8" diskettes.
  557.  
  558.  
  559.  
  560.                               To Place Your Order:
  561.  
  562.              You may place your order at the following number:
  563.  
  564.                         (215)-646-4894   - day and night.
  565.  
  566.  
  567.  
  568.                                      Returns
  569.  
  570.              The  software may be returned within 30 days of purchase for 
  571.         a full refund.  This applies whether or not the software has been 
  572.         used.  We do ask that manuals, disks and packaging be returned in 
  573.         excellent condition.
  574.  
  575.  
  576.  
  577.  
  578.  
  579.  
  580.  
  581.  
  582.  
  583.  
  584.  
  585.  
  586.  
  587.  
  588.  
  589.  
  590.  
  591.  
  592.  
  593.  
  594.  
  595.  
  596.                                   Installation
  597.  
  598.              You will need an IBM PC compatible machine with a minimum of 
  599.         256  kbytes  of  memory.  ED PROLOG benefits from  all  available 
  600.         memory up to the 1 megabyte INTEL limit.
  601.  
  602.              To  determine the amount of TPA your machine  has,  run  the 
  603.         "chkdsk" program which is supplied with DOS. The last line reads:
  604.  
  605.                                 XXXXXX bytes free
  606.  
  607.         where XXXXXX is a six digit number.
  608.  
  609.         If  this  number  is greater than 200000,  ED  PROLOG  will  have 
  610.         reduced workspace.  If it's over 245000,  the amount of memory is 
  611.         optimal. If this is not the case, there are two possibilities:
  612.  
  613.         1) The machine doesn't have enough memory.
  614.  
  615.         2)  Something  else is removing memory from TPA,  such as  a  co-
  616.         resident  program,  a  ramdisk,  a large dos driver,  or a  large 
  617.         number of file or disk buffers.
  618.  
  619.         If  you're  short of memory,  make sure that no  other  programs, 
  620.         ramdisks,  or drivers besides DOS are running in the machine. You 
  621.         may find it helps to eliminate (by renaming) the config.sys  file 
  622.         when you intend to run ED PROLOG.
  623.  
  624.  
  625.                       How to run the Demonstration Programs 
  626.                         without Knowing What You're Doing
  627.  
  628.              We strongly advise that you purchase the book Programming in 
  629.         PROLOG by Clocksin and Mellish,  publisher Springer Verlag, 1981. 
  630.         For  the  impatient we give some advice.  Type the  demonstration 
  631.         program you wish to run.  There must be at least one entry  point 
  632.         within  the  program.  
  633.  
  634.         Note:  Please  understand that these are demonstrations programs. 
  635.         Regarding  user  interface,  they are poorly  written.  You  will 
  636.         probably have to read Clocksin and Mellish to appreciate that the 
  637.         following examples of input are not equivalent: "yes." , "yes" .
  638.  
  639.  
  640.         The animals program - "animal"
  641.          
  642.              Most  of the examples require C & M for  comprehension.  The 
  643.         program "animals", however, can be appreciated by anyone. It is a 
  644.         traditional   example of an expert system.
  645.              
  646.              We had hoped to include the animals program on disk,  but we 
  647.         have  found  to  our  dismay that the version which  we  used  is 
  648.         allegedly copyrighted by the implementors of PROLOG 86.  Don't be 
  649.         surprised - even "happy birthday" is copyrighted.  We will simply 
  650.         point out that the November '84 issue of Robotics Age included  a 
  651.         version  of  the  animals game,  which you can,  at the  risk  of 
  652.         copyright infringement,  type in.  There is only one change  that 
  653.         need  be  made.  The "concat" function used in that  program  has 
  654.         arguments of the form:
  655.  
  656.  
  657.  
  658.  
  659.  
  660.  
  661.  
  662.                       concat( [atom1, atom2,...], result ).
  663.  
  664.         In order to make the concat definition more closely resemble that 
  665.         of  "name",  which  is  described by Clocksin  and  Mellish,  the 
  666.         argments have been reversed:
  667.  
  668.                       concat( result, [atom1, atom2,...] )
  669.  
  670.         Assuming  that you have typed in the program and made the  change 
  671.         just noted, the following steps are required to run it:
  672.              
  673.              Run the prolog.exe file.  The prompt "?-" will appear.  Type 
  674.         "consult( 'animals' ).<CR>".  Here <CR> indicates you are to type 
  675.         a  carriage  return.  The PROLOG system will load  "animals"  and 
  676.         compile  it into an internal form.  When the "?-" prompt  appears 
  677.         PROLOG is ready to run the "animals" guessing game. The object of 
  678.         the program is to deduce the animal you are thinking of. To start 
  679.         it  off  type  "help.<CR>".  PROLOG  will  respond  by  asking  a 
  680.         question. 
  681.              Because of the way the animals program is written,  you must 
  682.         respond in a rigid format.  You may type "yes<CR>",  "no<CR>", or 
  683.         "why<CR>". 
  684.              Eventually the program will terminate with either a guess as 
  685.         to what animal you are thinking of,  or a remark that the  animal 
  686.         is  not within its domain of knowledge.  The program has learned, 
  687.         however.  You  may  run  the  program again to  see  what  effect 
  688.         additional knowledge has on the program's behavior. 
  689.  
  690.              The program fragment "console" shows how you may improve the 
  691.         console input routines of any of these programs.
  692.              
  693.  
  694.         The Hematology Diagnosis Program - "hemat"
  695.  
  696.              Although  the  logical structure is not as sophisticated  as 
  697.         that of "animals", it is interesting for several reasons:
  698.  
  699.              1)  The  program  evaluates numerical data to  arrive  at  a 
  700.         diagnosis.
  701.  
  702.              2) Although inaccurate, it demonstrates that useful question 
  703.         answering systems are not difficult to write in PROLOG.
  704.  
  705.              3)  There  are  some mistakes in  the  program,  which  only 
  706.         slightly impede its usefulness. 
  707.  
  708.              This  program  uses  structure  input.  Terminate  all  your 
  709.         answers with a period, as in "y.<CR>", or "no.<CR>".
  710.         The starting point is "signs.<CR>".  PROLOG will prompt  you 
  711.         for  signs  of  anemia.  The  program attempts  to  diagnose  two 
  712.         varieties of a hemolytic anemia.
  713.              The program could use a good working over by a  hematologist 
  714.         and we would be delighted to collaborate.
  715.  
  716.  
  717.         Prime Number Generator - "sieve"
  718.  
  719.              This  program demonstrates that anything can be programed in 
  720.         PROLOG if one tries hard enough.  Asking the  question   
  721.           "primes( 50, L ).<CR>" causes a list of prime numbers less than 
  722.  
  723.  
  724.  
  725.  
  726.  
  727.  
  728.         50  to be printed out.  "Sieve" is heavily recursive and  quickly 
  729.         exhausts the stack space of the small model interpreters.
  730.  
  731.  
  732.         Grrules
  733.  
  734.              This  is  an  example  of the use  of  the  definite  clause 
  735.         grammer  notation.  PD  PROLOG  does not  have  this  translation 
  736.         facility,  but ED PROLOG and  all of our other versions do. It is 
  737.         possible  to  perform  the  translations  by  hand  if  you  have 
  738.         thoroughly  read  C  & M.  Then you would have  the  pleasure  of 
  739.         asking:
  740.  
  741.                  ?-sentence( X, [every,man,loves,a,woman], [] ).
  742.  
  743.         and  having the meaning elucidated as a statment in the predicate 
  744.         calculus.
  745.  
  746.  
  747.  
  748.  
  749.  
  750.  
  751.  
  752.  
  753.  
  754.  
  755.  
  756.  
  757.  
  758.  
  759.  
  760.  
  761.  
  762.  
  763.  
  764.  
  765.  
  766.  
  767.  
  768.  
  769.  
  770.  
  771.  
  772.  
  773.  
  774.  
  775.  
  776.  
  777.  
  778.  
  779.  
  780.  
  781.  
  782.  
  783.  
  784.  
  785.  
  786.  
  787.  
  788.  
  789.  
  790.  
  791.  
  792.  
  793.  
  794.                                Special Offer  # 1
  795.  
  796.              For  some  inexplicable reason,  demonstration programs  are 
  797.         hard to come by. We are too busy writing PROLOG fill this gap. We 
  798.         will  reward the contribution of "cute" sample programs with  the 
  799.         following:
  800.  
  801.              1) A free  copy of type VMI virtual memory PROLOG
  802.  
  803.              2) The sample program will be published as an intact file 
  804.              together with whatever comments or advertisments the author
  805.              may see fit to include, on our distribution disks. 
  806.  
  807.              3) Exceptional contributions may merit a copy of type VML 
  808.              large  model virtual memory PROLOG which now incorporates  a 
  809.              UNIX1 style tree structured domain system.
  810.  
  811.  
  812.                                 Special Offer # 2
  813.  
  814.  
  815.              If  you are a hardware manufacturer and would like a  PROLOG 
  816.         language  for your system,  the solution is simple.  Just send us 
  817.         one  of  your machines!  Provided your system  implements  a  "C" 
  818.         compiler, it will be ported in no time flat.
  819.  
  820.  
  821.         ______
  822.              1. Trademark of AT & T.
  823.  
  824.  
  825.  
  826.  
  827.  
  828.  
  829.  
  830.  
  831.  
  832.  
  833.  
  834.  
  835.  
  836.  
  837.  
  838.  
  839.  
  840.  
  841.  
  842.  
  843.  
  844.  
  845.  
  846.  
  847.  
  848.  
  849.  
  850.  
  851.  
  852.  
  853.  
  854.  
  855.  
  856.  
  857.  
  858.  
  859.  
  860.                          Writing Programs For ED PROLOG
  861.  
  862.              You do not type in programs at the "?-" prompt.  There is no 
  863.         built-in  editor.  The command "consult( user )" is accepted  but 
  864.         does not cause PROLOG to enter an editing mode.  We feel that the 
  865.         most universally acceptable editing method is for the user to use 
  866.         a text editor of choice,  which can be invoked from within PROLOG 
  867.         by the "exec" predicate.
  868.  
  869.              Use  Wordstar  or your customary editor to write a  program. 
  870.         Then  run  PD  PROLOG and use the consult function  to  load  the 
  871.         program.
  872.  
  873.              In  all  cases except PD PROLOG,  you can  run  your  editor 
  874.         without leaving PROLOG by use of the "exec" predicate.
  875.  
  876.  
  877.  
  878.  
  879.  
  880.  
  881.  
  882.  
  883.  
  884.  
  885.  
  886.  
  887.  
  888.  
  889.  
  890.  
  891.  
  892.  
  893.  
  894.  
  895.  
  896.  
  897.  
  898.  
  899.  
  900.  
  901.  
  902.  
  903.  
  904.  
  905.  
  906.  
  907.  
  908.  
  909.  
  910.  
  911.  
  912.  
  913.  
  914.  
  915.  
  916.  
  917.  
  918.  
  919.  
  920.  
  921.  
  922.  
  923.  
  924.  
  925.  
  926.                              Running the Interpreter
  927.  
  928.         COMMANDS: Give commands in lower case.
  929.  
  930.         TO RUN:
  931.              Invoke PROLOG.EXE. After the "?-" prompt appears,
  932.                type "consult( <filename><CR> )", where <filename> is the 
  933.                desired database.
  934.              To exit, type "exitsys.<CR>"
  935.  
  936.         TO ENTER A FACT:
  937.              Don't do it except with the "assert" predicates. This is the 
  938.              most  frequently misunderstood aspect of A.D.A.  Prolog.  If 
  939.              you want to enter a bunch of facts,  put them in a file  and 
  940.              "consult" them using the "consult" predicate.
  941.  
  942.         TO ASK A QUESTION:
  943.              At the prompt, type "<expression>.<CR>", where 
  944.              <expression>  is  a  question as described by  Clocksin  and 
  945.              Mellish. Be sure to terminate the question with a period.
  946.              The question may be up to 500 characters long.
  947.  
  948.         TO INPUT A STRUCTURE AT THE KEYBOARD:
  949.              The structure may be up to 500 characters in length. Be sure 
  950.              to terminate with a period.
  951.  
  952.         TO ASK FOR ANOTHER SOLUTION:
  953.              If a solution has been provided, the PROLOG interpreter will 
  954.              ask  "More?  (Y/N):".  Only  if  a "y"  is  typed  will  the 
  955.              interpreter perform a search.
  956.  
  957.         TO ABORT A SEARCH:
  958.              Simply   type   the  escape  key.   The   interpreter   will      
  959.              respond  with  "Interrrupted.",  and return to  the  command      
  960.              prompt.
  961.  
  962.         TO LOAD ANOTHER DATABASE:
  963.              Type  "consult(<filename>).<CR>" The file name must have the 
  964.              extension  ".PRO".  It  is  not  necessary  to  include  the 
  965.              extension in the argument of consult. The file name as given 
  966.              must not be the same as a predicate name in the file or  any 
  967.              file which will be loaded.
  968.  
  969.         TO TRACE:
  970.              When the system displays the prompt "?-", type "trace.<CR>".  
  971.              The display will likely move too rapidly for you to read. To 
  972.              stop the display,  type Control S.  To restart the  display, 
  973.              type  Control S.  To turn the trace      display  off,  type 
  974.              "notrace<CR>"  at  the  prompt  "?-".   The  interrupt  menu 
  975.              contains  additional  options,  such  as sending  all  trace 
  976.              output to a file, as well as display at the console.
  977.  
  978.  
  979.  
  980.  
  981.  
  982.  
  983.  
  984.  
  985.  
  986.  
  987.  
  988.  
  989.  
  990.  
  991.  
  992.         TO INTERRUPT A PROGRAM:
  993.              See  the  section  entitled  "The  Interrupt  Menu"  for   a 
  994.              description  of the flexible options.  Basically,  one types 
  995.              ESC  to terminate a program,  while Control V or  Control  I 
  996.              interrupt a program. 
  997.  
  998.         TO RECONSULT A FILE:
  999.              The   predicate  "recon"  is  identical  to  the   Edinburgh 
  1000.              predicate "reconsult."
  1001.  
  1002.         TO REMOVE A DATABASE:
  1003.              Type "forget(<filename>).<CR>"
  1004.  
  1005.         TO EXIT TO THE OPERATING SYSTEM:
  1006.              Type "exitsys.<CR>"
  1007.  
  1008.              The system is totally interactive; any commands the operator 
  1009.         gives  are and must be valid program statements.  Statements must 
  1010.         terminate with a period.      All commands which take a file name 
  1011.         also  accept a path name.  Any name which is not a  valid  PROLOG 
  1012.         atom (refer to C & M) must be enclosed in single quotes. Thus one 
  1013.         could say
  1014.  
  1015.              consult( expert )
  1016.  
  1017.         but one would need single quotes with
  1018.  
  1019.              consult( 'b:\samples\subtype\expert' ).
  1020.  
  1021.  
  1022.         To exit the system, type "exitsys.<CR>"
  1023.  
  1024.         Atoms  may contain MSDOS pathnames if they are enclosed by single 
  1025.         quotes, ie.,  '\b:\samples\animal' .
  1026.  
  1027.         You may consult more than one file at a time.  However, all names 
  1028.         are public and name conflicts must be avoided. The order in which 
  1029.         modules are loaded may,  in cases of poor program design,  affect 
  1030.         the behavior.
  1031.  
  1032.  
  1033.  
  1034.                              Command Line Arguments
  1035.  
  1036.              ED and PD PROLOG accept one command line argument,  which is 
  1037.         the name of a "stream" which replaces the console for input.  The 
  1038.         "stream"  in  MSDOS is a pipe or file which supplies input  until 
  1039.         end-of-file is reached. Control then reverts back to the console. 
  1040.         To avoid noisy parser error messages when end-of-file is reached, 
  1041.         the  last command in the file should be "see( user )." See  Simon 
  1042.         Blackwell's PIE program for an example of this.
  1043.  
  1044.  
  1045.  
  1046.  
  1047.  
  1048.  
  1049.  
  1050.  
  1051.  
  1052.  
  1053.  
  1054.  
  1055.  
  1056.  
  1057.  
  1058.                                A Reference of Note
  1059.  
  1060.  
  1061.              With  minor  exceptions,  the syntax is a superset  of  that 
  1062.         described  by  Clocksin and Mellish in the  book  Programming  in 
  1063.         Prolog by W.F.  Clocksin and C.S.  Mellish, published by Springer 
  1064.         Verlag in Berlin, Heidelberg, New York, and Tokyo. We shall refer 
  1065.         to this book as "C & M".
  1066.  
  1067.  
  1068.              There   are  very  few   syntactical   differences,   mostly 
  1069.         unrecognized and/or minor.
  1070.              When  an operator is declared using the "op" statement,  the 
  1071.         operator must be enclosed in single quotes in the "op"  statement 
  1072.         itself,  if  it would not otherwise be a legal Edinburgh functor. 
  1073.         Subsequently,  however,  the parser will recognize it for what it 
  1074.         is,  except  in  the "unop" statement,  where it  must  again  be 
  1075.         enclosed in single quotes.
  1076.  
  1077.              Variable numbers of functor paramaters are supported.
  1078.  
  1079.              A  goal  may be represented by a  variable,  which  is  less 
  1080.         restrictive  than  the  C  &  M requirement  that  all  goals  be 
  1081.         functors.  The  variable must be instantiated to a  functor  when 
  1082.         that goal is pursued.
  1083.  
  1084.              Rules which appear inside other expressions must be enclosed 
  1085.         in  parenthesis  if  the "," operator is to be  recognized  as  a 
  1086.         logical connective.
  1087.  
  1088.              All  infix  operators described by C & M,  and user  defined 
  1089.         infix,  prefix, and postfix operators with variable associativity 
  1090.         and precedence are supported exactly as in C & M.
  1091.  
  1092.  
  1093.  
  1094.  
  1095.  
  1096.  
  1097.  
  1098.  
  1099.  
  1100.  
  1101.  
  1102.  
  1103.  
  1104.  
  1105.  
  1106.  
  1107.  
  1108.  
  1109.  
  1110.  
  1111.  
  1112.  
  1113.  
  1114.  
  1115.  
  1116.  
  1117.  
  1118.  
  1119.  
  1120.  
  1121.  
  1122.  
  1123.  
  1124.                          The Built In Predicate Library
  1125.  
  1126.                         Available Operators in PD and ED PROLOG
  1127.  
  1128.  
  1129.         Column 1 gives the function symbol. 
  1130.  
  1131.         Column 2 gives the precedence. The range of precedence is 1 to 255.
  1132.         A zero in the precedence column indicates the symbol is parsed as 
  1133.         a functor, and precedence is meaningless in this case.
  1134.  
  1135.         Column 3 gives the associativity. 
  1136.         A zero in the associativity column indicates the symbol is parsed
  1137.         as a functor, and associativity is meaningless in this case.
  1138.  
  1139.         Column 4 indicates which version the function is available in. 
  1140.         Unless otherwise noted, the function is available in all versions.
  1141.         Nonstandard predicates are indicated by "NS".
  1142.  
  1143.  
  1144.         op/pred      precedence    associativity         availability
  1145.  
  1146.         "!"             0             0
  1147.         "|"             0             0
  1148.         "="             40,           XFX                   
  1149.         "=="            40,           XFX                   
  1150.         "\\="           40,           XFX                   
  1151.         "\\=="          40,           XFX       
  1152.         "/"             21,           YFX       
  1153.         "@="            40,           XFX       
  1154.         ">="            40,           XFX       
  1155.         "=<"            40,           XFX       
  1156.         ">"             40,           XFX       
  1157.         "<"             40,           XFX       
  1158.         "-"             31,           YFX        
  1159.         "*"             21,           YFX
  1160.         "+"             31,           YFX
  1161.         "=.."           40,           XFX
  1162.         "-->"           255,          YFY       (not  in  PD PROLOG)
  1163.         "?-"            255,          FY  
  1164.               
  1165.  
  1166.  
  1167.         "arg"           0,            0,                                   
  1168.         "asserta"       0,            0,                                   
  1169.         "assertz"       0,            0,                                   
  1170.         "atom"          0,            0,                                   
  1171.         "atomic"        0,            0,                                   
  1172.         "batch"         0,            0
  1173.         "clause"        0,            0,                                   
  1174.         "clearops"      0,            0,                                   
  1175.         "cls"           0,            0,       NS
  1176.         "concat"        0,            0,                                   
  1177.         "consult"       8,            FX,                                  
  1178.         "crtgmode"      0,            0,       NS
  1179.         "crtset"        0,            0,       NS
  1180.         "curset"        0,            0,       NS
  1181.         "curwh"         0,            0,       NS
  1182.         "debugging      0,            0,                                   
  1183.         "dir"           0,            0,                                   
  1184.  
  1185.  
  1186.  
  1187.  
  1188.  
  1189.  
  1190.         "display"       0,            0,                                   
  1191.         "dotcolor"      0,            0,       NS
  1192.         "drawchar"      0,            0,       NS
  1193.         "drawdot"       0,            0,       NS
  1194.         "drawline"      0,            0,       NS
  1195.         "exec"          0,            0,                                   
  1196.         "exitsys"       0,            0,       NS                          
  1197.         "forget"        0,            0,       NS                          
  1198.         "functor"       0,            0,                                   
  1199.         "get0"          8,            FX,                                  
  1200.         "integer"       0,            0,                                   
  1201.         "is"            40,           XFX,                                 
  1202.         "listing"       0,            0,                                   
  1203.         "memleft"       0,            0,      NS
  1204.         "mod"           11,           XFX,                                 
  1205.         "name"          0,            0,                                   
  1206.         "nl"            0,            0,                                   
  1207.         "nodebug"       0,            0,       (not in PD PROLOG)
  1208.         "nonvar"        0,            0,                                   
  1209.         "nospy"         50,           FX,      (not in PD PROLOG)
  1210.         "not"           60            FX                                   
  1211.         "notrace"       0,            0,       (not in PD PROLOG)
  1212.         "op"            0,            0,                                   
  1213.         "popoff"        0,            0,       NS
  1214.         "popoffd"       0,            0,       NS
  1215.         "popon"         0,            0,       NS
  1216.         "popond"        0,            0,       NS
  1217.         "print"         0,            0,                                   
  1218.         "prtscr"        0,            0,       NS
  1219.         "put"           0,            0,                                   
  1220.         "ratom"         0,            0,                                   
  1221.         "read"          0,            0,                                   
  1222.         "recon"         0,            0, (Note: this is "reconsult")
  1223.         "repeat"        0,            0,                                   
  1224.         "retract"       0,            0                                    
  1225.         "rnum"          0,            0,                                   
  1226.         "see"           0,            0,       
  1227.         "seeing"        0,            0,       
  1228.         "seen"          0,            0,       
  1229.         "skip"          0,            0,       (not in PD PROLOG)
  1230.         "spy"           50,           FX,      
  1231.         "tab"           0,            0,                                   
  1232.         "tell"          0,            0,       
  1233.         "telling"       0,            0,       
  1234.         "told"          0,            0,       
  1235.         "trace"         0,            0,       (not in PD PROLOG)
  1236.         "true"          0,            0,                                   
  1237.         "unop"          0,            0,                                   
  1238.         "var"           0,            0,                                   
  1239.         "write"         0,            0,                                   
  1240.                         Description of the Modifications.
  1241.              
  1242.  
  1243.         I/O Redirection
  1244.  
  1245.         I/O  redirection is a feature described by Clocksin and  Mellish. 
  1246.         The predicates "see",  "seeing",  "seen",  "tell", "telling", and 
  1247.         "told" are used to select the streams used for input and output. 
  1248.  
  1249.              The  predicates  "seen" and "told" require as arguments  the 
  1250.  
  1251.  
  1252.  
  1253.  
  1254.  
  1255.  
  1256.         name of the stream that is to be closed.  This enables the system 
  1257.         to  remember the indices of several streams and switch  back  and 
  1258.         forth between them.
  1259.  
  1260.              The  predicate "batch",  when inserted at the beginning of a 
  1261.         stream file, has the following properties:
  1262.  
  1263.              1)  The normal prompt,  "?-",  and advisory messages do  not 
  1264.              appear at the screen.
  1265.  
  1266.              2)  It is self cancelling if the input stream is  reassigned 
  1267.              to the console.
  1268.  
  1269.              3) It may also be cancelled by the predicate "batch".
  1270.  
  1271.  
  1272.  
  1273.         call( <goal> )
  1274.  
  1275.              The  predicate as defined in C & M is obsolete.  The purpose 
  1276.         was  to permit a goal search where the goal name was  a  variable 
  1277.         instantiated  to  some functor name.  A.D.A.  permits writing  of 
  1278.         goals with such names,  so the mediation of the "call" clause  is 
  1279.         no longer necessary.
  1280.  
  1281.              The  "call"  predicate  may  be  trivially  implemented  for 
  1282.         compatibility with the PROLOG definition
  1283.  
  1284.                                  call( X ) :- X.
  1285.  
  1286.  
  1287.  
  1288.         clause
  1289.  
  1290.              The  function  clause(  X,  Y ) has the  new  optional  form 
  1291.         clause(  X,  Y,  I  ).  If the third variable is written,  it  is 
  1292.         instantiated  to the current address of a clause in  memory.  The 
  1293.         only  use of the result is with succeeding assertfa and  assertfz 
  1294.         statements.
  1295.  
  1296.  
  1297.  
  1298.  
  1299.  
  1300.  
  1301.  
  1302.  
  1303.  
  1304.  
  1305.  
  1306.  
  1307.  
  1308.  
  1309.  
  1310.  
  1311.  
  1312.  
  1313.  
  1314.  
  1315.  
  1316.  
  1317.  
  1318.  
  1319.  
  1320.  
  1321.  
  1322.         debugging
  1323.  
  1324.              "Debugging"  prints a list of the current  spypoints.  After 
  1325.         each name a sequence of numbers may appear, indicating the number 
  1326.         of  arguments that is a condition of the trace.  The  word  "all" 
  1327.         appears  if  the  number of arguments is not a condition  of  the 
  1328.         trace.
  1329.  
  1330.         op( <prec>, <assoc>, <functor> )
  1331.  
  1332.              Defines  the  user  definable  grammar  of  a  functor.  The 
  1333.         definition conforms to that in C & M. We mention here a minor but 
  1334.         important point.  If <functor> is not a valid PROLOG atom it must 
  1335.         be   enclosed  in  single  quotes  when  declared  in  the   "op" 
  1336.         declaration.  It  is  not necessary or legal to do this when  the 
  1337.         functor is actually being used as an operator.  In version 1.6, a 
  1338.         declared  or built-in operator can be used either as an  operator 
  1339.         or as a functor. For example, 
  1340.  
  1341.                                  +(2,3) = 2 + 3.
  1342.  
  1343.         is a true statement.
  1344.  
  1345.              Declared  operators  are annotated in the directory  display 
  1346.         with their precedence and associativity.
  1347.  
  1348.  
  1349.  
  1350.  
  1351.  
  1352.  
  1353.  
  1354.  
  1355.  
  1356.  
  1357.  
  1358.  
  1359.  
  1360.  
  1361.  
  1362.  
  1363.  
  1364.  
  1365.  
  1366.  
  1367.  
  1368.  
  1369.  
  1370.  
  1371.  
  1372.  
  1373.  
  1374.  
  1375.  
  1376.  
  1377.  
  1378.  
  1379.  
  1380.  
  1381.  
  1382.  
  1383.  
  1384.  
  1385.  
  1386.  
  1387.  
  1388.         Output predicates
  1389.  
  1390.            display
  1391.            write
  1392.            print
  1393.            put
  1394.  
  1395.              These  functions  have  been  modified  to  accept  multiple 
  1396.         arguments in the form:
  1397.  
  1398.                        print( <arg1>, <arg2>, <arg3>,... )
  1399.  
  1400.         Thus, "put( a, b, c )" would result in the display of "abc".
  1401.              The  names  of  some  PROLOG atoms that may  occur  are  not 
  1402.         accepted  by  the  PROLOG scanner  unless  surrounded  by  single 
  1403.         quotes.  This only applies when such an atom is read in, not when 
  1404.         it is internally generated. Nevertheless, this presents us with a 
  1405.         problem:  We  would  like to be capable of writing  valid  PROLOG 
  1406.         terms to a file. In some cases, it is necessary to add the single 
  1407.         quotes.  In other cases,  such as human oriented output, they are 
  1408.         an irritant. The modified definitions of the following predicates 
  1409.         are an attempt at a solution:
  1410.  
  1411.              display
  1412.              Operator  precedence  is ignored,  all functors are  printed 
  1413.              prefix and single quotes are printed if needed or they  were 
  1414.              supplied if and when the atom was originally input.
  1415.  
  1416.              write
  1417.              Operator  precedence is taken into account and operators are 
  1418.              printed according to precedence.  Single quotes are  printed 
  1419.              under the same conditions as for "display."
  1420.  
  1421.              print
  1422.              Operator  precedence is taken into account and operators are 
  1423.              printed  according to precedence.  Single quotes  are  never 
  1424.              displayed.  This  is  a  human oriented form of  output  and 
  1425.              should  never  be used for writing of terms for  the  PROLOG 
  1426.              scanner.
  1427.  
  1428.  
  1429.  
  1430.  
  1431.  
  1432.  
  1433.  
  1434.  
  1435.  
  1436.  
  1437.  
  1438.  
  1439.  
  1440.  
  1441.  
  1442.  
  1443.  
  1444.  
  1445.  
  1446.  
  1447.  
  1448.  
  1449.  
  1450.  
  1451.  
  1452.  
  1453.  
  1454.         get0
  1455.         read
  1456.  
  1457.              The  functions  "get0"  and "read"  have  been  extended  to 
  1458.         support input from a stream other than the one currently selected 
  1459.         by "see". To direct output to a file or other stream, an optional 
  1460.         argument  is used.  For example,  "get0( char,  <file name> )" or 
  1461.         "get0( char,  user )" would cause input to come from <file  name> 
  1462.         or the console.  If the file has not already been opened,  "get0" 
  1463.         will fail.
  1464.  
  1465.  
  1466.  
  1467.              Atoms enclosed by single quotest, eg. '\nthis is a new line' 
  1468.         can contain the escape sequences
  1469.  
  1470.              '\n', '\r', '\t' and '\''.
  1471.  
  1472.              If these atoms are printed by "display" or "write" they  are 
  1473.         printed  just  as they are.  If they are printed by  the  "print" 
  1474.         clause they are translated as follows:
  1475.  
  1476.         '\n'  results  in  the printing of a carriage return and  a  line 
  1477.         feed.
  1478.         '\r' results in the printing of a carriage return only.
  1479.         '\t' results in the printing of a tab character.
  1480.         '\'' allows the printing of a single quote within a quoted atom.
  1481.  
  1482.              The "portray" feature is not presently implemented.
  1483.  
  1484.  
  1485.  
  1486.  
  1487.  
  1488.  
  1489.  
  1490.  
  1491.  
  1492.  
  1493.  
  1494.  
  1495.  
  1496.  
  1497.  
  1498.  
  1499.  
  1500.  
  1501.  
  1502.  
  1503.  
  1504.  
  1505.  
  1506.  
  1507.  
  1508.  
  1509.  
  1510.  
  1511.  
  1512.  
  1513.  
  1514.  
  1515.  
  1516.  
  1517.  
  1518.  
  1519.  
  1520.                         Description of the New Predicates
  1521.  
  1522.  
  1523.         clearops-
  1524.  
  1525.              Nullify  the  operator  status  of  every  operator  in  the 
  1526.              database.
  1527.  
  1528.         concat( (<variable> | <functor>), <List> )
  1529.  
  1530.              A  list  of functors or operators is concatenated  into  one 
  1531.         string,  which becomes the name of a new atom to which <variable> 
  1532.         or <functor> must match or be instantiated.
  1533.  
  1534.  
  1535.         dir( option )
  1536.  
  1537.              Provide  an  alphabetized listing to the console  of  atoms, 
  1538.         constants,   or   open  files.   Without  options,   simply  type 
  1539.         "dir.<CR>". Options are:
  1540.  
  1541.              dir( p ) - list clause names only.
  1542.              dir( c ) - list consulted files only.
  1543.  
  1544.         Consulted files are prefixed by "S:".
  1545.  
  1546.  
  1547.         exitsys
  1548.  
  1549.              Exit to the operating system.
  1550.  
  1551.  
  1552.  
  1553.         forget( <file name> )
  1554.              Make  a database unavailable for use and reclaim the storage 
  1555.         it occupied.
  1556.  
  1557.  
  1558.  
  1559.         ratom( <arg>, <stream> )-
  1560.              Read an atom from the input stream,  to which <arg>  matches 
  1561.         or  is  instantiated.  <stream> is optional.  If <stream> is  not 
  1562.         given, the input stream defaults to the standar input.
  1563.              Input is terminated by a CR or LF, which are not included in 
  1564.         the stream.
  1565.  
  1566.  
  1567.  
  1568.  
  1569.  
  1570.  
  1571.  
  1572.  
  1573.  
  1574.  
  1575.  
  1576.  
  1577.  
  1578.  
  1579.  
  1580.  
  1581.  
  1582.  
  1583.  
  1584.  
  1585.  
  1586.                              Arithmetic Capabilities
  1587.  
  1588.              Integer  arithmetic is supported.  Numbers are 32 bit signed 
  1589.         quantities. The following arithmetic operators are supported:
  1590.  
  1591.                       "+", "-", "*", "/", <, <=, >, >=, mod.
  1592.  
  1593.         Arithmetic operators must never be used as goals,  although  they 
  1594.         may be part of structures. It is legal to write:
  1595.  
  1596.                                     X = a + b
  1597.              
  1598.         which  results in the instantiation of X to the struture (a + b). 
  1599.         But the following is not legal:
  1600.  
  1601.                        alpha( X, Y ) :- X + Y, beta( Y ).
  1602.  
  1603.  
  1604.         Evaluation  of  an arithemtic expression is mediated by the  "is" 
  1605.         and inequality predicates.  For instance,  the following would be 
  1606.         correct:
  1607.  
  1608.                          alpha( X, Y, Z ) :- Z is X + Y.
  1609.  
  1610.                          beta( X, Y ) :- X + 2 < Y + 3.
  1611.  
  1612.  
  1613.  
  1614.  
  1615.  
  1616.  
  1617.  
  1618.  
  1619.  
  1620.  
  1621.  
  1622.  
  1623.  
  1624.  
  1625.  
  1626.  
  1627.  
  1628.  
  1629.  
  1630.  
  1631.  
  1632.  
  1633.  
  1634.  
  1635.  
  1636.  
  1637.  
  1638.  
  1639.  
  1640.  
  1641.  
  1642.  
  1643.  
  1644.  
  1645.  
  1646.  
  1647.  
  1648.  
  1649.  
  1650.  
  1651.  
  1652.                             Memory Metric Predicate
  1653.  
  1654.              The purpose of this predicate is to give the prolog system 
  1655.         a  sense  of  how much memory remains so  that  expensive  search 
  1656.         strategies  can  be  controlled.  It is not possible  to  exactly 
  1657.         quantify how much memory remains.  At the lowest level, there are 
  1658.         two  types of memory - the stack and the heap.  The stack expands 
  1659.         down  from  high  memory,  while  the heap  tends  to  expand  at 
  1660.         unpredictable intervals upwards.  If the stack and heap meet, the 
  1661.         prolog  system  must abort the search and return to  the  prompt. 
  1662.         Judicious  use  of  the  memory  metric  predicates  reduces  the 
  1663.         probability of this happening.
  1664.  
  1665.              The  stack is easy to quantify because it expands  downwards 
  1666.         in  a  predictable  way with recursion.  The symbol  space  is  a 
  1667.         "heap".  For  those  interested,  the structure of  the  heap  is 
  1668.         determined  by  the C compiler under which Prolog  was  compiled. 
  1669.         There  is  a function internal to Prolog known as  the  allocator 
  1670.         searches  the  heap for enough contiguous memory to create a  new 
  1671.         symbol.  The  heap resembles a piece of Swiss cheese;  the  holes 
  1672.         represent symbols and already allocated memory while the remained 
  1673.         is  searched  by the allocator for a piece of  contiguous  memory 
  1674.         large enough to satisfy a request.  If one cannot be  found,  the 
  1675.         uppermost  bound of the heap is expanded upwards,  and that bound 
  1676.         is  the  number  which we measure for an  estimate  of  remaining 
  1677.         memory.
  1678.  
  1679.              The  sqace between the top of the heap,  and  the top of the 
  1680.         stack,  which we call "gap",  serves as a rough guide to how much 
  1681.         memory  remains.  The  demands  of the system  are  not  entirely 
  1682.         predictable,  however.  For example, the creation of a new symbol 
  1683.         larger  than "gap" would cause an abort.  The user must  use  the 
  1684.         numbers  supplied  by  these  functions  as  a  heuristic  guide, 
  1685.         tempered  by  experience,  to  minimize  the  possibility  of  an 
  1686.         unexpected abort.
  1687.  
  1688.         "Gap" is measured in 256 byte pages.
  1689.  
  1690.         memleft( X )
  1691.  
  1692.         If  the argument is an integer,  this is satisfied if the size of 
  1693.         "gap" is greater than "X".
  1694.  
  1695.         If the argument is a variable,  it is instantiated to the  amount 
  1696.         of "gap" remaining.
  1697.  
  1698.  
  1699.  
  1700.  
  1701.  
  1702.  
  1703.  
  1704.  
  1705.  
  1706.  
  1707.  
  1708.  
  1709.  
  1710.  
  1711.  
  1712.  
  1713.  
  1714.  
  1715.  
  1716.  
  1717.  
  1718.                          IBM PC Video Display Predicates
  1719.  
  1720.  
  1721.         A high level method is provided for drawing and displaying on the 
  1722.         screen of IBM PC and compatible computers. 
  1723.  
  1724.  
  1725.  
  1726.         cls
  1727.  
  1728.         Clear  the screen and position the cursor at the upper left  hand 
  1729.         corner.
  1730.  
  1731.  
  1732.  
  1733.         crtgmode( X )
  1734.  
  1735.         Matches  the  argument to the mode byte of the display  which  is 
  1736.         defined as follows:
  1737.  
  1738.                   mode           meaning
  1739.  
  1740.                    0             40 x  25  BW (default)
  1741.                    1             40 x  25  COLOR
  1742.                    2             80 x  25  BW
  1743.                    3             80 x  25  COLOR
  1744.                    4            320 x 200  COLOR
  1745.                    5            320 x 200  BW
  1746.                    6            640 x 200  BW
  1747.                    7             80 x  25  monochrome  display card
  1748.  
  1749.  
  1750.  
  1751.         crtset( X )
  1752.          
  1753.         This  sets the mode of the display.  The argument must be one  of 
  1754.         the modes given above. 
  1755.  
  1756.  
  1757.  
  1758.         curset( <row>, <column>, <page> )
  1759.  
  1760.         Sets the cursor to the given row, column, and page. The arguments 
  1761.         must be integers.
  1762.  
  1763.  
  1764.  
  1765.         curwh(  <row>, <column> )
  1766.  
  1767.         Reports the current position of the cursor.  The argument must be 
  1768.         an integer or variable. The format is:
  1769.  
  1770.              1) page zero is assumed.
  1771.              2) The row is in the range 0 to 79, left to right.
  1772.              3) The column is in the range 0 to 24, bottom to top.
  1773.         dotcolor( <row>, <column>, <color> )
  1774.  
  1775.         The  argument  <color> is matched to the color of  the  specified 
  1776.         dot. The monitor must be in graphics mode.
  1777.  
  1778.  
  1779.  
  1780.  
  1781.  
  1782.  
  1783.  
  1784.  
  1785.  
  1786.         drawchar( <character>, <attribute> )
  1787.  
  1788.         Put a character at the current cursor position with the specified 
  1789.         attribute.  The  arguments  <character> and <attribute>  must  be 
  1790.         integers.  Consult  the IBM technical reference manual  regarding 
  1791.         attributes.
  1792.  
  1793.  
  1794.  
  1795.         drawdot( <row>, <column>, <color> )
  1796.  
  1797.         Put  a dot at the specified position.  The monitor must be in the 
  1798.         graphics  mode.  The  arguments  must be  integer.  The  argument 
  1799.         <color> is mapped to integers by default in the following manner:
  1800.  
  1801.  
  1802.  
  1803.         drawline( <X1>, <Y1>, <X2>, <Y2>, <color> )
  1804.  
  1805.         Draw a line on the between the coordinate pairs. The monitor must 
  1806.         be in the graphics mode and the arguments are integer.
  1807.  
  1808.  
  1809.  
  1810.         prtscr
  1811.  
  1812.         Print  the  screen  as it currently appears.  Be  sure  that  the 
  1813.         printer  is  on  line and ready before invoking  this  predicate, 
  1814.         since otherwise, the system may lock up or abort.
  1815.  
  1816.  
  1817.  
  1818.         The  integer argument <color> referred to in the above predicates 
  1819.         is represented as follows:
  1820.  
  1821.              COLOR          PALETTE 0           PALETTE 1
  1822.              
  1823.                0            background          background
  1824.                1            green               cyan
  1825.                2            red                 magenta
  1826.                3            brown               white
  1827.  
  1828.         To change the palette and the background,  see the IBM  Technical 
  1829.         Reference Bios listings for more information.
  1830.  
  1831.  
  1832.  
  1833.  
  1834.  
  1835.  
  1836.  
  1837.  
  1838.  
  1839.  
  1840.  
  1841.  
  1842.  
  1843.  
  1844.  
  1845.  
  1846.  
  1847.  
  1848.  
  1849.  
  1850.                                    Trace Files
  1851.  
  1852.                                  (type ED only)
  1853.  
  1854.              You  can  now dump your trace to disk,  instead  of  (groan) 
  1855.         wasting  reams of printer paper.  This option is described in the 
  1856.         next section.
  1857.  
  1858.  
  1859.                                The Interrupt Menu
  1860.  
  1861.                                  (type ED only)
  1862.  
  1863.              This  menu  has been modified.  It was formerly  called  the 
  1864.         ESCAPE   menu,  but  the  meaning  of the  ESCAPE  key  has  been 
  1865.         redefined.  It  is  no  longer necessary to display the  menu  to 
  1866.         perform  one of the menu functions.  This reduces the  amount  of 
  1867.         display which is lost by scrolling off the screen.
  1868.  
  1869.              Version  1.9 offers the ability to attempt a goal  from  the 
  1870.         interrupt menu, while not disturbing the ongoing computation.
  1871.  
  1872.              At any time while searching, printing, or accepting keyboard 
  1873.         input,  you can break to this menu.  It is generally not possible 
  1874.         to  do  this  during disk access,  since control  passes  to  the 
  1875.         operating  system  at this time.  Two keys cause  this  break  to 
  1876.         occur:
  1877.  
  1878.              ^V:  The menu is displayed and a command is accepted at the 
  1879.                   prompt  "INTERRUPT>".  After  a command,  the  menu  is 
  1880.                   redisplayed  until  the user selects  a  command  which 
  1881.                   causes an exit. 
  1882.  
  1883.              ^I:  The menu is not displayed.  Command is accepted at the 
  1884.                   prompt  "INTERRUPT>" until the user selects  a  command 
  1885.                   which causes an exit.
  1886.  
  1887.              ESC: Typing this key  causes a  termination of  the  PROLOG      
  1888.                   search  and  control returns to the user command  level      
  1889.                   with a prompt of "?-".  Notice that previously, the ESC      
  1890.                   key invoked this menu. 
  1891.  
  1892.  
  1893.  
  1894.  
  1895.  
  1896.  
  1897.  
  1898.  
  1899.  
  1900.  
  1901.  
  1902.  
  1903.  
  1904.  
  1905.  
  1906.  
  1907.  
  1908.  
  1909.  
  1910.  
  1911.  
  1912.  
  1913.  
  1914.  
  1915.  
  1916.              As the resulting menu indicates, the following functions are 
  1917.         possible:
  1918.  
  1919.              A: Abort the search and return to the prompt.
  1920.  
  1921.              O  Open  a trace file.  The user is prompted for  the  file 
  1922.                 name.  The file receives all trace output.  If a file is 
  1923.                 already opened it is closed with all output preserved.
  1924.  
  1925.              C  Close the trace file if one is open.  Otherwise there is 
  1926.                 no effect.
  1927.  
  1928.             ^C: Immediately  exit PROLOG without closing files.  This is 
  1929.                 not advised.
  1930.  
  1931.             ^P: Typing <Control>P toggles the printer. If the printer is 
  1932.                 on,  all  input  and output will also be  routed  to  the 
  1933.                 printer.
  1934.  
  1935.              S: If  the machine in use is an IBM PC compatible  machine, 
  1936.                 the  currently displayed screen will be printed.  If  the 
  1937.                 machine  is  not an IBM PC compatible,  do not  use  this 
  1938.                 function.
  1939.  
  1940.              T: If  trace  is in use,  most of the trace output  can  be 
  1941.                 temporarily turned off by use of this function,  which is 
  1942.                 a toggle.
  1943.  
  1944.              G: Satisfy a goal.  The system prompt will appear. Do not be         
  1945.                 confused  into  thinking that the system has reverted  to 
  1946.                 the  prompt.  After the user has entered the goal in  the 
  1947.                 usual  manner,  satisfaction  of the goal is  immediately 
  1948.                 attempted.  This need not affect the running  computation 
  1949.                 in  any way,  although it is certainly possible to do so. 
  1950.                 After  the  goal is attempted,  control  returns  to  the 
  1951.                 INTERRUPT  menu.  The  purpose is to facilitate  detailed 
  1952.                 analysis of a running system.
  1953.  
  1954.              R:  Entering  another  ESC causes a return to the  current 
  1955.                 activity  (keyboard  input or search)  with  no  residual 
  1956.                 effect from the interruption.
  1957.  
  1958.  
  1959.  
  1960.  
  1961.  
  1962.  
  1963.  
  1964.  
  1965.  
  1966.  
  1967.  
  1968.  
  1969.  
  1970.  
  1971.  
  1972.  
  1973.  
  1974.  
  1975.  
  1976.  
  1977.  
  1978.  
  1979.  
  1980.  
  1981.  
  1982.  
  1983.                              Conserving memory space
  1984.  
  1985.  
  1986.                Success popping is controlled by the predicates "popond",
  1987.         "popoffd",  "popon",  and  "popoff".  Success popping is means of 
  1988.         reclaiming  storage which is used on backtracking to  reconstruct 
  1989.         how a particular goal was satisfied.  If it is obvious that there 
  1990.         is no alternative solution to a goal this PROLOG system is  smart 
  1991.         enough to reclaim that storage. 
  1992.  
  1993.              In  this system,  succees popping is an expensive operation. 
  1994.         Therefore,  there  is a tradeoff of memory versus  time.  On  the 
  1995.         other hand, discrete use of success popping can actually speed up 
  1996.         a program by recreating structures in a more accessible form.
  1997.  
  1998.              The  definitions of the control predicates is given in  this 
  1999.         manual  and  their use is totally  optional.  The  modulation  of 
  2000.         success popping has no effect on program logic (read solution.)
  2001.              
  2002.              The  "cut"  can  save  substantial  time  and  computational 
  2003.         overhead  as well as storage.  Although the execution of the  cut 
  2004.         costs  time,  you can design your program to use cuts in critical 
  2005.         places  to  avoid unnecessary backtracking.  Thus  the  execution 
  2006.         speed of the program can actually increase. 
  2007.              
  2008.              Anyone  who  has  read Clocksin and  Mellish  is  aware,  of 
  2009.         course, that the "cut" has a powerful logical impact which is not 
  2010.         always desirable.
  2011.  
  2012.  
  2013.         popoff 
  2014.  
  2015.         See the below definition.
  2016.  
  2017.  
  2018.  
  2019.         popon
  2020.  
  2021.         The  inference  engine  does complete success popping  for  goals 
  2022.         which appear after "popon".  Consider this example: 
  2023.  
  2024.           goal :-  a, popon, b, c, popoff, d.
  2025.  
  2026.         If  no alternative solutions exist for b,  then  success  popping 
  2027.         will  reclaim storage by removing unnecessary records  describing 
  2028.         how  "b"  was  satisfied.  If the Prolog system cannot  rule  out 
  2029.         possible additional solutions,  success popping will never occur, 
  2030.         regardless of your use of "popon". 
  2031.              Since goal "d" occurs after "popoff",  success popping  will 
  2032.         never occur.
  2033.  
  2034.  
  2035.  
  2036.  
  2037.  
  2038.  
  2039.  
  2040.  
  2041.  
  2042.  
  2043.  
  2044.  
  2045.  
  2046.  
  2047.  
  2048.         popoffd
  2049.  
  2050.         If  no  "popon" or "popoff" declarations occur in a  clause,  the 
  2051.         default  action  is  determined by  "popoffd"  and  "popond".  If 
  2052.         "popoffd" has been invoked,  the default is that success  popping 
  2053.         will not occur.
  2054.  
  2055.  
  2056.  
  2057.         popond
  2058.  
  2059.         The inverse of "popoffd". Turns on default success popping.
  2060.         printf( <stream>, <term1>,<term2>,... )
  2061.  
  2062.  
  2063.  
  2064.  
  2065.  
  2066.  
  2067.  
  2068.  
  2069.  
  2070.  
  2071.  
  2072.  
  2073.  
  2074.  
  2075.  
  2076.  
  2077.  
  2078.  
  2079.  
  2080.  
  2081.  
  2082.  
  2083.  
  2084.  
  2085.  
  2086.  
  2087.  
  2088.  
  2089.  
  2090.  
  2091.  
  2092.  
  2093.  
  2094.  
  2095.  
  2096.  
  2097.  
  2098.  
  2099.  
  2100.  
  2101.  
  2102.  
  2103.  
  2104.  
  2105.  
  2106.  
  2107.  
  2108.  
  2109.  
  2110.  
  2111.  
  2112.  
  2113.  
  2114.                                  Prolog Tutorial          
  2115.  
  2116.  
  2117.                                   Introduction
  2118.  
  2119.  
  2120.  
  2121.  
  2122.              Probably  you  have heard of the language PROLOG within  the 
  2123.         last year or so. You probably wondered the following things:
  2124.  
  2125.         1) What does the name stand for? Names of computer languages are 
  2126.         almost always acronyms.
  2127.  
  2128.         2) What is it good for?
  2129.  
  2130.         3) Why now?
  2131.  
  2132.         4) Can I get a copy to play with?
  2133.  
  2134.              Congratulations! You obviously know the answer to the fourth 
  2135.         question. We now respond to the other three.
  2136.              
  2137.         1)  The  name  stands for "programming in logic." This  we  shall 
  2138.         elaborate on in depth later on.
  2139.  
  2140.         2) PROLOG is good for writing question answering systems.  It  is 
  2141.         also   good   for  writing  programs  that  perform   complicated 
  2142.         strategies  that  compute the best or worst way to  accomplish  a 
  2143.         task, or avoid an undesirable result.
  2144.  
  2145.         3) PROLOG was virtually unknown in this country until researchers 
  2146.         in  Japan announced that it was to be the core language  of  that 
  2147.         country's fifth generation computer project.  This is the project 
  2148.         with  which  Japan hopes to achieve a domainant position  in  the 
  2149.         world information industry of the 1990's. 
  2150.  
  2151.              PROLOG  is  one of the most unusual computer languages  ever 
  2152.         invented.  It  cannot be compared to  FORTRAN,  PASCAL,  "C",  or 
  2153.         BASIC.  The facilities complement,  rather than replace those  of 
  2154.         conventional  languages.  Although  it  has great  potential  for 
  2155.         database  work,  it  has  nothing in  common  with  the  database 
  2156.         languages used on microcomputers.
  2157.  
  2158.              Perhaps  the  best point to make is that while  conventional 
  2159.         languages are prescriptive, PROLOG is descriptive. A statement in 
  2160.         a conventional language might read:
  2161.  
  2162.              if( car_wheels = TRUE ) then
  2163.                begin
  2164.                  (some sort of procedure)
  2165.                  X = X + 1;
  2166.                end 
  2167.  
  2168.  
  2169.  
  2170.  
  2171.  
  2172.  
  2173.  
  2174.  
  2175.  
  2176.  
  2177.  
  2178.  
  2179.  
  2180.         A statment in PROLOG could just be a statment of fact about  cars 
  2181.         and wheels. There are many relationships that hold. For instance,
  2182.  
  2183.              has( car, wheels ).
  2184.  
  2185.              has( car, quant(wheels, four) ).
  2186.  
  2187.              round( wheels ).
  2188.  
  2189.         Each  of  these statments is an independent fact  relating  cars, 
  2190.         wheels,  and  the  characteristics of wheels.  Because  they  are 
  2191.         independent, they can be put into a PROLOG program by programmers 
  2192.         working separately. The man who is a specialist on car bodies can 
  2193.         say  his thing,  the wheel specialist can have his say,  and  the 
  2194.         participants can work with relative independence. And this brings 
  2195.         to light a major advantage of PROLOG:
  2196.  
  2197.  
  2198.                              PARALLEL PROGRAMMING!!!
  2199.                             
  2200.  
  2201.         With  conventional  programming languages projects can  still  be 
  2202.         "chunked",  or  divided between programmers.  But efficiency on a 
  2203.         team  project  drops  drastically below that  of  the  individual 
  2204.         programmer  wrapped  up  in  his own trance.  As  the  number  of 
  2205.         participants    grows   the   need   for   communication    grows 
  2206.         geometrically. The time spent communicating can exceed that spent 
  2207.         programming! 
  2208.              Although   PROLOG   does   not  eliminate   the   need   for 
  2209.         task  coordination,  the problem is considerably  simplified.  It 
  2210.         also provides the ability to answer questions in a "ready to  eat 
  2211.         form."  Consider your favorite BASIC interpreter.  Based upon the 
  2212.         statements about cars and wheels previously given,  could you ask 
  2213.         it the following question?   
  2214.  
  2215.                        
  2216.               has( car, X ), round( X ).
  2217.  
  2218.              Does  a  car  have anything which  is  round?  The  question 
  2219.         instructs the PROLOG interpreter to consider all the objects that 
  2220.         it  knows are possessed by a car and find those which are  round. 
  2221.         Perhaps  you are beginning to guess that PROLOG has the abilities 
  2222.         of a smart database searcher.  It can not only find the facts but 
  2223.         selectively find them and interpret them.
  2224.  
  2225.  
  2226.  
  2227.  
  2228.  
  2229.  
  2230.  
  2231.  
  2232.  
  2233.  
  2234.  
  2235.  
  2236.  
  2237.  
  2238.  
  2239.  
  2240.  
  2241.  
  2242.  
  2243.  
  2244.  
  2245.  
  2246.              Consider the problem of a fault tree, as exemplified by this 
  2247.         abbreviated one:
  2248.  
  2249.  
  2250.  
  2251.         {Car won't start}
  2252.              | 
  2253.              | 
  2254.         [Engine  turns  over](No) --> [Battery voltage](no)-\
  2255.                 (Yes)                                       v
  2256.                  |                                  {Check battery}
  2257.                  |
  2258.         [Smell gasoline](yes) --> {Try full throttle cranking}
  2259.                  |                       (failure)
  2260.         /--------/                           |
  2261.  
  2262.                             (details omitted)
  2263.  
  2264.  
  2265.  
  2266.              The fault tree is easily programmed in BASIC. Later we shall 
  2267.         show  that  PROLOG supplies a superior replacement for the  fault 
  2268.         tree.  Though the tree is capable of diagnosing only the  problem 
  2269.         for  which  it was designed,  PROLOG dynamically  constructs  the 
  2270.         appropriate  tree from facts and rules you have provided.  PROLOG 
  2271.         is not limited to answering one specific question.  Given  enough 
  2272.         information,  it  will attempt to find all deductive solutions to 
  2273.         any problem.
  2274.  
  2275.  
  2276.  
  2277.  
  2278.  
  2279.  
  2280.  
  2281.  
  2282.  
  2283.  
  2284.  
  2285.  
  2286.  
  2287.  
  2288.  
  2289.  
  2290.  
  2291.  
  2292.  
  2293.  
  2294.  
  2295.  
  2296.  
  2297.  
  2298.  
  2299.  
  2300.  
  2301.  
  2302.  
  2303.  
  2304.  
  2305.  
  2306.  
  2307.  
  2308.  
  2309.  
  2310.  
  2311.  
  2312.  
  2313.                                   PROLOG PRIMER
  2314.  
  2315.         I.                       Rules and Facts     
  2316.  
  2317.  
  2318.  
  2319.              This  is  where you should start if you know  nothing  about 
  2320.         PROLOG. Let us consider a simple statment in PROLOG, such as:
  2321.  
  2322.         1)   has( car, wheels ).
  2323.  
  2324.         This  statement  is a "fact.  The word "has" in this statment  is 
  2325.         known  either  as a functor or predicate.  It is a name  for  the 
  2326.         relationship  within the parenthesis.  It implies that a car  has 
  2327.         wheels.  But  the  order  of  the words  inside  the  bracket  is 
  2328.         arbitrary and established by you. You could just as easily say:
  2329.  
  2330.         2)   has( wheels, car ).
  2331.  
  2332.         and if you wrote this way consistently,  all would be  well.  The 
  2333.         words  has,  wheels,  and car are all PROLOG atoms.  "Wheels" and 
  2334.         "car" are constants. 
  2335.              
  2336.         A   database   of  facts  can  illustrate  the   data   retrieval 
  2337.         capabilities of PROLOG. For instance:
  2338.  
  2339.         3)   has( car, wheels ).
  2340.              has( car, frame ).
  2341.              has( car, windshield ).
  2342.              has( car, engine ).
  2343.  
  2344.         You could then ask PROLOG the question:
  2345.  
  2346.         4)   has( car, Part ).
  2347.  
  2348.         The  capital  "P" of Part means that Part is a  variable.  PROLOG 
  2349.         will make Part equal to whatever constant is required to make the 
  2350.         question match one of the facts in the database. Thus PROLOG will 
  2351.         respond:
  2352.  
  2353.              Part = wheels.
  2354.              
  2355.              More?(Y/N):
  2356.  
  2357.         If you type "y" the next answer will appear:
  2358.  
  2359.              Part = frame.
  2360.  
  2361.              More?(Y/N):
  2362.  
  2363.         If you continue, PROLOG will produce the answers Part = windshield 
  2364.         and Part = engine. Finally, you will see:
  2365.  
  2366.              More?(Y/N):y
  2367.  
  2368.              No.
  2369.          
  2370.         indicating that PROLOG has exhausted the database.  Incidentally, 
  2371.         when  a  variable is set equal to a constant or  other  variable, 
  2372.  
  2373.  
  2374.  
  2375.  
  2376.  
  2377.  
  2378.         it is said to be instantiated to that object.
  2379.  
  2380.              Notice  that  PROLOG searches the database forwards  and  in 
  2381.         this case,  from the beginning.  The forward search path is built 
  2382.         into PROLOG and cannot be changed. An author of a program written 
  2383.         in  a  prescriptive language is quite conscious of the  order  of 
  2384.         execution  of  his program,  while in PROLOG it is  not  directly 
  2385.         under his control.
  2386.              
  2387.              The other major element is the rule which is a fact which is 
  2388.         conditionally true. In logic this is called a Horn clause: 
  2389.  
  2390.  
  2391.         5)   has( X, wheels ) :- iscar( X ).
  2392.  
  2393.         The  fact iscar( car ) and the above rule are equivalent to
  2394.  
  2395.         6)   has( car, wheels).
  2396.  
  2397.         The  symbol :- is the "rule sign." The expression on the left  of 
  2398.         :-is the "head" and on the right is the body.  The variable X has 
  2399.         scope  of the rule,  which means that it has meaning only  within 
  2400.         the rule.  For instance,  we could have two rules in the database 
  2401.         using identically named variables.
  2402.  
  2403.  
  2404.         7)   has( X,  transportation ) :- 
  2405.                            has( X,  car ), has( license, X ).
  2406.  
  2407.         8)   has( X, elephant ) :- istrainer( X ), hasjob( X ).
  2408.  
  2409.         The  variables  X in the two expressions are completely  distinct 
  2410.         and have nothing to do with each other.
  2411.  
  2412.         The comma between has( X, car ) and has( license, X ) means "and" 
  2413.         or logical conjuction.  The rule will not be true unless both the 
  2414.         clauses has(X, car) and has( license, X ) are true.
  2415.  
  2416.  
  2417.              On the other hand if there is a rule
  2418.              
  2419.         9)   has( license, X ) :- passedexam( X ).
  2420.  
  2421.         consider what PROLOG will do in response to the question:
  2422.  
  2423.         10)  has( harry, transportation ).
  2424.  
  2425.         (Notice  that  harry has not been capitalized because we  do  not 
  2426.         want  it  taken as a variable.  We could,  however,  say  'Harry' 
  2427.         enclosed in single quotes.)
  2428.  
  2429.              It  will scan the database and use (7),  in which X will  be 
  2430.         instantiated to harry. The rule generates two new questions:
  2431.  
  2432.         11)  has( harry, car ).
  2433.  
  2434.         12)  has( license, harry ).
  2435.  
  2436.         Assuming  that  harry  has  a car,  the first clause  of  (7)  is 
  2437.         satisfied and the database is scanned for a match to (12). PROLOG 
  2438.  
  2439.  
  2440.  
  2441.  
  2442.  
  2443.  
  2444.         picks  up  rule (9) in which X is instantiated to harry  and  the 
  2445.         question is now posed:
  2446.  
  2447.         13)  passedexam( harry ).
  2448.  
  2449.              If there is a fact:
  2450.  
  2451.              passedexam( harry ).
  2452.  
  2453.         in  the database then all is well and harry  has  transportation. 
  2454.         If there is not, then PROLOG will succinctly tell you:
  2455.  
  2456.              No.
  2457.  
  2458.         But  suppose Harry has money and can hire a chauffer as any  good 
  2459.         programmer  can.  That  could be made part of the program in  the 
  2460.         following way.
  2461.  
  2462.              The rule which PROLOG tried to use was:
  2463.  
  2464.         14)  has( X,  transportation ) :- 
  2465.                            has( X,  car ), has( license, X ).
  2466.  
  2467.         At any point following it there could be included another rule:
  2468.  
  2469.         15)  has( X, transportation ) :- has( X, money ).
  2470.  
  2471.         or simply the bald fact:
  2472.  
  2473.         16)  has( harry, transportation ).
  2474.  
  2475.              These  additional  rules  or  facts would  be  used  in  two 
  2476.         circumstances.  If at any point a rule does not yield a solution, 
  2477.         PROLOG   will  scan  forward  from  that  rule  to  find  another 
  2478.         applicable  one.  This process is known as "backtracking  search" 
  2479.         and can be quite time consuming.
  2480.  
  2481.  
  2482.         If  in response to the "More?" prompt you answer "y" PROLOG  will 
  2483.         search  for an additional distinct solution.  It will attempt  to 
  2484.         find an alternate rule or fact for the last rule or fact used. If 
  2485.         that  fails,  it  will back up to the antecedent rule and try  to 
  2486.         find  an alternate antecedent.  And it will continue to  back  up 
  2487.         until  it  arrives at the question you asked,  at which point  it 
  2488.         will say:
  2489.  
  2490.              No.
  2491.  
  2492.         "Antecedent"  to a rule means that it gave rise to its' use.  For 
  2493.         example,  (7)  is  the antecedent of (9) in the  context  of  the 
  2494.         question (16).
  2495.  
  2496.  
  2497.  
  2498.  
  2499.         II.                          Grammar
  2500.  
  2501.              It is a boring subject, but it must be discussed. All PROLOG 
  2502.         statements are composed of valid terms, possibly a rule sign (":-
  2503.         "),  commas representing conjunction ("and"), and a period at the 
  2504.  
  2505.  
  2506.  
  2507.  
  2508.  
  2509.  
  2510.         very end.
  2511.              A term is a structure, constant, variable, or number.
  2512.          
  2513.              What is a structure? It is a kind of grouping:
  2514.  
  2515.              1) Structures consist of a functor, and a set of objects or
  2516.                 structures in parenthesis.
  2517.  
  2518.              2)  Objects are constants,  variables,  numbers,  or  lists, 
  2519.                 which we have not discussed yet.
  2520.  
  2521.              3)  A  constant or functor must be a string of  letters  and 
  2522.                 numbers, beginning with a lower case letter, unless
  2523.                 you  choose  to  enclose  it in single  quotes  (  'howdy 
  2524.                 pardner'  ),  in  which  case you are  freed  from  these 
  2525.                 restrictions.
  2526.              4) A  variable  must be a string of  letters  and  numbers 
  2527.                 beginning with a capital letter.
  2528.              
  2529.              5) A  functor  may optionally have  arguments  enclosed  in 
  2530.                 parenthesis , as in: hascar( X ) or hascar. 
  2531.  
  2532.         An example:  "has( X, transportation )." is a structure.
  2533.  
  2534.  
  2535.  
  2536.  
  2537.  
  2538.  
  2539.  
  2540.  
  2541.  
  2542.  
  2543.  
  2544.  
  2545.  
  2546.  
  2547.  
  2548.  
  2549.  
  2550.  
  2551.  
  2552.  
  2553.  
  2554.  
  2555.  
  2556.  
  2557.  
  2558.  
  2559.  
  2560.  
  2561.  
  2562.  
  2563.  
  2564.  
  2565.  
  2566.  
  2567.  
  2568.  
  2569.  
  2570.  
  2571.  
  2572.  
  2573.  
  2574.  
  2575.  
  2576.         III.                     Input / Output      
  2577.  
  2578.              You   now   know  enough  to  write  simple  databases   and 
  2579.         interrogate   them  profitably.   But  before  we  examine   more 
  2580.         sophisticated  examples,  it  will be necessary to add input  and 
  2581.         output to the language. There are built in functions which appear 
  2582.         as rules which are satisfied once. Thus the statment:
  2583.  
  2584.              write( 'Hello world.' ).
  2585.  
  2586.         can be included on the right side of a rule:
  2587.  
  2588.  
  2589.         greetings(  X ) :- ishuman( X ),  write( 'Hello world.' ).  You 
  2590.         can  also write "write( X )" where X is some variable.  Note that 
  2591.         'Hello  world.' is not enclosed in double quotes.  Single quotes, 
  2592.         which denote a constant, are required. Double quotes would denote 
  2593.         a list, which is another thing entirely.
  2594.  
  2595.         Provided  that  a match to "ishuman" can be  found,  the  builtin 
  2596.         function  "write"  is  executed and the message  printed  to  the 
  2597.         screen.
  2598.              The  builtin  read( X ) reads a "structure" that  you  input 
  2599.         from the keyboard. More formally, we have
  2600.  
  2601.              read( <variable> or <constant> )
  2602.              write( <variable> or <constant> )
  2603.  
  2604.         If you write read( Input ),  then the variable "keyboard" will be 
  2605.         assigned to whatever is typed at the keyboard,  provided that the 
  2606.         input  is a valid PROLOG structure.  The builtin "read" will fail 
  2607.         if instead of Keyboard we wrote read( baloney ),  where "baloney" 
  2608.         is a constant,  and the user at the keyboard did not type exactly 
  2609.         "baloney." 
  2610.  
  2611.         When you input a structure in response to a "read" statement,  be 
  2612.         sure to end it with a period and an <ENTER>. 
  2613.  
  2614.              There  is  a convenient way of putting the cursor on  a  new 
  2615.         line. This is the builtin "nl". For example:
  2616.  
  2617.              showme :- write( 'line 1' ), nl, write( 'line 2' ). 
  2618.  
  2619.         would result in:
  2620.  
  2621.              line 1
  2622.              line 2
  2623.  
  2624.              There  is  also a primitive form of input/output for  single 
  2625.         characters. It will be discussed later.
  2626.  
  2627.  
  2628.  
  2629.  
  2630.  
  2631.  
  2632.  
  2633.  
  2634.  
  2635.  
  2636.  
  2637.  
  2638.  
  2639.  
  2640.  
  2641.  
  2642.         IV.                   A Fault Tree Example
  2643.  
  2644.              Consider the "won't start" fault tree for an automobile:
  2645.  
  2646.         {Car won't start}
  2647.              | 
  2648.              | 
  2649.         [Engine  turns  over](No) --> [Battery voltage](no)-\
  2650.                 (Yes)                                       v
  2651.                  |                                  {Check battery}
  2652.                  |
  2653.         [Smell gasoline](yes) --> {Try full throttle cranking}
  2654.                  |                       (failure)
  2655.         /--------/                           |
  2656.         |           /------------------------/ 
  2657.         |           |                       
  2658.         |           |
  2659.         |  [Check for fuel line leaks](yes)-->{Replace fuel line}
  2660.         |          (no)
  2661.         |           |
  2662.         |           |
  2663.         |  [Check for defective carburator](yes)--\
  2664.         |          (no)                           v
  2665.         |                                {Repair carburator}
  2666.         \----\
  2667.              |
  2668.              |
  2669.         [Is spark present](no)-->[Do points open and close](no)-\
  2670.              |                             (yes)                v
  2671.         /----/                               |          {Adjust points}
  2672.         |           /------------------------/
  2673.         |           |
  2674.         |  [Pull distributor wire, observe spark](blue)--\
  2675.         |        (orange)                                v
  2676.         |           |                           {Check plug wires & cap}
  2677.         |           |
  2678.         |  [Measure voltage on coil primary](not 12V)--\
  2679.         |         (12V)                                v
  2680.         |           |              {Check wiring, ballast resistor}
  2681.         |           |
  2682.         |  [Check condenser with ohmmeter](conducts)--\
  2683.         |    (no conduction)                          v
  2684.         |           |                         {Replace condenser}
  2685.         |           |
  2686.         |  [Open and close points](voltage not 0 - 12)--\
  2687.         |   (voltage swings 0 - 12)                     v
  2688.         |           |                         {Fix primary circuit}
  2689.         |           |
  2690.         |  {Consider hidden fault, swap components]
  2691.         |
  2692.         |
  2693.         \-------{Call a tow truck!!}
  2694.  
  2695.  
  2696.  
  2697.  
  2698.  
  2699.  
  2700.  
  2701.  
  2702.  
  2703.  
  2704.  
  2705.  
  2706.  
  2707.  
  2708.              A PROLOG program to  implement this is simple. Each statment 
  2709.         represents  a  decision point fragment of the  tree.  The  PROLOG 
  2710.         interpreter  dynamically  assembles  the tree as  it  attempts  a 
  2711.         solution. 
  2712.  
  2713.         'car wont start' :- write( 'Is the battery voltage low?' ), 
  2714.                             affirm, nl,
  2715.                             write( 'Check battery' ).
  2716.  
  2717.         'car wont start' :- write( 'Smell gasoline?' ), 
  2718.                             affirm, nl,
  2719.                             'fuel system'.
  2720.  
  2721.         'fuel system'    :- write( 'Try full throttle cranking' ).
  2722.  
  2723.         'fuel system'    :- write( 'Are there fuel line leaks?' ),
  2724.                             affirm, nl,
  2725.                             write( 'Replace fuel line.' ).
  2726.  
  2727.         'fuel system'    :- write( 'Check carburator' ).
  2728.  
  2729.         'car wont start' :- write( 'Is spark present?' ),
  2730.                             not( affirm ), nl,
  2731.                             'no spark'.
  2732.  
  2733.         'no spark'       :- write( 'Do points open and close?' ),
  2734.                             not( affirm ), nl,
  2735.                             write( 'Adjust or replace points.' ).
  2736.  
  2737.         'no spark'       :- write( 'Is the spark off the coil good?' ),
  2738.                             affirm,
  2739.                             write( 'Check plug wires and cap.' ).
  2740.  
  2741.         'no spark'       :- write( 'What is the voltage on the primary
  2742.                              of the coil: ' ), 
  2743.                             read( Volts ), 
  2744.                             Volts < 10,
  2745.                             nl,
  2746.                             write('Check wiring and ballast resistor.').
  2747.  
  2748.         'no spark'       :- write( 'Does the capacitor leak?' ),
  2749.                             affirm,
  2750.                             write( 'Replace the capacitor.' ).
  2751.  
  2752.         'no spark'       :- not( 'primary circuit' ).
  2753.  
  2754.         'primary circuit' 
  2755.                          :- write( 'Open the  points.  Voltage  across 
  2756.                               coil?:'), nl,
  2757.                             read( Openvolts ), Openvolts < 1, 
  2758.                             write(  'Close the points.  Voltage  across 
  2759.                               coil?:'),
  2760.                             read( Closevolts ), Closevolts > 10, nl,
  2761.                             write( 'Primary circuit is OK.' ). 
  2762.  
  2763.         'no spark'       :- write( 'Consider a hidden fault. Swap
  2764.                               cap, rotor,points,capacitor.' ).
  2765.  
  2766.  
  2767.         'Car wont start' :- write( 'Get a tow truck!!' ).
  2768.  
  2769.  
  2770.  
  2771.  
  2772.  
  2773.  
  2774.  
  2775.  
  2776.                                  --End program--
  2777.  
  2778.  
  2779.              The  above  is  a  simple example of  an  expert  system.  A 
  2780.         sophisticated  system would tell you exactly the method by  which 
  2781.         it  has reached a conclusion.  It would communicate by a  "shell" 
  2782.         program  written  in PROLOG which would accept a wider  range  of 
  2783.         input   than  the  "valid  structure"  required  by  the   PROLOG 
  2784.         interpreter directly.
  2785.  
  2786.  
  2787.  
  2788.  
  2789.  
  2790.  
  2791.  
  2792.  
  2793.  
  2794.  
  2795.  
  2796.  
  2797.  
  2798.  
  2799.  
  2800.  
  2801.  
  2802.  
  2803.  
  2804.  
  2805.  
  2806.  
  2807.  
  2808.  
  2809.  
  2810.  
  2811.  
  2812.  
  2813.  
  2814.  
  2815.  
  2816.  
  2817.  
  2818.  
  2819.  
  2820.  
  2821.  
  2822.  
  2823.  
  2824.  
  2825.  
  2826.  
  2827.  
  2828.  
  2829.  
  2830.  
  2831.  
  2832.  
  2833.  
  2834.  
  2835.  
  2836.  
  2837.  
  2838.  
  2839.  
  2840.         V.                            Lists               
  2841.  
  2842.              Consider  a  shopping list given you by your wife.  It is  a 
  2843.         piece of paper with items written on it in an order that probably 
  2844.         symbolizes  their  importance.  At the top it  may  say  EGGS!!!, 
  2845.         followed by carrots, hamburger, and finally a flea collar for the 
  2846.         dog, if you can find one. In PROLOG such a list would be written:
  2847.  
  2848.         1)   [eggs, carrots, hamburger, fleacollar]
  2849.  
  2850.         The  order of a list is important so that eggs and carrots cannot 
  2851.         be reversed and PROLOG be uncaring.
  2852.  
  2853.         Let us put the list in a structure:
  2854.  
  2855.              shopping( [eggs, carrots, hamburger, fleacollar] ).
  2856.  
  2857.         Then  if you wished to isolate the head of the list you could ask 
  2858.         the question:
  2859.  
  2860.              shopping( [ Mostimportant | Rest ] ).
  2861.  
  2862.         and PROLOG would respond:
  2863.  
  2864.              Mostimportant   =  eggs,   
  2865.              Rest   =   [carrots,   hamburger, fleacollar].
  2866.  
  2867.         The vertical bar "|" is crucial here. It is the string extraction 
  2868.         operator,  which  performs  a  combination  of the  CDR  and  CAR 
  2869.         functions  of LISP.  When it appears in the context [X|Y] it  can 
  2870.         separate the head of the list from the rest, or tail.
  2871.  
  2872.  
  2873.              You  may have gained the impression that PROLOG is a  rather 
  2874.         static language capable of answering simple questions,  but it is 
  2875.         far  more powerful than that.  The string extraction operator  is 
  2876.         the  key.  It permits PROLOG to whittle a complex expression down 
  2877.         to the bare remainder.  If the rules you have given it permit  it 
  2878.         to  whittle  the  remainder  down to  nothing,  then  success  is 
  2879.         achieved. An example of this is the definition of "append."
  2880.  
  2881.              Let  us suppose you have not yet done yesterday's  shopping, 
  2882.         let alone today's. You pull it out of your wallet and sootch tape 
  2883.         it to the list your wife just gave you. Yesterday's list was:
  2884.  
  2885.              [tomatoes, onions, ketchup]
  2886.  
  2887.         Combined with [eggs, carrots, hamburger, fleacollar] we obtain
  2888.  
  2889.              [eggs,carrots,hamburger,fleacollar,tomatoes,onions,garlic].
  2890.  
  2891.         To  take one list and to attach it to the tail of another list is 
  2892.         to  "append"  the first to the second.  The PROLOG definition  of 
  2893.         append is:
  2894.  
  2895.  
  2896.  
  2897.         Rule1:     append( [], L, L ).
  2898.  
  2899.         Rule2:     append( [X|List1], List2, [X|List3] ) :-
  2900.  
  2901.  
  2902.  
  2903.  
  2904.  
  2905.  
  2906.                       append( List1, List2, List3 ].
  2907.  
  2908.         The  general  scheme is this:  
  2909.  
  2910.         The definition consists of one rule and one fact.  The rule  will 
  2911.         be used over and over again until what little is left matches the 
  2912.         fact.  The [] stands for empty list,  which is like a bag without 
  2913.         anything in it. This is an example of a recursive definition.
  2914.              Suppose we ask:
  2915.  
  2916.              append( [a,b,c], [d,e,f], Whatgives ).
  2917.  
  2918.         1. Rule 2 is invoked with arguments ( [a,b,c], [d,e,f], Whatgives ).
  2919.         2. Rule 2 is invoked again with arguments:
  2920.              ( [b,c], [d,e,f], List3 ).
  2921.         3. Rule 2 is invoked again with arguments:
  2922.              ( [b], [d,e,f], List3 ).
  2923.         4.  The  arguments  are now ([],  [d,e,f],  List3 ).  Rule 1  now 
  2924.             matches. End.
  2925.  
  2926.         How does this cause a list to be constructed? The key is to watch 
  2927.         the   third  argument.   Supplied  by  the  user,   it  is  named 
  2928.         "Whatgives". The inference engine matches it to [X|List3] in rule 
  2929.         2. Now lets trace this as rule two is successivly invoked: 
  2930.  
  2931.  
  2932.                 Whatgives                                                
  2933.                    |                                                     
  2934.                    |                                                     
  2935.                    |                                                     
  2936.                    v                                                     
  2937.         Rule2:  [X|List3] (List1 = [b,c])                                
  2938.                  |  \                                                    
  2939.                  |   \                                                   
  2940.                  |    \                                                  
  2941.                  v     \                                                 
  2942.         Rule2:   a   [X'|List3'] (List1' = [c])                          
  2943.                       |    \                                             
  2944.                       |     \                                            
  2945.                       |      \                                           
  2946.                       v       \                                          
  2947.         Rule2:        b     [X''|List3''] (List1'' = [], ie., empty set.)
  2948.                               |    \                                     
  2949.                               |     \                                    
  2950.                               |      \                                   
  2951.         Rule1:                c       L  ( in Rule1 = [d,e,f] )              
  2952.                                                                          
  2953.         End.
  2954.  
  2955.  
  2956.         L in rule 1 is [d,e,f] for the following reason: Notice that rule 
  2957.         2 never alters List2. It supplies it to whatever rule it invokes. 
  2958.         So L in rule 1 is the original List2, or [a,b,c].
  2959.  
  2960.              This example would not have worked if the order of rules one 
  2961.         and  two  were  reversed.  The  PROLOG  inference  engine  always 
  2962.         attempts to use the the first rule encountered. You could imagine 
  2963.         it as always reading your program from the top down in attempting 
  2964.         to  find an appropriate rule.  Since rule 2 would always satisfy, 
  2965.         an  unpleasant  thing  would  have happened  if  the  order  were 
  2966.  
  2967.  
  2968.  
  2969.  
  2970.  
  2971.  
  2972.         reversed. The program would loop forever.
  2973.              
  2974.  
  2975.  
  2976.  
  2977.              I  hope  that  this tiny introduction to PROLOG  whets  your 
  2978.         appetite. You should now purchase the book
  2979.  
  2980.              Programming In Prolog
  2981.              W.F. Clocksin and C.S. Mellish
  2982.              Springer - Verlag
  2983.              Berlin,Heidelberg,New York. 1981,1984
  2984.  
  2985.  
  2986.  
  2987.  
  2988.  
  2989.  
  2990.  
  2991.  
  2992.  
  2993.  
  2994.  
  2995.  
  2996.  
  2997.  
  2998.  
  2999.  
  3000.  
  3001.  
  3002.  
  3003.  
  3004.  
  3005.  
  3006.  
  3007.  
  3008.  
  3009.  
  3010.  
  3011.  
  3012.  
  3013.  
  3014.  
  3015.  
  3016.  
  3017.  
  3018.  
  3019.  
  3020.  
  3021.  
  3022.  
  3023.  
  3024.  
  3025.  
  3026.  
  3027.  
  3028.  
  3029.  
  3030.  
  3031.  
  3032.  
  3033.  
  3034.  
  3035.  
  3036.  
  3037.