LING 388: Language and Computers Sandiway Fong Lecture 4.

Slides:



Advertisements
Similar presentations
© Johan Bos Logic Programming About the course –Taught in English –Tuesday: mostly theory –Thursday: practical work [lab] Teaching material –Learn Prolog.
Advertisements

© Patrick Blackburn, Johan Bos & Kristina Striegnitz Lecture 10: Cuts and Negation Theory –Explain how to control Prolog`s backtracking behaviour with.
Lecturer: Dr. Abeer Mahmoud Logic Programming in Prolog.
Prolog.
© Patrick Blackburn, Johan Bos & Kristina Striegnitz Lecture 6: More Lists Theory –Define append/3, a predicate for concatenating two lists, and illustrate.
LING 388: Language and Computers Sandiway Fong Lecture 5: 9/5.
© Patrick Blackburn, Johan Bos & Kristina Striegnitz Lecture 6: More Lists Theory –Define append/3, a predicate for concatenating two lists, and illustrate.
Prolog: List © Patrick Blackburn, Johan Bos & Kristina Striegnitz.
LING 388: Language and Computers Sandiway Fong Lecture 5: 9/8.
1 Logic Programming. 2 A little bit of Prolog Objects and relations between objects Facts and rules. Upper case are variables. parent(pam, bob).parent(tom,bob).
LING 388: Language and Computers Sandiway Fong Lecture 2: 8/24.
LING 388: Language and Computers Sandiway Fong Lecture 2: 8/25.
CSE 425: Logic Programming I Logic and Programs Most programs use Boolean expressions over data Logic statements can express program semantics –I.e., axiomatic.
For Friday Read “lectures” 1-5 of Learn Prolog Now: prolog-now/
LING 438/538 Computational Linguistics Sandiway Fong Lecture 3: 8/29.
© Patrick Blackburn, Johan Bos & Kristina Striegnitz Lecture 10 Exercises –Solutions to Exercises of LPN chapter 9 Theory –Explain how to control Prolog`s.
LING 388 Language and Computers Lecture 2 9/04/03 Sandiway FONG.
© Patrick Blackburn, Johan Bos & Kristina Striegnitz Logic Programming About the course –Taught in English –Tuesday: mostly theory –Thursday: practical.
LING 388 Language and Computers Lecture 3 9/09/03 Sandiway FONG.
LING/C SC/PSYC 438/538 Computational Linguistics Sandiway Fong Lecture 6: 9/6.
LING 388: Language and Computers Sandiway Fong Lecture 6: 9/7.
LING 388: Language and Computers Sandiway Fong Lecture 9: 9/21.
LING 388: Language and Computers Sandiway Fong Lecture 4: 8/31.
LING 388: Language and Computers Sandiway Fong Lecture 3: 8/29.
© Patrick Blackburn, Johan Bos & Kristina Striegnitz Lecture 4: Lists Theory –Introduce lists, an important recursive data structure often used in Prolog.
LING 388 Language and Computers Take-Home Final Examination 12/9/03 Sandiway FONG.
LING 388: Language and Computers Sandiway Fong Lecture 3: 8/28.
© Patrick Blackburn, Johan Bos & Kristina Striegnitz Lecture 2 Theory –Unification –Unification in Prolog –Proof search Exercises –Correction exercises.
CIS101 Introduction to Computing Week 11. Agenda Your questions Copy and Paste Assignment Practice Test JavaScript: Functions and Selection Lesson 06,
LING 364: Introduction to Formal Semantics Lecture 3 January 19th.
LING 388 Language and Computers Lecture 18 10/30/03 Sandiway FONG.
© Patrick Blackburn, Johan Bos & Kristina Striegnitz Lecture 9: A closer look at terms Theory –Introduce the == predicate –Take a closer look at term structure.
LING 388: Language and Computers Sandiway Fong Lecture 4: 9/1.
CIS101 Introduction to Computing Week 12 Spring 2004.
1 LING 438/538 Computational Linguistics Sandiway Fong Lecture 4: 8/31.
LING 388: Language and Computers Sandiway Fong Lecture 13: 10/10.
© Patrick Blackburn, Johan Bos & Kristina Striegnitz Lecture 4: Lists Theory –Introduce lists, an important recursive data structure often used in Prolog.
LING 388: Language and Computers Sandiway Fong Lecture 8.
© Patrick Blackburn, Johan Bos & Kristina Striegnitz Horn clauses A literal is an atomic formula or its negation A clause is a disjunction of literals.
Formal Models of Computation Part II The Logic Model
CSC 270 – Survey of Programming Languages Prolog Lecture 1 – Facts, Rules, and Queries.
LING 388: Language and Computers Sandiway Fong Lecture 22: 11/10.
LING 388: Language and Computers Sandiway Fong Lecture 5.
LING 388: Language and Computers Sandiway Fong Lecture 7.
IPC144 Introduction to Programming Using C Week 1 – Lesson 2
LING 388: Language and Computers Sandiway Fong Lecture 3.
LING 388: Language and Computers Sandiway Fong Lecture 6.
30/09/04 AIPP Lecture 3: Recursion, Structures, and Lists1 Recursion, Structures, and Lists Artificial Intelligence Programming in Prolog Lecturer: Tim.
For Wednesday Read “lectures” 7-10 of Learn Prolog Now Chapter 9, exs 4 and 6. –6 must be in Horn clause form Prolog Handout 2.
CSC 270 – Survey of Programming Languages Prolog Lecture 2 – Unification and Proof Search.
CS 330 Programming Languages 11 / 13 / 2008 Instructor: Michael Eckmann.
Chapter Three: Lists, Operators, Arithmetic 1. © Patrick Blackburn, Johan Bos & Kristina Striegnitz Important things about lists  List elements are enclosed.
1 Prolog and Logic Languages Aaron Bloomfield CS 415 Fall 2005.
PROLOG SYNTAX AND MEANING Ivan Bratko University of Ljubljana Faculty of Computer and Info. Sc. Ljubljana, Slovenia.
Introduction to Prolog. Outline What is Prolog? Prolog basics Prolog Demo Syntax: –Atoms and Variables –Complex Terms –Facts & Queries –Rules Examples.
© Patrick Blackburn, Johan Bos & Kristina Striegnitz Lecture 9: A closer look at terms Theory –Introduce the == predicate –Take a closer look at term structure.
Introduction to Prolog © Patrick Blackburn, Johan Bos & Kristina Striegnitz.
LING/C SC/PSYC 438/538 Lecture 15 Sandiway Fong. Did you install SWI Prolog?
Programming Language Concepts Lecture 17 Prepared by Manuel E. Bermúdez, Ph.D. Associate Professor University of Florida Logic Programming.
In The Name Of Allah Lab 03 1Tahani Aldweesh. objectives Searching for the solution’s. Declaration. Query. Comments. Prolog Concepts. Unification. Disjunction.
For Friday No reading Prolog Handout 2. Homework.
07/10/04 AIPP Lecture 5: List Processing1 List Processing Artificial Intelligence Programming in Prolog Lecturer: Tim Smith Lecture 5 07/10/04.
Thinking about programming Intro to Computer Science CS1510 Dr. Sarah Diesburg.
LING/C SC/PSYC 438/538 Lecture 19 Sandiway Fong 1.
1 CSC160 Chapter 1: Introduction to JavaScript Chapter 2: Placing JavaScript in an HTML File.
1 Artificial Intelligence CS370D Prolog programming Declarative meaning of Prolog programs and Lists representation.
1 Agenda  Unit 7: Introduction to Programming Using JavaScript T. Jumana Abu Shmais – AOU - Riyadh.
LING/C SC/PSYC 438/538 Lecture 19 Sandiway Fong.
© Patrick Blackburn, Johan Bos & Kristina Striegnitz
PROLOG.
Presentation transcript:

