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 points
In Part I, you are going to write a Prolog knowledge base and use it to answer some queries.
Let the relation parentA B means A is a parent of B or B is a child of A; and let the relation siblingA 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
himselfherselfNote 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 points
In Chapter 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
Detecting Power of Two
Convention:
powerOfX means X is a power of
We are going to define this predicate recursively. The followings are the fact and rule for detecting whether a numeral
is a power of or not:
The base clause is a fact: is a power of because ;
The recursive clause is a rule: X is a power of only if there is a Y such that when adding Y to Y the result is
X and Y is a power of
For example, the following shows how the queries should be performed:
powerOfsuccsuccsuccsucc
true
yes
powerOfsuccsuccsucc
no
The first query shows that is a power of ; while the second shows that 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 a power of
Is a power of
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
