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

Define physical context, Question : Context aware mobile web applicatio...

Question : Context aware mobile web applications are the important to achieve ubiquity, device independence and personalization. The context provides detailed information about

Engineering phyics, what is interference of light explain the nessicity of ...

what is interference of light explain the nessicity of coharent source for obtaining sustain interference pattern

Differentiate between programming tools and authoring tools, Diffrentiate p...

Diffrentiate programming tools and authoring tools Distinction between programming tools and authoring tools is not at first obvious. Though, authoring tools require less techn

Illustrate what is a ion pair energy, Q. Illustrate what is a ion pair ener...

Q. Illustrate what is a ion pair energy? Answer:- Ion energy contains electric charges called protons (+) and neutrons (0) and electrons (-) charges. It's present in an at

Project, how many pins does a floppy drive connector have

how many pins does a floppy drive connector have

Exdplain instruction buffers, Instruction buffers For taking the comple...

Instruction buffers For taking the complete advantage of pipelining pipelines must be filled continuously. So instruction fetch rate must be matched with pipeline consumption r

Determine the equivalent hexadecimal form of decimal number, Solve the equa...

Solve the equation 65.535 10 = X 16 Ans. In order to get X, convert the Decimal number 65.535 in its equal Hexadecimal form. So first taking 65 the integer part to convert in i

Explain a full subtractor using half subtractors, Draw the logic diagram of...

Draw the logic diagram of a full subtractor using half subtractors and explain its working with the help of a truth table Ans: Full Subtractor: It has to take care of repe

Evaluation stack architecture, Q. Evaluation Stack Architecture? A stac...

Q. Evaluation Stack Architecture? A stack is a data structure which implements Last-In-First-Out (LIFO) access policy. You can add an entry to the with a PUSH(value) as well as

What is the conclude of the force of gravity on an object, Q. What is the...

Q. What is the conclude of the force of gravity on an object? Answer:- Force is the vector product of mass as well as acceleration F = ma. Weight is an unusual case of t

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