Docsity

PROLOG: Defining Family Predicates & Merging Sorted Lists, Assignments of Programming Languages

Toggle sidebar
bg1
UCF
School of Computer Science
COP 4020: Programming Languages
Summer 2006
Homework 3 (PROLOG)
Due on 07/28/06 by 11:59pm
Instructions
This assignment will be due on Friday, July 28 at 11:59pm. It will only be accepted late
within 24 hours of the due date at a loss of 30%, after which it will not be accepted.
Email to [email protected]. To turn in, put all of your predicates in a file named by a
concatenation of your first initial and last name with an extension “.prl”. Example: John
Doe would turn in jdoe.prl. Please write all of you own predicates. The only exception to
this is that you may use the built in predicate not. If you need “helper” functions, please
include them in your file.
Problem 1: Define predicates for “simple” family information
All binary predicates of form predicate(A,B) in this exercise can be read as A is
predicate of B, unless otherwise noted.
For this exercise you will be given a knowledge base containing info for three predicates:
parent/2, female/1, and male/1.
You need to define the following predicates that will work for any family knowledge
base:
• mother/2
• brother/2
• niece/2
• cousin/2
• grandparent/2
pf2

Partial preview of the text

Download PROLOG: Defining Family Predicates & Merging Sorted Lists and more Assignments Programming Languages in PDF only on Docsity!

UCF

School of Computer Science

COP 4020: Programming Languages

Summer 2006

Homework 3 (PROLOG)

Due on 07/28/06 by 11:59pm

Instructions

This assignment will be due on Friday, July 28 at 11:59pm. It will only be accepted late within 24 hours of the due date at a loss of 30%, after which it will not be accepted. Email to [email protected]. To turn in, put all of your predicates in a file named by a concatenation of your first initial and last name with an extension “.prl”. Example: John Doe would turn in jdoe.prl. Please write all of you own predicates. The only exception to this is that you may use the built in predicate not. If you need “helper” functions, please include them in your file.

Problem 1 : Define predicates for “simple” family information

All binary predicates of form predicate(A,B) in this exercise can be read as A is p redicate of B, unless otherwise noted. For this exercise you will be given a knowledge base containing info for three predicates: parent/2, female/1, and male/1. You need to define the following predicates that will work for any family knowledge base:

  • mother/
  • brother/
  • niece/
  • cousin/
  • grandparent/

Example knowledge base parent(alice,betty). parent(alice,bob). parent(alice,ricky). parent(rebecca,alice). parent(castro,betty). parent(castro,bob). parent(castro,ricky). parent(dana,castro). parent(dana,vince). parent(vince,erma). male(ricky). male(vince). male(bob). male(castro). female(alice). female(betty). female(dana). female(erma). female(rebecca). Note! If you are going to test with your own KB (which is recommended!), be sure to define the gender of each person. Also, be sure that no one is their own brother or sister.

Problem 2 : Merge non-decreasing lists

Define a predicate merge/3 that takes two non-decreasing sorted lists and merges them into a single sorted lists. It should also remove duplicates in the list. Here’s an example: ?- merge([2, 4, 6], [1, 2, 3, 4, 5], list). list = [1, 2, 3, 4, 5, 6]