Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

To write a program in Prolog you will write your code in vi or emacs and then use gprolog or swipl to execute your code.

To write a program in Prolog you will write your code in vi or emacs and then use gprolog or swipl to execute your code. Prolog code usually has the extension .pro or .pl. Rule 1: & Rule 2: & & Rule 3: Rule 4: Rule 5: & Enter these rules into your Prolog source code. following the example enter A, B, C, D and E as fact.

Rules are encoded with the consequent first, followed by the operator :-, then the clauses of the antecedent separated by commas. For example: fruit(apple) :- color(red). full(X) :- ate(X, hamburger). The first rule is interpreted as: IF color is red THEN apple is fruit. The second rule is interpreted as: IF X ate hamburger THEN X is full. Unlike the first rule, the second rule uses a variable. Variables in Prolog begin with an upper case letter. Invoking full(X) during runtime will check for all objects in the database that ate a hamburger. If you invoke full(jill) it will check if jill ate a hamburger. This is how you will implement functions in Prolog. Queries Enter code into a text editor, save it, then run gprolog and consult your source code (see above for the command to do this). Here is the code repeated for your convenience: color(red). ate(albert, hamburger). ate(joe, salad). ate(jill, hamburger). fruit(apple) :- color(red). full(X) :- ate(X, hamburger). To check if a rule has been proven (e.g. it has fired/it is true/it is in the database) invoke the following command: | ?- fruit(apple). true. which attempts to prove that fruit is apple. Since color is red is fact, the rule fruit(apple) :- color(red). will always be true. This is an example of a ground query. To check if an object is full: | ?- full(joe). false.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Beginning VB 2008 Databases

Authors: Vidya Vrat Agarwal, James Huddleston

1st Edition

1590599470, 978-1590599471

More Books

Students also viewed these Databases questions

Question

What are the Five Phases of SDLC? Explain each briefly.

Answered: 1 week ago

Question

How can Change Control Procedures manage Project Creep?

Answered: 1 week ago