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

What is floppy drives, Q. What is Floppy Drives? Disks used with a flop...

Q. What is Floppy Drives? Disks used with a floppy disk drive are small removable disks fabricated of plastic coated with magnetic recording material. Disk rotates at 360RPM. F

Intel architecture – 64, IA-64 (Intel Architecture-64) is a 64-bit processo...

IA-64 (Intel Architecture-64) is a 64-bit processor architecture created in cooperation by Hewlett-Packard and Intel applied by processors like Itanium. The objective of Itanium wa

Processor technology , Processor Technology: Computers consist of elec...

Processor Technology: Computers consist of electronic components assembled in a design or "architecture" that will perform necessary functions of input, output, computation an

What is dhcp and how it works, Full form of is DHCP: Dynamic Host Control P...

Full form of is DHCP: Dynamic Host Control Protocol. It is mainly used to bound MAC Addresses of system. Especially for Wireless System.

Programming with parallel virtual machine, Q. Programming with parallel vir...

Q. Programming with parallel virtual machine? The general method for writing a program with PVM is like this:  A user writes one or more sequential programs in C++, C or FOR

Basic characteristics of an experts system, An experts systems must perform...

An experts systems must perform well that is achieve the same levels of performance in the domain of interest that human experts can achieve. But simply producing good so

Ifstream on the input file, Write a main function that opens an ifstream on...

Write a main function that opens an ifstream on the input file, "person.dat".  If the stream cannot be  opened, output an error message and exit.       The file format is as foll

Contain your variable names and definitions, Give your analysis for the fol...

Give your analysis for the following problem statement: You require to write a program that calculates the area and perimeter of a rectangle whose dimensions (Length &width) are gi

What is time out mechanism, What is time out mechanism. If one unit is ...

What is time out mechanism. If one unit is faulty the data transfer will not be done. Such an error can be detected using time out mechanism which makes an alarm if the data tr

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