LING 388: Language and Computers Sandiway Fong Lecture 4

Administrivia Today’s Topics – want to make sure everyone is able to run SWI- Prolog – SWI-Prolog (6.6.6) on the mac – Introduction to Prolog contd. Lab class: Unification – Homework 2: due next Wednesday by midnight Ben Martin

SWI-Prolog app on Mac Two strikes against the SWI-Prolog app: 1.Default directory is / (root, non-writeable), not your home directory – fixable 2.Uses the X11 Window System (which runs under OSX) – very slow

SWI-Prolog App on Mac Takes two parameters: (1 st ) current working directory, (2 nd ) the new working directory

SWI-Prolog App on Mac

Takes a very long time to fire up because it fires up PCE-EMACS running under the X11 Window System Better options: aquamacs runs natively under OSX or use your favorite plain text editor

Prolog online resources Some background in logic or programming? Useful Online Tutorials – Learn Prolog Now! Patrick Blackburn, Johan Bos & Kristina Striegnitz – An introduction to Prolog Michel Loiseleur & Nicolas Vigier

SWI-Prolog Chapter 2 of Learn Prolog Now

Unification Data Types: Variables (begin with an uppercase letter): – e.g. X, Y3, Var… Atoms (numbers or begin with a lowercase letter): – e.g. x, var, (Complex) terms (functor + 1 or more arguments): – e.g. f(1,x), g(X), g(f(1,x)) Lists: – e.g. [](empty list) – [1,2,3](list containing three numbers) – [f(1),x,Y3](list containing a term, an atom and variable)

