LING 388: Language and Computers Sandiway Fong Lecture 6.

Slides:



Advertisements
Similar presentations
PROLOG 8 QUEENS PROBLEM.
Advertisements

E-2020 Science Classes New Year 2012 Procedures. Vocabulary Write each vocabulary word Each definition, in your own words if possible Draw a picture to.
LING 388: Language and Computers Sandiway Fong Lecture 5: 9/5.
LING 364: Introduction to Formal Semantics Lecture 24 April 13th.
LING 388: Language and Computers Sandiway Fong Lecture 5: 9/8.
LING/C SC/PSYC 438/538 Computational Linguistics Sandiway Fong Lecture 13: 10/9.
LING 388: Language and Computers Sandiway Fong Lecture 9: 9/27.
LING 388: Language and Computers Sandiway Fong 9/29 Lecture 11.
LING 388: Language and Computers Sandiway Fong Lecture 2: 8/24.
LING 388: Language and Computers Sandiway Fong Lecture 2: 8/25.
LING 364: Introduction to Formal Semantics Lecture 8 February 7th.
LING 438/538 Computational Linguistics Sandiway Fong Lecture 3: 8/29.
LING 438/538 Computational Linguistics Sandiway Fong Lecture 7: 9/12.
LING 388: Language and Computers Sandiway Fong Lecture 12: 10/5.
LING/C SC/PSYC 438/538 Computational Linguistics Sandiway Fong Lecture 7: 9/11.
LING 388 Language and Computers Lecture 8 9/25/03 Sandiway FONG.
LING 388: Language and Computers Sandiway Fong Lecture 28: 12/6.
LING 364: Introduction to Formal Semantics Lecture 4 January 24th.
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 Lecture 4 9/11/03 Sandiway FONG.
LING 388: Language and Computers Sandiway Fong Lecture 9: 9/21.
LING 388: Language and Computers Sandiway Fong Lecture 6: 9/13.
LING 388: Language and Computers Sandiway Fong Lecture 4: 8/31.
LING 388: Language and Computers Sandiway Fong Lecture 11: 10/3.
LING 388: Language and Computers Sandiway Fong Lecture 3: 8/29.
LING 438/538 Computational Linguistics Sandiway Fong Lecture 6: 9/7.
© 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 438/538 Computational Linguistics Sandiway Fong Lecture 12: 10/5.
LING 364: Introduction to Formal Semantics Lecture 3 January 19th.
LING 388 Language and Computers Lecture 18 10/30/03 Sandiway FONG.
LING 388 Language and Computers Lecture 11 10/7/03 Sandiway FONG.
LING 388: Language and Computers Sandiway Fong Lecture 10: 9/26.
LING 388 Language and Computers Lecture 7 9/23/03 Sandiway FONG.
LING 388: Language and Computers Sandiway Fong Lecture 4: 9/1.
LING 438/538 Computational Linguistics Sandiway Fong Lecture 5: 9/5.
LING 388: Language and Computers Sandiway Fong Lecture 7: 9/12.
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 Lecture 15 10/21/03 Sandiway FONG.
LING 388: Language and Computers Sandiway Fong Lecture 8.
LING 388: Language and Computers Sandiway Fong 10/4 Lecture 12.
LING 388: Language and Computers Sandiway Fong Lecture 17.
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 4.
LING 388: Language and Computers Sandiway Fong Lecture 7.
Recursion A method is recursive if it makes a call to itself. A method is recursive if it makes a call to itself. For example: For example: public void.
LING 388: Language and Computers Sandiway Fong Lecture 30 12/8.
CMPS 1371 Introduction to Computing for Engineers RECURSION.
LING 388: Language and Computers Sandiway Fong Lecture 7 9/15.
LING 388: Language and Computers Sandiway Fong Lecture 18.
LING/C SC/PSYC 438/538 Lecture 12 10/4 Sandiway Fong.
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.
LING 388: Language and Computers Sandiway Fong 9/27 Lecture 10.
LING 388: Language and Computers Sandiway Fong Lecture 25.
LING/C SC/PSYC 438/538 Lecture 15 Sandiway Fong. Did you install SWI Prolog?
LING/C SC/PSYC 438/538 Lecture 16 Sandiway Fong. SWI Prolog Grammar rules are translated when the program is loaded into Prolog rules. Solves the mystery.
CS 554: Knowledge base systems Part-4: Prolog- 2 By Dr. Syed Noman Hasany.
In The Name Of Allah Lab 03 1Tahani Aldweesh. objectives Searching for the solution’s. Declaration. Query. Comments. Prolog Concepts. Unification. Disjunction.
1 Artificial Intelligence CS370D Prolog programming List operations.
07/10/04 AIPP Lecture 5: List Processing1 List Processing Artificial Intelligence Programming in Prolog Lecturer: Tim Smith Lecture 5 07/10/04.
Artificial Intelligence Programming ,Spring 2016
Chapter 11 :: Logic Languages
CSE 311: Foundations of Computing
Chapter 12 :: Logic Languages
Chapter 12 :: Logic Languages
Presentation transcript:

