Program - 1: AIM:-Introduction To Prolog
Program - 1: AIM:-Introduction To Prolog
Introduction Prolog is a general purpose logic programming language associated with artificial intelligence and computational linguistics. Prolog is declarative, The program logic is expressed in terms of relations, represented as facts and rules and a computation is initiated by running a query over these relations. The language was first conceived by a group around Alain Colmeraurer in Marseille, France.
Data types Prologs single data type is the term. Terms are either atoms, numbers, variables and compound terms. An atom is a general purpose name with no inherit meaning. Ex: x,blue etc. Numbers can be floats or integers. Variables are denoted by a string consisting of letters, numbers and underscore characters, and beginning with an upper case characters and underscore. A compound term is composed of an atom called functor and a number of arguments, which are again terms.
Compound terms are ordinarily written as a functor followed by a commaseparated list of argument terms, which is contained in the parentheses. A List is an ordered collection of terms. It is denoted by square brackets with the terms separated by brackets with the terms separated by commas or in
the case of an empty list, [] ex: [1,2,3] or [red, green, blue] etc.
Rules and Facts Prolog programs describe relations, defined by means of clauses. There are two types of clauses:
o o
Facts Roles
A role is of the form Head :- Body and is read as head is true if body is true. A rules body consists of calls to predicates, which are called the rules goals. Classes with empty bodies are called facts. Ex: cat(tom).
Evaluation Execution of a Prolog program is initiated by the user's posting of a single goal, called the query. Logically, the Prolog engine tries to find a resolution refutation of the negated query. The resolution method used by Prolog is called SLD resolution.
Ex: mother_child(trude, sally). father_child(tom, sally). father_child(tom, erica). father_child(mike, tom). 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). Results in the following query being evaluated as true: ?- sibling(sally, erica). Yes