Concepts of Programming Languages, Spring 2014 Practice Assignment1 Discussion:

Similar documents
The Language of First-Order Predicate Logic

TRANSLATIONS IN SENTENTIAL LOGIC

PARTICIPIAL PHRASES: EXERCISE #1

Your English Podcasts. Vocabulary and Fluency Building Exercises. Pack 1-5. Scripts - Version for Mobile Devices (free)

English Listening and Speaking Patterns 2

Fungsi sosial Menjalin hubungan dengan guru, teman dan orang lain Ungkapan. My name is... I m... I live in... I have I like.

Actual MH CET Test Name Actual MH CET 2016 Total Questions 200 Total Time 150 Mins

Introduction p. 1 The Elements of an Argument p. 1 Deduction and Induction p. 5 Deductive Argument Forms p. 7 Truth and Validity p. 8 Soundness p.

1 Look at the pictures and read about three families from around the world. Underline the family words.

READING Introducing Will Smith!

UNIT 1. The Individual and Society. Personal Identification. 4. Complete the instructions with a verb. 1. Write the missing letters.

Independent and Subordinate Clauses

The high C that ends the major scale in Example 1 can also act as the beginning of its own major scale. The following example demonstrates:

MUSIC PRODUCTION AUDITI ON F ORM

ITU-T Y.4552/Y.2078 (02/2016) Application support models of the Internet of things

CSC384: Intro to Artificial Intelligence Knowledge Representation IV

Lesson 5: Using the Identity and Inverse to Write Equivalent Expressions

1. Introduction. Abstract. 1.1 Logic Criteria

J.t. lambert s Musical Theatre Production. ***You must have already turned in your completed Audition Form!!!*** Included in this packet:

Practice with PoP: How to use Publish or Perish effectively? Professor Anne-Wil Harzing Middlesex University

Introduction to Sentence Structures

First Order Logic. Xiaojin Zhu Computer Sciences Department University of Wisconsin, Madison. [Based on slides from Burr Settles]

JUDSON. Teacher Booktalks: An Examination of Motivational Influence on Intermediate Grade Readers. Follow Us on Twitter stevenlayne and benzulau 2

Achieving Faster Time to Tapeout with In-Design, Signoff-Quality Metal Fill

Unit 1 People FEATURES. 1 Look at the photo and the caption. Where is the explorer? What is the photographer s name? 10 Explorers

Person 2 person GRAMMAR AND READING. I m from Barcelona. and

STUDY GUIDE. a midsummer night's dream William Shakespeare

S2 Homework Workbook Understanding Music. Listening & Literacy. Name: Class: Replacement Copy Cost: 50p. S2 Homework Workbook pg.

Essay pleasure of college life >>>CLICK HERE<<<

Lecture 3: Nondeterministic Computation

Grammar. Name: 1 Underline the correct words.

GENDER EQUALITY COMMISSION Strasbourg, April Gender Equality in Eurimages

Presenting the Final report

Unit 6. of Anna s family members in the correct spaces in the family tree. Look at the box with

BBC LEARNING ENGLISH 6 Minute Vocabulary Jobs suffixes

ADVERBS MODIFYING VERBS

PAGE HEADERS AND FOOTERS

A BRIDGE OVER THE ATLANTIC OCEAN

UNIVERSITY OF MASSACHUSETTS Department of Biostatistics and Epidemiology BioEpi 540W - Introduction to Biostatistics Fall 2002

CSE221- Logic Design, Spring 2003

Fifteenth Annual University of Oregon Eugene Luks Programming Competition

SIP Project Report Format

C overs R are B ooks. Faith Baldwin Rich Girl, Poor Girl New York: Farrar & Rinehart, Inc. (1938) $350

UNIT 1. The Individual and Society. Neighbours. 3. Complete the sentences with the words below. 1. Write the missing letters.

The Blonde, The Brunette & The Vengeful Redhead By arrangement with the Author

Stars in my eyes! Name:... Date:... Class:... Find and stick pictures of your favourite stars from around the world. Then, write.

UNIT 4. LOOKING GOOD SUMMIT 1 REVIEW & EXTRA PRACTICE

Product/Process Change Notice (PCN) Major change Minor change

Lesson 65: Home Services (20-25 minutes)


to believe all evening thing to see to switch on together possibly possibility around

Symbolization and Truth-Functional Connectives in SL

Aristotle s Metaphysics

Adult Initial Questionnaire

Margherita. The Production. By Rurik Seven A Mage Plays Production

