Question: part I ( 1 2 points ) In Part I, you are going to write a Prolog knowledge base and use it to answer some

part I (12 points)
In Part I, you are going to write a Prolog knowledge base and use it to answer some queries.
Let the relation parent(A, B). means A is a parent of B (or B is a child of A); and let the relation sibling(A, B).
means A and B are siblings.
Encoding the Knowledge Base
Encode in your knowledge base these (and only these) six facts:
Amy is the daughter of Bob.
Bob is the father of Christine.
David is the son of Bob.
Emily is the mother of Frank.
Gilbert is the son of Emily.
Heidi is the daughter of Emily.
Define a Rule for Siblings
Also encode in your knowledge base this (and only this) rule:
A and B are siblings only if A and B are children of the same person. However, a person cannot be a sibling of
himself/herself.(Note that in Prolog, we use A \= B to mean that A and B are not the same object.)
Querying the Knowledge Base
Put the facts and the rule in a prolog file. Load the file into Prolog; and then perform the following queries:
Is Bob a parent of Amy?
Is Bob a parent of Heidi?
Who are the children of Emily?
Are Christine and David siblings?
Are Amy and Gilbert siblings?
Who are Franks siblings?
Draw the Search Tree
Draw the search tree for the last question: Who are Franks siblings?
Part II (8 points)
In Chapter 3 of the prolog book, we have discussed how to implement the add predicate using the definition of numeral
with the successor (complex) term. Now we would like to extend the system to detect if a numeral is a power of 2.
Detecting Power of Two
Convention:
powerOf2(X). means X is a power of 2.
We are going to define this predicate recursively. The followings are the fact and rule for detecting whether a numeral
is a power of 2 or not:
The base clause is a fact: 1 is a power of 2(because 1=20);
The recursive clause is a rule: X is a power of 2 only if there is a Y such that when adding Y to Y the result is
X, and Y is a power of 2.
For example, the following shows how the queries should be performed:
|?- powerOf2(succ(succ(succ(succ(0))))).
true ?
yes
|?- powerOf2(succ(succ(succ(0)))).
no
The first query shows that 4 is a power of 2; while the second shows that 3 is not.
Querying the Knowledge Base
Put the relations and the rule in a prolog file. Load the file into Prolog; and then perform the following queries:
Is 8 a power of 2?
Is 10 a power of 2?
part I ( 1 2 points ) In Part I, you are going to

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Accounting Questions!