0
1.9kviews
Introduction to PROLOG
1 Answer
0
15views

It uses idea of logical programming.

It is a language which can build a database of facts and build a knowledge Base of protocols/rules.

Syntax and Semantics: In PROLOG programming logic is expressed in terms of relations. For computation a query has to be executed based upon these relations.

Working of PROLOG:

Once a query is given, the prolog engine tries to find a resolution denial of the negated query.

If the negated query can be proven false then it makes the union of clauses and set of single negated query false is created.

Data type:

i. Term: Relations and Queries are constructed using the term.

ii. Atoms:

It is a general purpose name which doesn’t have any inherent meaning. For e.g.: “X”, red etc.

iii. Numbers: Number can be in integer format or in floating format.

iv. Variable: It is denoted with help of string of alphabets, underscore and numbers.

NNme of variable begins with a Capital letter or an underscore: it cannot start with a number as per standards.

v. Compound terms: As the name suggests it is a blend of an atom called functor which is followed by a comma- separated lists of arguments which is enclosed in paranthesis.

Clauses:

• Relations are represented by help of clauses.

• There are two types of clauses:

Rules:

• Clauses with the bodies are called as rules.

• Conjunction and disjunction cannot appear in the head of rule, it can only appear in body.

• For example: Head: Body(i.e. Head is True if Body is true)

Facts:

• Clauses with the empty bodies are called as facts.

e.g.: Mickey (mouse)

Execution:

• Execution is done with the help of queries. For e.g.: is Mickey a mouse?

• We can write this query as: ?-mouse(X).

X=Mickey.

Loops and recursion: It has loops and recursion.

Negation:

• As per PROLOG predicates negation is treated as a failure.

• It uses few built-in predicates for input-output activities. For e.g. Write, which is used to display a term on the screen.

Basic Programs in PROLOG:

Facts are:

  1. Mango is a fruit.

  2. Watermelon is a fruit.

These clauses can be written as:

Fruit (mango)

Fruit (watermelon).

Please log in to add an answer.