Search mechanisms in prolog, Computer Engineering

Search mechanisms in Prolog:

Here we can needs this simple Prolog program to describe how Prolog searches as:president(X) :- first_name(X, georgedubya), second_name(X, bush).

prime_minister(X) :- first_name(X, maggie), second_name(X, thatcher).

prime_minister(X) :- first_name(X, tony), second_name(X, blair).

first_name(tonyblair, tony).
first_name(georgebush, georgedubya).

second_name(tonyblair, blair).
second_name(georgebush, bush).

If there we loaded this in a Prolog implementation into as Sicstus, or queried the database as:

?- prime_minister(P).

In fact then Sicstus would search in the following manner as: it would run through it is database when pending for it came across a Horn clause or fact for that the head was prime_minister and the arity of the predicate was 1. Than there It would first look at the president clause, so after that reject this to see the name of the head doesn't match with the head in the query. moreover, next it would find the clause as:

prime_minister(X) :- first_name(X, maggie), second_name(X, thatcher).

There fits the bill. After than it would look at the predicates in the body of the clause or see if it could satisfy them. In fact in this case, we see that it would try to find a match for first_name(X, maggie). But, it would fail, it means that there no such information can be found in the database. Because it means that the entire clause fails Sicstus would backtrack, thai is., so it would go back just to looking for a clause with the same head as the query. But it would next find this clause such as:

prime_minister(X) :- first_name(X, tony), second_name(X, blair).

So there then it would look at the body again, than try to find a match for first_name(X, tony). According to that it would look through the datatabase and find X=tonyblair a good assignment hence it means the fact first_name(tonyblair, tony) is found towards the end of the database. as well having assigned X=tonyblair, so it would then look for a match to: second_name(tonyblair, blair), and would succeed. Likewise, the answer tonyblair would make the query succeed, for this would be reported back to us.

Posted Date: 1/10/2013 5:56:32 AM | Location : United States







Related Discussions:- Search mechanisms in prolog, Assignment Help, Ask Question on Search mechanisms in prolog, Get Answer, Expert's Help, Search mechanisms in prolog Discussions

Write discussion on Search mechanisms in prolog
Your posts are moderated
Related Questions
What is assembly language? Assembly language : It is a family of low-level language for microprocessors, programming computers, microcontrollers etc. All are implement a symbo

Define Time Sharing. Time Sharing: Sharing of a computing resource among various users by means of multiprogramming and multi-tasking is termed as timesharing. By permittin

Q. Example on PUBLIC DIVISOR? Linker appends all segments having the same name and PUBLIC directive with segment name into one segment. Their contents are pulled together in co

Explain a multiprogramming operating system? A multiprogramming operating system: It is system which allows more than one active user program or part of user program to be st

The UNIX operating system for a multiprocessor system has a number of extra features as compared to normal UNIX operating system.  Let's first consider the design objectives of mul

Q. Define Decision Support System? Ans. The decision support system is an information system application which help decision making. DSS tends to be used in planning or analy

Trunks are the lines that run between (A)  Subscribers and exchange (B)  Switching system and power plant (C) Local area network (D) Switching stations Ans:

Q. What is Data link layer? Data link layer: data link layer is responsible for transmitting a group of bits between adjacent nodes. Group of bits is termed as frame. Network

Students are needed to work in group of 3 and make an Android mobile application falling under the following categories: Multimedia o    Eg: Camera app, mp3 player, ga

Write a program to find the area and perimeter of a circle of given radius # include void main() { float radius, area, perimeter, pi=3.14; printf("\nEnter the rad