home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / lang / prolog / 1610 < prev    next >
Encoding:
Internet Message Format  |  1992-08-26  |  2.0 KB

  1. Path: sparky!uunet!munnari.oz.au!goanna!ok
  2. From: ok@goanna.cs.rmit.oz.au (Richard A. O'Keefe)
  3. Newsgroups: comp.lang.prolog
  4. Subject: Re: Help on problem needed!
  5. Keywords: help
  6. Message-ID: <14219@goanna.cs.rmit.oz.au>
  7. Date: 27 Aug 92 07:29:44 GMT
  8. References: <meskes.713709771@ulysses> <1992Aug25.074623.25450@greco-prog.fr>
  9. Organization: Comp Sci, RMIT, Melbourne, Australia
  10. Lines: 39
  11.  
  12. In article <1992Aug25.074623.25450@greco-prog.fr>, billaud@greco-prog.fr (Michel BILLAUD) writes:
  13. > In article <meskes.713709771@ulysses> meskes@ulysses.informatik.rwth-aachen.de (Michael Meskes) writes:
  14. > >Can you program a IF...THEN...ELSE in Prolog without using the cut?
  15. > No. a proof by contradiction:
  16.  
  17. Well, a lot depends on what goes in the gaps.  If the stuff to go in the
  18. gaps is logical formulas, the proof goes through.  But with suitable
  19. restrictions it is possible.  For example, define
  20.     <test> ::= <expression> <a.relop> <expression>
  21.             |  <term> <t.relop> <term>
  22.             |  NOT <test>
  23.             |  <test> AND <test>
  24.             |  <test> OR <test>
  25. where the understanding is that the arithmetic expressions whose values
  26. are to be compared and the terms which are to be compared must be ground.
  27. (NU-Prolog-style 'when' declarations for comparison predicates can do this.)
  28. Then we can negate a formula:
  29.     NOT(E1 a.R E2) => E1 NOT(a.R) E2        e.g. NOT(<) = >=
  30.     NOT(T1 t.R T2) => T1 NOT(t.R) T2        e.g. NOT(@<) = @>=
  31.     NOT(NOT(T))    => T
  32.     NOT(X1 AND X2) => NOT(X1) OR NOT(X2)
  33.     NOT(X1 OR  X2) => NOT(X1) AND NOT(X2)
  34. and something of the form
  35.     IF <test> THEN <true> ELSE <false>
  36. can be converted to
  37.     ( <test>, <true>
  38.     ; NOT(<test>), <false>
  39.     )
  40. Note that SB-Prolog already recognises some special cases of this pattern,
  41. so that ( X < 0, a ; X >= 0, b ) will be compiled as an if-then-else.
  42.  
  43. If you are writing an interpreter for some other language (e.g. a pure
  44. functional programming language) you can _interpret_ an if-then-else in
  45. that language without a Prolog cut.
  46.  
  47. -- 
  48. You can lie with statistics ... but not to a statistician.
  49.