The following references and the references contained therein are normative.

ITU-T Y Specific requirements and capabilities of the Internet of things for big data

Title of the Project

In this project, we wish to create a database to store and analyze television show ratings data for the top 20 most-watched shows in a given week.

LIBRARY ORIENTATION. Office of Library and Information Technology

Introduction to APA Citation

Really Good Stuff Activity Guide Writers At Work Poster Set

Crucible Act Two Literary Analysis Skill Builder

ENCYCLOPEDIA DATABASE

Failure to acknowledge sources or how to plagiarise - 1. Referencing and references. Failure to acknowledge sources or how to plagiarise - 2

Q516 HIGH RES AUDIO DELAY ORDERING OPTIONS SUPPORT OPTIONS MANAGEMENT AND CONTROL HIGH PRECISION AUDIO DELAY FOR MICRO SECOND ACCURACY

CAP240 First semester 1430/1431. Sheet 4

London Life Hollywood star on London stage

(Class-IV) D.A.V. College Managing Committee. Publication Division. Chitra Gupta Road, New Delhi

1 The structure of this exercise

Subtitle Safe Crop Area SCA

In this paper, the issues and opportunities involved in using a PDA for a universal remote

Formatting Instructions for Advances in Cognitive Systems

A Pleasant Evening. Listening Comprehension Lesson Plan

UNIT 1: My Family and neighbor.

Language and Mind Prof. Rajesh Kumar Department of Humanities and Social Sciences Indian Institute of Technology, Madras

Step by Step: Format a Research Paper GET READY. Before you begin these steps, be sure to launch Microsoft Word. Third line: History 101

67. LEVEL TRANSITION FROM LEVEL NTC TO LEVEL 1 (SYSTEM VERSION 2.Y)

Background Information. Instructions. Problem Statement. HOMEWORK INSTRUCTIONS Homework #5 Nielsen Television Ratings Problem

This document describes the GUIs and menu operations of the self-service attendance terminal. Not all the devices have the function with.

Tape. Tape head. Control Unit. Executes a finite set of instructions

Calculating Attainment 8 - Answers

ENGINEERING COMMITTEE Interface Practices Subcommittee AMERICAN NATIONAL STANDARD ANSI/SCTE

Emergence of Cooperation Through Mutual Preference Revision

Musical Harmonization with Constraints: A Survey. Overview. Computers and Music. Tonal Music

Subjects & Predicates. Project LA Activity

Theatre Guild, Inc. collection regarding William Saroyan's Love's Old Sweet Song

SCHOOL OF LAW Legal Methods & Skills Professor Murphy s Style Guide for Assessed Coursework

Strong african american women monologues

Minimailer 4 OMR SPECIFICATION FOR INTELLIGENT MAILING SYSTEMS. 1. Introduction. 2. Mark function description. 3. Programming OMR Marks

What are MLA, APA, and Chicago/Turabian Styles?

A. Good morning, how s life?

Unit 7. Exercise 1. Listening Activity: Taking a Test about International Tourist Destinations, p.

Terminal Time: An Ideologically-biased History Machine

Privacy, Playreading, and Women s Closet Drama, (review)

Unit 1: Listening and Understanding in Greek. Thursday 16 June 2011 Afternoon Time: 45 minutes and 5 minutes reading time

Mallrats: Mirror Image. kathryn chinn tania choi jessica cohen john wong

6.034 Notes: Section 4.1

NECK WINGS TAIL HORN BACK SCALES FEATHERS

Logic Riddles. I'm where yesterday follows today and tomorrow is in the middle. What am I? Everyone has me but nobody can lose me. What am I?

Transcription:

German University in Cairo Media Engineering and Technology Prof. Dr. Slim Abdennadher Concepts of Programming Languages, Spring 2014 Practice Assignment1 Discussion: 22.02.2014-27.02.2014 Exercise 1-1 Movies The supplied file movies.pl includes a database of movies specified by 4 different predicates: movie(m,y). % movie M was produced in year Y director(m,d). % movie M was directed by director D actor(m,a,r). % actor A played role R in movie M actress(m,a,r). % actress A played role R in movie M a) Implement the queries that answer the following questions: 1. What is the production year of the movie American Beauty??- movie(american_beauty,y).?- movie(n,y),n=american_beauty. 2. Find a movie that was produced in the year 2000.?- movie(n,2000).?- movie(m,y),y=2000. 3. Find a movie that was produced before the year 2000.?- movie(n,y),y<2000. 4. Find the name and year of a movie.?- movie(n,y). 5. Find a director who has directed a movie in which the actress Scarlett Johansson appeared.?- actress(m,scarlett_johansson,_), director(m,d).?- actress(m,a,_), director(m,d),a=scarlett_johansson. 1

