<戻る>

--- This is prolog1.doc ---
<< start of prolog guidance >>
1.kick
   Keyin "cmis"    <-MODEL INFERENCE SYSTEM
   Keyin "cprolog"   <-PROLOG WITH INFIX/DCG NOTATION

2.input
   1) kinds
    a) command
    b) Horn clause
    c) Goal clause
   2) command
      pre symbolized with : and left 4 char
      :sys  terminate prolog
      :dvc  at kick --> set input method 0:getch(),1:getc(stdin)
         at command input --> set list level 0:out,1:nop,2:dsnap
      :step execution step by step by getch
      :nost execution non stop
      :mode s,v smode(cpro/cmis)=0/1,vmode(VM=R/V)=0/1
         or no operand display mode and otherinfo
      :stat prolog/MIS execution status
      :help command list display
    a) i/o
      :cls  clear screen
      :list display list of input clause from line# (if input)
         if next exist then can reply y/n at next? prompt
      :file display directory able to select pfx
      :new  Horn clause (memory) clear
      :load prolog program (Horn clause) disk to memory
      :save prolog program (Horn clause) memory to disk
    b) Horn clause edit
      from,to,a/b,dest
         from/to/dest=line#
         a/b=after/before dest line#
      :move from-to -> dest after/before
      :copy from-to -> dest after/before
      :del  from-to
    c) set mode or specification
      :pure out yes/no
      :ans  out is one answer
      :quer out is all answers
      :trac trace out Goal clause & unify Horn clause at each
         unification
      :notr no trace but display unify Horn clause # tree
      :dupl out permit duplicate ans
      :nodu no duplicate
      :orde matching seq of Horn clause is left to right
    d) MIS operation
      :cond 0,1,2 lrmcond 0:nocond,1:ρ(p) at cond,2:ρ(p)(n) at refine
      :nocond lrmcond 0:no
      :log  MIS Lrm(k),CPtoHorn log
      :nolog no log
      :mult atom/func count control in refine
      :subfy h:subfy head(default),c:subfy clause
      :bind n:addbody(default) only,y:addbody+bindbody
      :samep same predicates atom add control in refine
      :gen  clause generate(ll fid can specify)
      :nogen no gen
      :god  t:godans true,f:godans false,n:asktogod
      :szcomp r:refine,c:cond
      :tatm two clauses atomsck y/n
      :hexu <Horn,example> unifyck y/n at CPtoHorn
      :lang Lang-L input Horn(pp(X):- style) save
      :ex  example <a,V> input orn(pp(X):-true/false style) save
      :rmis RMEM MIS execution(ll,ex fid can specify)
      :vmis VMEM MIS execution(ll,ex fid can specify)
      :hexck <Horn,example> unifyck(hn# can specify)
      :texu true example resolve used Lローm(k)
      :back backtrace execution
      :fine refinement execution
      :szck sizecomp & usageck 1 Horn clause statement
      :tack Horn clause hn#1 & hn#2 atom dup check
      :bltp builtin predicate sleep/wakeup
    e) etc
      :dcg  Horn clause DCG form convert to prolog form
   3) Horn clause
      head:-body.  ----- head is predicate and body are some predicates
                with ","
      head:-.    ----- no body
      head.     ----- same to head:-.
    a) 1 line edit
      new   input ----- line# no need input(add aftr last line)
      replace input ----- line # need input
      delete input ----- only 1 line# need
      n,u      ----- n:line#,u:a/b = (after/before)
                1 line new input(line# no need)
    b) flexible input or insert input (offline)
      input by 2 tools
         by MS-DOS edlin (line editor)
         by editor(ex. MIFES,etc)
      by any method
         with/without digit line# and 1 space before Horn clause
         with/without last period
      ex -> 0001 append([],X,X):-.
      if no need spaces exist then delete at :load exec
      4-digit line# and period may add at :save exec
    c) physical format in disk
      filename is with suffix ".PRO" or any
   4) Goal clause
     ?-body ----- body is only one predicate or are some predicates
            with ","

3.prolog syntax
   enclosed <> comments word of prolog style
   1) predicate or data
     name(term1,term2,---,termN)
     predicates are predicates separated by comma
     < assertion > : definition of predicates -> Horn clause
     < execution > : conclusion        -> Goal clause
     predicate exp --- father(child,parent) = child's father is
              parent
     data   exp --- birthday(1986,11,10)
   2) name
     1 or some chars a-z,0-9,ア-ン
   3) term
     constant,variable,function,list(comma list,period list,split list)
     or compound
     < pattern > : term
     < atom > : predicate with or without arguments
   4) constant
     int = signed or unsigned integer
     char = any chars enclosed with ' ' (don't forget ' mark!)
     /* function with or without arguments */
     /*  = s(N):successor equal to N+1 */
   5) variable
     pre symbolized _ or 1 char A-Z followed by any A-Z,a-z,0-9,ア-ン
     internal variable
      _tempNN
   6) function
     name(term list)
     ex: f(X) return true or false
   7) list
     [term1,term2,---,termN] <-- [term1|[term2|[---|[termN]]]]-]
     [term1|termL]      <-- termL=[term2,---,termN]
   8) infix notation
     operator="+ - * / <= >= ^= < > == = is || & ** ( )"
     sign mark permitt as A>+1, A=-1, A is -1
     nested parenhesis permitt as X=((2+3)*6+4)/2

