Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a Python program that emulates the behavior of the Prolog family.pro program below: You will need to only emulate queries that have at all

Write a Python program that emulates the behavior of the Prolog "family.pro" program below: You will need to only emulate queries that have at all but one of the arguments known. This means that for something like ?-cousin_of('Marie',Who). you will have a query like: >> list(cousin_of('Marie')) >> for Who in cousin_of('Marie') : print(Who) You can uses "yield" to return multiple answers, as needed.

family.pro:

c:-['family.pro'].

% facts

male('Joe'). male('Bill'). male('Paul').

female('Marie'). female('Helen'). female('Miranda').

parent_of('Joe','Helen'). parent_of('Joe','Bill'). parent_of('Marie','Helen'). parent_of('Marie','Bill'). parent_of('Bill','Mike'). parent_of('Helen','Adam'). parent_of('Paul','Miranda'). parent_of('Miranda','Mike').

% rules sibling_of(X,S):-parent_of(X,P),parent_of(S,P),X\==S.

brother_of(X,B):-sibling_of(X,B),male(B).

sister_of(X,S):-sibling_of(X,S),female(S).

mother_of(X,M):-parent_of(X,M),female(M).

father_of(X,M):-parent_of(X,M),male(M).

gp_of(X,GP):-parent_of(X,P),parent_of(P,GP).

cousin_of(X,C):- gp_of(X,GP), gp_of(C,GP), X\==C, not(sibling_of(X,C)).

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

Data And Databases

Authors: Jeff Mapua

1st Edition

1978502257, 978-1978502253

More Books

Students also viewed these Databases questions