Prolog - The Solar System.

LA home
Computing
Logic
 Prolog
  Intro.
  Syntax
  Examples
   Windsor
   Append
   Aunt
   Solar
   Diff
   Tree
   Witch

Prolog is excellent for queries on relational data (as in the Mathematical sense of a "relation"), e.g.,

orbits(mercury, sun).  {facts}
orbits(venus,   sun).
orbits(earth,   sun).
orbits(mars,    sun).
orbits(jupiter, sun).
orbits(saturn,  sun).
orbits(uranus,  sun).
orbits(neptune, sun).

orbits(moon, earth).

orbits(deimos, mars).
orbits(phobos, mars).

orbits(ganymede, jupiter).
orbits(callisto, jupiter).
orbits(io,       jupiter).
orbits(europa,   jupiter).

orbits(titan,     saturn).
orbits(enceladus, saturn).

orbits(titania, uranus).
orbits(oberon,  uranus).
orbits(umbriel, uranus).
orbits(ariel,   uranus).
orbits(miranda, uranus).

orbits(triton, neptune).

planet(P)    <= orbits(P, sun).     {rules}
satellite(S) <= orbits(S, P) and planet(P).

? satellite(S).   {query}

NB. The applet above needs Java on.
www:

free:
Linux
 Ubuntu operating-sys
OpenOffice office-suite
The GIMP ~photoshop
Firefox web-browser
FlashBlock flash on/off

© L. Allison   http://www.allisons.org/ll/   (or as otherwise indicated),
Created with "vi (Linux + Solaris)",  charset=iso-8859-1,  fetched Friday, 18-May-2012 13:49:12 EST.