4. builtin predicate
   1) inquiry
     ans(term1,term2,---,termN)
      argument include all variable in Goal clause predicates
      display one answer and terminate
     query(term1,term2,---,termN)
      argument include all variable in Goal clause predicates
      display all answers and terminate
   2) cut operator
     !
      make backtrack fail at "!"
   3) relational operator
     (true=-1,false=0) character string or numeric compare
     lt(term1,term2)    ---- true at term1< term2 else false
     le(term1,term2)    ---- true at term1<=term2 else false
     eq(term1,term2)    ---- true at term1==term2 else false
     ne(term1,term2)    ---- true at term1<>term2 else false
     gt(term1,term2)    ---- true at term1> term2 else false
     ge(term1,term2)    ---- true at term1>=term2 else false
   4) arithmetic operator term3=variable
     add(term1,term2,term3) ---- term3=term1+term2
     sub(term1,term2,term3) ---- term3=term1-term2
     mul(term1,term2,term3) ---- term3=term1*term2
     div(term1,term2,term3) ---- term3=term1/term2
     mod(term1,term2,term3) ---- term3=term1 mod term2
     exp(term1,term2,term3) ---- term3=term1**term2
   5) input/output operator
     read(term)       ---- term=input variable
     write(term)      ---- term=output char enclosed with ' '
     put(term)       ---- term=output ascii int
     nl           ---- new line
   6) substitution term2=variable
     eqv(term1,term2)    ---- term2=term1
   7) others
     true          ---- success
     false or fail     ---- failure (backtrack may happen)
     var(term)       ---- if term=variable then return true

5. prolog processing
   backward inference
    --> Goal's negative results inconsistency
   reply as yes/no/one-ans/all-ans by mode
   1) pattern matching
     a) Goal clause & Horn clause's Head
     b) Horn clause's Body & other Horn clause's Head
   2) matching rule
      from   to
     a) symbol  : symbol  = must equal symbol
     b) variable : symbol  = able to substitute to symbol
     c) symbol  : variable = able to substitute to variable
     d) variable : variable = 1st is substitute, else must equal
   3) unification if matched
     unificate = substitute matched pattern
   4) back-track if matching fail or strong cut

6. sample program in disk
  (:load and keyin command,Goal clause as under)
    <filename>    <contents>
   1) poisonus     simple sample (mushroom or nonmushroom)
             :pure
             ?-poisonus(X)
              answer = yes
   2) append   ---- list append definition sample
             ?-append([1,2],X,[1,2,3,4,5])
              answer = [3,4,5]
   3) fact    ---- list sample (calculate n!)
             :pure
             ?-fact(7,X)
              answer = 5040
   4) qsort    ---- cut operater sample (quick sort)
             ?-qsort([3,2,1],[],S)
              answer = [1,2,3]
   5) joinsel   ---- relational database search sample
             (join and sel)
             :query
             ?-sel(X) ------ 選択演算
              answer = ('tanaka','ono')
             ?-join(X,Y) --- 不等号結合演算
              answer = ('tanaka','matsuda')
                   ('kawaguchi','tanaka')
                   ('kawaguchi','matsuda')
   6) division  ---- arithmetic operation sample (relatinal database)
             :query
             :nodup
             ?-division(X) - 割り算
              r[A]=表rのAの部分の取り出し
              r[品物/品物]s=(r-((r[生産者]*s[品物])-r))[生産者]
                       <------ diff ------->
              answer = ('x') ('y')

7.system max
  HMAX 800  Horn(VM=32767) clause(lines)
  UHMAX 300  Sfalseck=FALSE USED HN history count
  DMAX 30  resolution depth
  GMAX 150  Goal length(bytes)
  AMAX 8   argcnt/atom
  MMAX 7   atom count/clause
  OMAX 40  INFIX OPR type
  TVMAX 40  sizecomp tvarc
  MAXWD 80  word length(bytes)
  LMAX 50  Lang-L(lines)
  EMAX 100  example(lines)
  CMAX    RM:RCMAX,VM:VCMAX
  RCMAX 2000 RM:REAL MEMORY MODE CMAX
  VCMAX 10000000L VM:VIRTUAL MEMORY MODE CMAX
  VMAX 26  VARIABLE MAP A-Z
  SMAX 15  max size of clause
  HL  120  Horn length(bytes) INFIX/DCG:REAL HL=80+INFIX,DCG
  GL  200  Goal length(bytes)
  ML  80   Lローm(k) length(bytes)
  TL  80   term length(bytes)
  WL  16   word length(bytes)

end of prolog guidance