Unification Lists: – [] – [1,2,3]also can be written as [1|[2,3]] – Notation: [head|tail] vertical bar (|) separate the head of the list from the rest of the list, the tail. – So [1,2,3] is equal to (and unifiable with) [1|[2,3]] – i.e. [1,2,3] = [1|[2,3]]

Unification – Variables (begin with an uppercase letter): – e.g. X, Y3, Var… – Atoms (numbers or begin with a lowercase letter): – e.g. x, var, Single quotation marks: – ‘x’ = x – ’12.34’ – not a number, not unifiable with – ‘X’ – not a variable, ‘X’ is not equal to variable X but they are unifiable – single quote can be part of an atom: e.g. ‘\’s’ apostrophe s

Exercise 1 Using the Prolog interpreter, evaluate the following queries: 1.X = mia, X = vincent.(, = logical and, conjunction) 2.X = mia ; X = vincent. (; = logical or, disjunction) 3.X = Y. 4.[1,2,3] = [1|[2,3]] 5.[1,2,3] = [X|Y] 6.[1,2,3] = [X|[3]] 7.[1,2,3] = [X|[Y]] Note: if a list is too long, SWI Prolog uses … instead of printing the whole list. Type w to get the full display.

Exercise 2 Using the Prolog interpreter, evaluate the following queries with complex terms: 1.X = father(mia). 2.vincent = father(mia). 3.X = father(Y), Y = father(mia). 4.S = s(np(john),vp(v(likes),np(mary))), S = s(np(X),vp(v(Y),np(Z))).

Exercise 3 According to learnprolognow.org, this shouldn’t work in standard Prologs, try it: Try: 2.father(X) = X, father(Y) = Y, X = Y. 3.father(X) = Y, father(Y) = X.

Exercise 4 From section 2.2 on learnprolognow.org, try the following query: How many solutions are there?

For Homework Exercises You’ll make use of the following: 1.\+ is the negation operator: – vincent = mia.(false) – \+ vincent = mia.(true) – \+ (vincent = mia).- same as above 2.there’s a special variable _ (underscore), known as the anonymous variable. It doesn’t do anything and Prolog doesn’t report its value. – it’s used when you don’t want to give a variable a name or don’t care what it’s called… – Try: X = _, Y = _.

Homework Exercise 1 Consider Exercise 4 again. Assume one cannot be jealous of oneself. How would you change the rule or query so that this case is excluded from the answers? (show your code and query)

Homework Exercise 2 A word that’s a palindrome is spelt the same way backwards and forwards, e.g. kayak, radar or noon. We can check for “palindrome-hood” using Prolog lists. Run the queries: – [k,a,y,a,k] = [X,Z,Y,Z,X].(5 letter palindrome) – [c,a,n,o,e] = [X,Z,Y,Z,X]. 1.Where can we use the anonymous variable (_) in the palindrome check above? 2.What’s the four letter version of the palindrome check? (Give examples)

Homework Exercise 3 There’s a built-in predicate called reverse(List 1,List 2 ). Run the following queries: – reverse([1,2,3],[3,2,1]). – reverse([1,2,3],L). – reverse(L,[1,2,3]). Explain how you can use reverse/2 to check for palindromes of any length. (Give examples)

Homework Exercise 4 Extra Credit. Write a rule and query (or query) that solves the following puzzle: Hint: use the list representation