Prolog and Datalog
Prolog and Datalog
Prolog and Datalog
Prolog has its roots in first order logic and formal logic
Prolog is well-suited for specific tasks that benefit from rule-based logical
queries such as searching databases, voice control systems, and filling
templates.
3 History
It was found that Prolog was the ideal choice for the language due
to its simplicity and expressiveness.
5 Implementations
Data Types
Compound
Atoms Numbers Variables
Terms
10 Atoms, Numbers AND Variables
Atom: General purpose name without any meaning; can be a single word starting
with a small case letter, but if it consists of more words or starts with a capital case
letter, then it should be surrounded by single quotes. Ex: red, tree, ‘collage c1’,
‘Red’…
Numbers: Can be floats or Integers
Variables: A place holder of arbitrary term. Name of a variable is an alphanumeric
string that can contain underscores. The name can only start with a capital letter or
an underscore. Ex: X_a1, _x1
11 compound terms
A prolog program is run through queries on the rules and facts present in a
program
A query maybe used to ask whether something is true or false, where we
get answers like ‘yes’ or ‘no’
We can also try to find/search for the value of a variable given some
relations.
16 Query Examples
The Zebra puzzle, a.k.a. Einstein's Riddle, is a logic puzzle which is to be solved
programmatically.
It has several variants, one of them this:
There are five houses.
The English man lives in the red house.
The Swede has a dog.
The Dane drinks tea.
The green house is immediately to the left of the white house.
They drink coffee in the green house.
The man who smokes Pall Mall has birds.
In the yellow house they smoke Dunhill.
In the middle house they drink milk.
26 Demo – Zebra Puzzle (Einstein’s Riddle)
http://www.liquisearch.com/datalog/features_limitations_and_extensions
http://rosettacode.org/wiki/Zebra_puzzle
http://www.deransart.fr//prolog/docs.html
https://www.cpp.edu/~jrfisher/www/prolog_tutorial/contents.html
http://link.springer.com/chapter/10.1007%2F978-3-642-24206-9_5