6. Find an actor who has also directed a movie.?- actor(_,a,_),director(_,a). 7. Find an actor who has appeared in more than one movie.?- actor(m1,a,_),actor(m2,a,_),m1\=m2. 8. Find an actor or actress who has also directed a movie (You may use disjunction).?- director(_,a),(actor(_,a,_);actress(_,a,_)). Note: It is necessary to add parentheses around the disjunction in this example. Without them, Prolog would give a higher precedence to the logical-and and that will not correspond to our intent. b) Implement the following Prolog predicates: 1. same_year_as(m1,m2) succeeds if movie M1 was produced in the same year as movie M2. same_year_as(m1,m2):- movie(m1,y), movie(m2,y), M1\=M2. 2. cast_member(a,m) succeeds if person A was an actor or actress in movie M (write 2 rules). cast_member(a,m):- actor(m,a,_). cast_member(a,m):- actress(m,a,_). 3. cast_member2(a,m) succeeds if person A was an actor or actress in movie M (write a single rule). cast_member2(a,m):- actor(m,a,_); actress(m,a,_). 4. directed_by(x,y) succeeds if person X has been in a movie directed by person Y. directed_by(x,y):- director(m,y), cast_member(x,m). 5. released_since(m,y) succeeds if movie M was produced during or after year Y. released_since(m,y):- movie(m,year), Year>=Y. 6. newer(m1,m2) succeeds if movie M1 was produced after movie M2. newer(m1,m2):- movie(m1,y1), movie(m2,y2), Y1>Y2. 2

7. released_between(m,y1,y2) succeeds if movie M was produced between year Y1 and year Y2 inclusively. released_between(m,y1,y2):- movie(m,year), Year>=Y1. Year=<Y2. c) What is the difference between the three queries below??- actor(m1,d,_),actor(m2,d,_).?- actor(m1,d,_),actor(m2,d,_),m1\=m2.?- actor(m1,d,_),actor(m2,d,_),m1@<m2. The first query produces all possible combinations of results, including the case where M1 is the same as M2; whereas in the second query, the problem is solved by adding the constraint that M1 cannot be the same as M2. However, the second query still has redundancies as it displays the results of two distinct movies twice, in the second time M1 is bound to the second movie and M2 is bound to the first one. The third query allows the display of two different movies only if M1 lexicographically precedes M2, and hence solves the problem of the second query. 3

Exercise 1-2 Family We are going to add some new predicates to the family database family.pl. The database is specified by 3 different predicates: parent(x,y) % person X is the parent of person Y. male(x) % person X is a male. husband(x,y) % person X is the husband of person Y. Your task is to implement the following Prolog predicates: a) female(a): A is a female person. female(x) :- \+ male(x). b) grandfather(a,b): A is the grandfather of B. grandfather(x,y) :- father(x,p), parent(p,y). c) grandmother(a,b): A is a grandmother of B. grandmother(x,y) :- parent(x,p), \+male(x). d) brother(a,b): A is the brother of B. brother(x,y) :- parent(p,x), male(x), e) uncle(a,b): A is the uncle of B. uncle(x,y) :- brother(x,p), parent(p,y). f) sister(a,b): A is the sister of B. sister(x,y) :- parent(p,x), female(x), 4

g) has_son(a): The person A has a son. has_son(x) :- parent(x,y), male(y). h) married(a,b): A and B are married to each other. married(x,y) :- husband(x,y). married(x,y) :- husband(y,x). i) siblings(a,b): A and B are siblings (both parents in common) siblings(x,y) :- parent(z,x), parent(z,y), male(z), parent(m,x), parent(m,y), female(m), j) cousins(a,b): A and B are cousins cousins(x,y) :- parent(a,x), parent(b,y), siblings(a,b), k) no_children(a): A has no children no_children(x) :- \+ parent(x,_). no_children(x) :- married(x,y), \+parent(y,_). l) brother_in_law(a,b): A is the brother-in-law of B. brother_in_law(x,y) :- brother(x,p), married(p,y). brother_in_law(x,y) :- husband(x,w), sister(w,y). Hint: Insert new facts about your own parents and other relatives to see if the predicates work as expected! 5