Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Computer Engineering Expert

Search mechanisms in Prolog

We can utilize this simple Prolog program to describe how Prolog searches:

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(tony,tonyblair).

first_name(georgedubya,georgebush).

second_name(tonyblair, blair).

second_name(georgebush, bush).

If we loaded this into a Prolog implementation likeSicstus, and queried the database:

?- prime_minister(P).

then in the following mannerSicstus would search: it would run through it's database until it came across a Horn clause (or fact) for which the head was prime_minister and the arity of the predicate was 1. It would first search at the president clause and reject this because the name of the head does not match with the head in the query. Next it would find that the clause, through:

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

fits the bill. It would then lookin the body of the clause at the predicates and see if it could satisfy them. In this instance, it would try to find a match for first_nameX, maggie). However, it would fail, because no this type of information may be found in the database. That means that the total clause fails, and Sicstus would backtrack, for example, it would go back to looking for a clause with the same head as the query. Of course, it would next find this clause:

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

Then it would look at the body again, and try to discover a match for first_name(X, tony). It would look through the database and   discover   X=tonyblaira  good  assignment,   because  the   factfirst_name(tonyblair, tony) is got towards the end of the database. Similarly, having assigned X=tonyblair, then it would search for a match to: second_name(tonyblair, blair), and would succeed. So, the answer tonyblair would make the query succeed, and this would be reported back to us.

The essential thing to remember is that Prolog implementations search from the top to the bottom of the database, and in the body try each term of a clause in the order in which they appear. We say that Sicstus  has  verified  the  query  prime_minister(P) by  finding  something  which  satisfied  the declaration of what a prime minister is: Tony Blair. It is also good to remembering that Sicstus assumes negation as failure. This means that if it cannot verify a predicate, then the predicate is false. So the query is:

?- \+ president(tonyblair).

Returns an answer of 'true', because Sicstus cannot prove that Tony Blair is a president.

Computer Engineering, Engineering

  • Category:- Computer Engineering
  • Reference No.:- M9509975

Have any Question?


Related Questions in Computer Engineering

What are the similarities and differences of hierachical

What are the similarities and differences of hierachical, Network, and Object Oriented Database Models.

One of the issues in early virtualization use was slow

One of the issues in early virtualization use was slow performance due to translation of system commands. Which piece of computer hardware was revised to run hypervisors natively? Also There are three "families" of opera ...

The contracts manager at a company needs to make a large

The contracts manager at a company needs to make a large legal document available to an overseas customer. However, she has some challenges: The document contains sensitive information; it is too large to send via e-mail ...

Write a program in java to satisfy the following create a

Write a program in Java to satisfy the following : Create a class to store information on Network infrastructure assets. Network Infrastructure Asset may include PCs, Monitors, Switches, Routers, Cables, Access Points et ...

What is the binary representation of the decimal number

What is the binary representation of the decimal number 4.875 assuming the IEE 754 single precision format?

In powerpoint what is beneficial about the usage or video

In Powerpoint, what is beneficial about the usage or Video, Audio, Animation, and Photos with Effects during presentation and work. What are some useful tools you found that would improve performance?

Question suppose that as a dba you are tasked with

Question : Suppose that as a DBA, you are tasked with installing a new database management system in your organization. Would you choose the default system parameters when installing the system software? Explain and supp ...

Does bmw have a guided missile corporate culture and

Does BMW have a guided missile corporate culture, and incubator corporate culture, a family corporate culture, or an Eiffel tower corporate culture?

Assignment from chapter 10 page 302 web-based case read and

Assignment: From Chapter 10, page 302, Web-Based Case. Read and answer the questions. KNOWLEDGE MANAGEMENT SYSTEMS AND CRM In answer to the challenges Nelnet faces in servicing a growing volume of student loans, the comp ...

A chemistry student needsnbsp600 mlnbspof carbon

A chemistry student needs 60.0 mL of carbon tetrachloride for an experiment. By consulting the  CRC Handbook of Chemistry and Physics , the student discovers that the density of carbon tetrachloride is 1.59 g.cm^-3. Calc ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As