anup kunte
unread,Jan 8, 2008, 11:50:38 AM1/8/08Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Konkan gyanpeeth College of Engg. Dept of Computers and IT
* Prolog is a logic programming language. It is a general purpose
language often associated with artificial intelligence and
computational linguistics.
* It has a purely logical subset, called "pure Prolog", as well as a
number of extra-logical features.
* Having its roots in formal logic, and unlike many other programming
languages, Prolog is declarative in nature
* The program logic is expressed in facts and rules, and execution is
triggered by running queries over these facts and rules.
* We organize a prolog program into set of clauses: which may be
either facts or rules.
* Any general prolog program consists mainly of three sections
Predicate, Clauses, and Goal.
* Predicate defines vividly, the rules that are defined in the clauses
that is it's like a type definition/ prototyping in any other
programming language. This may also precede a section for defining
data types of terms used in the program.
* Clauses section contains either facts or Rules. Facts associate
truth value against the variable terms, whereas rules give rather
recursive definition so as to extend or rather make inference from the
facts.
e.g. consider following program:
/* START of program */
predicates:
sibling(string,string)
parent_child(string,string)
mother_child(string, string)
father_child(string,string)
clauses:
sibling(X, Y) :- parent_child(Z, X), parent_child(Z, Y).
parent_child(X, Y) :- father_child(X, Y).
parent_child(X, Y) :- mother_child(X, Y).
mother_child(trude, sally).
father_child(tom, sally).
father_child(tom, erica).
father_child(mike, tom).
goal:
sibling(sally, erica)
/* END of program */
father_child(tom, sally) This is a fact as it has variable
parameters been replaced by two terms "tom" "sally" thus making it
true.
sibling(X, Y) :- parent_child(Z, X), parent_child(Z, Y).
this is a rule left of ":-" is head and right is tail. While scanning
through for solving query if head matches with the query string then
compiler just replaces head by tail.
If the query was as above and we execute/ rather solve/ answer the
program as:
1. first searching is done in clauses section for "sibling(sally,
erica)"
2. we find a match in "sibling(X, Y) :- parent_child(Z, X),
parent_child(Z, Y)."
3. here X is assigned sally and Y = Erica and the right side is
expanded in tree fation
sibling(sally,
erica)
parent_child(Z, sally) parent_child(Z, erica).
4. now to know head to be surely true / false we need to know if all
the tail clauses are true or not.
5. The "," operates as and operator.
6. So now for left node "parent_child(Z, sally)" entire clauses
section is searched to get a matches
parent_child(Z, sally)
mother_child(trude, sally) father_child(tom, sally)
7. and Z= trude or Z=tom and both childs thus in fully a fact form
thus true. So we stop further expansion of tree and thus the searching
process for entire left part of tree.
8. Similar process is repeated for right part of tree root and thus
finally get result as true.
NOTE: Example u can take anything smaller also....I think this would
suffice you but if u require more u can mail me same.
in point 6 and 3 it is a tree pls refer prolog.doc file in file
section for better view.