Search mechanisms in prolog, Computer Engineering

Assignment Help:

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.


Related Discussions:- Search mechanisms in prolog

Stack overflow causes, Stack overflow causes   (A) Hardware interrupt. ...

Stack overflow causes   (A) Hardware interrupt.  (B) External interrupt.  (C) Internal interrupt.   (D) Software interrupt. Stack overflow occurs whereas execution

How 2-domain name servers contain exactly same set of names, Does it makes ...

Does it makes sense for two domain name servers to contain exactly the same set of names? Why? Yes. This is very advantageous for two domain servers having similar set of names

Define dynamic loading, Define dynamic loading. To get better memory-sp...

Define dynamic loading. To get better memory-space utilization dynamic loading is used. With dynamic loading, a routine is not loaded unless it is called. All routines are kept

By which many computers are connected in geographical area, A large numbers...

A large numbers of computers in a wide geographical area can be efficiently connected using? A large numbers of computers in a broad geographical area can be efficiently linked

By which analog signal combine with a carrier frequency, Analog signals can...

Analog signals can be              by combining them with a carrier frequency (A)  Carried                                      (B)  Transported (C)  Multiplexed

What is a scope resolution operator, A scope resolution operator (::), can ...

A scope resolution operator (::), can be used to describe the member functions of a class outside the class.

What is the window of the working set of a process, What is the window of t...

What is the window of the working set of a process? The window of the working set of a method is the total number in which the method had referred the set of pages in the work

How to work in dreamweaver?, HOW TO WORK IN DREAMWEAVER? How and Where ...

HOW TO WORK IN DREAMWEAVER? How and Where to open Dreamweaver? Step 1: Click on Start Step 2: Select Program Step 3: Select Macromedia Dreamweaver Step 4: Click on

How deep does fifo require to be stop underflow or overflow, Given the subs...

Given the subsequent FIFO and rules, how deep does the FIFO require to be to stop underflow or overflow? RULES: a. frequency(clk_A) = frequency(clk_B) / 4 b. per

Show block diagram of sequential circuits, Q. Show block Diagram of sequent...

Q. Show block Diagram of sequential circuits? A sequential circuit is an interconnection of storage elements and combinational circuits. The storage elements known as flip-flop

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd