In this assignment, 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 Filename: ID.py ID Name GPA Program City Ahmed 3.56 BS-CS Gujranwala 123 Zahid 2.85 BS-SE Lahore 456 Baber 3.70 BS-DS Gujranwala 789 Shahid 2.99 BS-CS Gujranwala 321 Jamal 3.33 BS-DS Lahore 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 AI 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 (ID.pdf) that describes the logie of your solution. Make sure to describe all main steps that your code uses to find the answers of the given questions.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
100%

In this assignment, 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 Filename: ID.py

ID Name GPA  Program City
123 Ahmed 3.56 BS-CS Gujranwala
456 Zahid 2.85 BS-SE Lahore
789 Baber 3.70 BS-DS Gujranwala
321 Shahid 2.99 BS-CS Gujranwala
654 Jamal 3.33 BS-DS Lahore


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 AI 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 (ID.pdf) 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.

 

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('\n' + output + ' is the owner of the rabbit')
print('\nHere are all the details:')
attribs = ['Name', 'Pet', 'Color', 'Country']
print('\n' + '\t\t'.join(attribs))
print('=' * 57)
for item in solutions[0]:
print('')
print('\t\t'.join([str(x) for x in item]))

 

In this assignment, 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 Filename: ID.py
ID
Name
GPA
Program
City
Ahmed
3.56
BS-CS
Gujranwala
123
Zahid
2.85
BS-SE
Lahore
456
Baber
3.70
BS-DS
Gujranwala
789
Shahid
2.99
BS-CS
Gujranwala
321
Jamal
3.33
BS-DS
Lahore
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 AI 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 (ID.pdf) that describes the logie of your solution. Make sure to describe all main steps that
your code uses to find the answers of the given questions.
Transcribed Image Text:In this assignment, 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 Filename: ID.py ID Name GPA Program City Ahmed 3.56 BS-CS Gujranwala 123 Zahid 2.85 BS-SE Lahore 456 Baber 3.70 BS-DS Gujranwala 789 Shahid 2.99 BS-CS Gujranwala 321 Jamal 3.33 BS-DS Lahore 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 AI 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 (ID.pdf) that describes the logie of your solution. Make sure to describe all main steps that your code uses to find the answers of the given questions.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 6 images

Blurred answer
Knowledge Booster
Public key encryption
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education