Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Here is the code file which you have to use to solve the above problem: puzzle.py: from kanren import * from kanren.core import lall #

image text in transcribed

Here is the code file which you have to use to solve the above problem:

puzzle.py:

from kanren import * from kanren.core import lall

# Declare the variable people = var()

# Define the rules rules = lall( # There are 4 people (eq, (var(), var(), var(), var()), people),

# Steve's car is blue (membero, ('Steve', var(), 'blue', var()), people),

# Person who owns the cat lives in Canada (membero, (var(), 'cat', var(), 'Canada'), people),

# Matthew lives in USA (membero, ('Matthew', var(), var(), 'USA'), people),

# The person who has a black car lives in Australia (membero, (var(), var(), 'black', 'Australia'), people),

# Jack has a cat (membero, ('Jack', 'cat', var(), var()), people),

# Alfred lives in Australia (membero, ('Alfred', var(), var(), 'Australia'), people),

# Person who owns the dog lives in France (membero, (var(), 'dog', var(), 'France'), people),

# Who is the owner of the rabbit? (membero, (var(), 'rabbit', var(), var()), people) )

# Run the solver solutions = run(0, people, rules)

# Extract the output output = [house for house in solutions[0] if 'rabbit' in house][0][0]

# Print the output print(' ' + output + ' is the owner of the rabbit') print(' Here are all the details:') attribs = ['Name', 'Pet', 'Color', 'Country'] print(' ' + '\t\t'.join(attribs)) print('=' * 57) for item in solutions[0]: print('') print('\t\t'.join([str(x) for x in item]))

you will need to write an agent that uses logical inference to find the answers to the given questions based on the data given in the below table: 1. Python Code ID GPA 123 456 Name Ahmed Zahid Baber Shahid Jamal 3.56 2.85 3.70 2.99 3.33 Program BS-CS BS-SE BS-DS BS-CS BS-DS City Gujranwala Lahore Gujranwala Gujranwala Lahore 789 321 654 Use the given code puzzle.py and amend the code so that it finds the answer to these questions: a. Who lives in Lahore? b. Who studies in the BS-DS program? c. Who has the minimum GPA and who has the maximum GPA? You are restricted to using only the kanren logical Al library and the given code for the Logical Programming lectures. You may use any mathematical library (if needed) for any math related work 2. Write a report that describes the logic of your solution. Make sure to describe all main steps that your code uses to find the answers of the given questions

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

Database Design And Relational Theory Normal Forms And All That Jazz

Authors: Chris Date

1st Edition

1449328016, 978-1449328016

More Books

Students also viewed these Databases questions