LING 388: Language and Computers Sandiway Fong Lecture 6

Administrivia Today’s Topics 1.Homework 2 review 2.Lists(Chapter 4 of learnprolognow.org) Lab Exercises

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? Query: jealous(A,B), \+ A = B.

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? Rule: jealous(A,B) :- loves(A,C), loves(B,C), \+ A = B. Query : jealous(A,B).

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? 1.[X,Z,_,Z,X] 2.[X,Z,Z,X]

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. Query: Word = [r,a,c,e,c,a,r], reverse(Word,Word).

Homework Exercise 4 Extra Credit. Write a rule and query (or query) that solves the following puzzle: H1V1H1V2 H1V3 H2V1H2V2 H2V3 H3V1H3V2 H3V3 Constraint is:

Homework Exercise 4 Extra Credit. Write a rule and query (or query) that solves the following puzzle: H1V1H1V2 H1V3 H2V1H2V2 H2V3 H3V1H3V2 H3V3

Homework Exercise 4 Final program: put all the constraints together.

Homework Exercise 4 Solution 1:Solution 2:

Last Time Recursive definitions: – Base case – Recursive case Example: factorial(0,1). factorial(N,F) :- N > 0, N1 is N-1, factorial(N1,F1), F is N*F1. Example: length_of([],0). length_of([_|List],Len) :- length_of(List,N), Len is N+1. Example: numeral(0). numeral(succ(X)) :- numeral(X). base case recursive case steps down from N to N1 steps down from [_|List] to List steps down from succ(X) to X

member Example: – list [1,3,5] – ask: is 5 a member of this list?(Yes: true) – ask: is 4 a member of this list?(No: false) In Prolog: member(X,[X|T]). member(X,[H|T]) :- member(X,T). Queries: ?- member(yolanda,[yolanda,trudy,vincent,jules]). ?- member(vincent,[yolanda,trudy,vincent,jules]). ?- member(X,[yolanda,trudy,vincent,jules]). built-in in SWI-Prolog

Exercise 1 Same number of a’s and b’s 4.3 Recursing down Lists Let’s suppose we need a predicate a2b/2 that takes two lists as arguments, and succeeds if the first argument is a list of a’s, and the second argument is a list of b’s of exactly the same length. Examples: – ?- a2b([a,a,a,a],[b,b,b,b]).true – ?- a2b([a,a,a,a],[b,b,b]).false – ?- a2b([a,c,a,a],[b,b,5,4]).false

Exercise 1 Same number of a’s and b’s Part 1: what is the base case? – In an empty list, we have the same number of a’s and b’s… – Write the Prolog code

Exercise 1 Same number of a’s and b’s Part 2: what is the recursive case? – Given two lists [X|L1] for a’s and [Y|L2] for b’s, what needs to be recursively true… – Write the Prolog code

Exercise 2 Exercise 4.5: database tran(eins,one). tran(zwei,two). tran(drei,three). tran(vier,four). tran(fuenf,five). tran(sechs,six). tran(sieben,seven). tran(acht,eight). tran(neun,nine). Write a predicate listtran(G,E) which translates a list of German number words to the corresponding list of English number words. For example: ?- listtran([eins,neun,zwei],X). X = [one,nine,two] ?- listtran(X,[one,seven,six,two]). X = [eins,sieben,sechs,zwei]

Exercise 2 German/English word list translation Part 1: what is the base case? – The empty list … – Write the Prolog code

Exercise 2 German/English word list translation Part 2: what is the recursive case? – Given two lists [G|L1] for German and [E|L2] for English, what needs to be recursively true… – Write the Prolog code