Question: Use Prolog only (syntax and semantics.} (Use siwpl-SWI-Prolog) We can represent a hierarchical multiple inheritance structure as a collection of objects in Prolog, connected with

Use Prolog only (syntax and semantics.} (Use siwpl-SWI-Prolog)

We can represent a hierarchical multiple inheritance structure as a collection of objects in Prolog, connected with "isa" relations. Given such a Prolog representation of a structure, we would like to determine all the objects from which a given object can inherit properties. For the purposes of this question, we assume that this inheritance relationship is reflexive --- ie, an object can inherit properties from itself.

We assume that the inheritance structure is a directed acyclic graph (DAG). While it will not have cycles, there may still be multiple paths connecting a pair of nodes. Write a relation inherits-from(X,Y) that holds when

Y is an ancestor of X in the isa-based inheritance structure. If Y is not instantiated, then successive values for Y should be produced. You should produce each ancestor exactly once; no duplicates.

Example: If we have the following knowledge base: object(a). object(b). object(c). object(d). object(e). object(f). isa(a,b). isa(a,c). isa(b,e). isa(c,d). isa(d,b). isa(d,f). Then we should get the following results: ?-inherits-from(a,e). true ?-inherits-from(b,f). false. ?-inherits-from(a,X). X=a; X=b; X=c; X=e; X=d; X=f; false

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 Databases Questions!