1 LING 438/538 Computational Linguistics Sandiway Fong Lecture 4: 8/31.

Slides:



Advertisements
Similar presentations
Artificial Intelligence: Natural Language and Prolog
Advertisements

CS4026 Formal Models of Computation Part II The Logic Model Lecture 6 – Arithmetic, fail and the cut.
Chapter 11 :: Logic Languages
Lecture 11: Datalog Tuesday, February 6, Outline Datalog syntax Examples Semantics: –Minimal model –Least fixpoint –They are equivalent Naive evaluation.
Logic Programming Automated Reasoning in practice.
LING 388: Language and Computers Sandiway Fong Lecture 5: 9/5.
11/10/04 AIPP Lecture 6: Built-in Predicates1 Combining Lists & Built-in Predicates Artificial Intelligence Programming in Prolog Lecturer: Tim Smith Lecture.
LING 388: Language and Computers Sandiway Fong Lecture 5: 9/8.
1 Introduction to Prolog References: – – Bratko, I., Prolog Programming.
LING/C SC/PSYC 438/538 Computational Linguistics Sandiway Fong Lecture 13: 10/9.
LING 388: Language and Computers Sandiway Fong Lecture 2: 8/24.
LING 388: Language and Computers Sandiway Fong Lecture 2: 8/25.
MB: 2 March 2001CS360 Lecture 31 Programming in Logic: Prolog Prolog’s Declarative & Procedural Semantics Readings: Sections
LING 581: Advanced Computational Linguistics Lecture Notes April 23rd.
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 Lecture 2 9/04/03 Sandiway FONG.
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering Controlling Backtracking Notes for Ch.5 of Bratko For CSCE 580 Sp03 Marco Valtorta.
LING 438/538 Computational Linguistics Sandiway Fong Lecture 9: 9/21.
LING 388 Language and Computers Lecture 8 9/25/03 Sandiway FONG.
LING 364: Introduction to Formal Semantics Lecture 4 January 24th.
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 6: 9/13.
LING 388: Language and Computers Sandiway Fong Lecture 4: 8/31.
LING/C SC/PYSC 438/538 Computational Linguistics
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.
LING 388 Language and Computers Take-Home Final Examination 12/9/03 Sandiway FONG.
LING 364: Introduction to Formal Semantics Lecture 3 January 19th.
Modal logic and databases. Terms Object terms Concept terms ↓ t: object denoted by concept t in some context Type designations: o (object) and c (concept)
1 CILOG User Manual Bayesian Networks Seminar Sep 7th, 2006.
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.
LING 388 Language and Computers Lecture 17 10/28/03 Sandiway FONG.
LING 388: Language and Computers Sandiway Fong Lecture 13: 10/10.
LING 388 Language and Computers Lecture 6 9/18/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 11.
Formal Models of Computation Part II The Logic Model
FATIH UNIVERSITY Department of Computer Engineering Controlling Backtracking Notes for Ch.5 of Bratko For CENG 421 Fall03.
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.
CS 321 Programming Languages and Compilers Prolog part 2.
LING 388: Language and Computers Sandiway Fong Lecture 3.
LING 388: Language and Computers Sandiway Fong Lecture 6.
LING 388: Language and Computers Sandiway Fong Lecture 7 9/15.
Cs7120 (Prasad)L16-Meaning1 Procedural and Declarative Meaning of Prolog
14/10/04 AIPP Lecture 7: The Cut1 Controlling Backtracking: The Cut Artificial Intelligence Programming in Prolog Lecturer: Tim Smith Lecture 7 14/10/04.
30/09/04 AIPP Lecture 3: Recursion, Structures, and Lists1 Recursion, Structures, and Lists Artificial Intelligence Programming in Prolog Lecturer: Tim.
15/11/04 AIPP Lecture 14: Database Manipulation1 Database Manipulation Artificial Intelligence Programming in Prolog Lecturer: Tim Smith Lecture 14 15/11/04.
CT214 – Logical Foundations of Computing Lecture 8 Introduction to Prolog.
CS Introduction to AI Tutorial 8 Resolution Tutorial 8 Resolution.
Logic Programming CSC 358/ Outline Pattern matching Unification Logic programming.
LING/C SC/PSYC 438/538 Lecture 13 Sandiway Fong. Administrivia Reading Homework – Chapter 3 of JM: Words and Transducers.
Negation Chapter 5. Stating Negative Conditions n Sometimes you want to say that some condition does not hold n Prolog allows this –not/1this is a predicate.
LING/C SC/PSYC 438/538 Lecture 18 Sandiway Fong. Adminstrivia Homework 7 out today – due Saturday by midnight.
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.
Prolog Fundamentals. 2 Review Last Lecture A Prolog program consists of a database of facts and rules, and queries (questions). –Fact:.... –Rule:... :-....
Recursive stack-based version of Back-chaining using Propositional Logic
Tests, Backtracking, and Recursion
LING 581: Advanced Computational Linguistics
Presentation transcript:

1 LING 438/538 Computational Linguistics Sandiway Fong Lecture 4: 8/31

2 Administrivia Homework 1 is due next Tuesday –please attempt it early as possible I’m glad to have seen questions about the homework already –today’s lecture will also help we’ll do more on base/recursive definitions –also check out the LING 388 class slides there is more detail there... that may help By request –slides are now numbered

3 So far... our introduction to Prolog Concepts –database DB (assert facts, closed world assumption) –transitivity (Prolog rule :-) –recursion, also left recursion –variables –lists (comma-delimited, head/tail, infinite list) –computation tree (matching the DB)

4 Today’s Topics Negation More practice on recursive definitions

5 Prolog Negation Prolog negation –“failure to prove” –is limited form of logical negation –denoted by \+ –used in queries and the bodies (not head) of rules only negative facts are not permitted –e.g. you can’t add a negative fact (using assert ) to the database ?- assert(\+ medal(aluminum)). ERROR: assert/1: No permission to modify static_procedure `(\+)/1'

6 Prolog Negation [From lecture 2] Facts: medal(gold). medal(silver). medal(bronze). Negated database query: ?- \+ medal(silver). No ?- \+ medal(aluminum). Yes Computation tree: –?- \+ medal(silver). –true if medal(silver) false ?- medal(silver). –Yes –medal(silver) true, –so \+ medal(silver) false Computation tree: –?- \+ medal(aluminum). true if medal(aluminum) false ?- medal( aluminum ). –No –medal(aluminum) false, –so \+ medal(aluminum) true SWI-Prolog trace: ?- trace. Yes [trace] ?- \+ medal(silver). Call: (8) medal(silver) ? creep Exit: (8) medal(silver) ? creep No SWI-Prolog trace: ?- trace. Yes [trace] ?- \+ medal(aluminum). Call: (8) medal(aluminum) ? creep Fail: (8) medal(aluminum) ? creep Yes

7 Prolog Negation [From lecture 2] Facts: medal(gold). medal(silver). medal(bronze). Negated database query: ?- \+ medal(X). No –does not give a value for X Computation tree: –?- \+ medal(X). – true if medal(X) false ?- medal(X). –X = gold – medal(X) true so \+ medal(X) false SWI-Prolog trace: ?- trace. Yes [trace] ?- \+ medal(X). Call: (8) medal(_G312) ? creep Exit: (8) medal(gold) ? creep No

8 Prolog Negation [From lecture 2] Facts: medal(gold). medal(silver). medal(bronze). Negated database query: ?- \+ \+ medal(X). Yes –does not give a value for X Computation tree: –?- \+ \+ medal(X). –true if \+ medal(X) false ?- \+ medal(X). true if medal(X) false –?- medal(X). »X = gold –medal(X) true, so \+ medal(X) false –\+ medal(X) false, so \+ \+ medal(X) true SWI-Prolog trace: ?- trace. Yes [trace] ?- \+ \+ medal(X). Call: (8) medal(_G312) ? creep Exit: (8) medal(gold) ? creep Yes

9 Prolog Negation We can write a complex query like: –?- \+ \+ medal(X), X = aluminum. –Yes –and the query will succeed because the variable X is not bound (i.e. set) by the sub- query ?- \+ \+ medal(X). However, the similar-looking query: ?- X = aluminum, \+ \+ medal(X). No returns the very different answer No because X = aluminum sets the value of X and the sub-query ?- \ + \+ medal(aluminum). –returns No

10 Prolog Negation Prolog negation in rules Example –Modal auxiliary verbs in English generally have contracted negative counterparts shouldshouldn’t wouldwouldn’t couldcouldn’t may*mayn’t –[* indicates ungrammaticality]

11 Prolog Negation write this rule in Prolog –modal auxiliary verbs in English generally have contracted negative counterparts Database modal(should). “should is a modal” modal(would). “would is a modal” modal(could). “could is a modal” modal(may). “may is a modal” Rule hasCNeg(X) :- modal(X). Rule with exception hasCNeg(X) :- modal(X), \+ X = may. Notes –, is to be read as “and” (conjunction) –\+ is in the body (not the head) of a rule – that’s allowed –but we can’t write something like: \+ hasCNeg(X) :- modal(X), X = may. –where the negation is in the head of the rule

12 Prolog Negation Rule with exception hasCNeg(X) :- modal(X), \+ X = may. Query ?- hasCNeg(X).X = should ;X = would ;X = could ;No Computation tree ?- hasCNeg(X). –?- modal(X). –?- \+ X = may. ?- modal(X).(subquery will be retried) –X = should ?- \+ should = may. –Yes

13 Prolog Rules and Negation Database modal(should). modal(could). modal(would). modal(may). hasCNeg(X) :- modal(X), \+ X = may. hasCNeg(X) modal(X)\+ X=may modal(should)\+ should=may true modal(could)\+ could=maymodal(would)\+ would=maymodal(may)\+ may=may false powerpoint animation

14 Recursive Definitions

15 More infinity Set of natural numbers –N = [1,2,3,4,...] Rules –nn(1). “ 1 is a natural number ” –nn(N) :- nn(M), N is M+1. Notes –recursive definition Query –?- nn(X). what happens? “M is a natural number then M+1 is a natural number” SWI-Prolog built-in computes the arithmetic expression on the right side of “ is ” and matches it with the variable on the left

16 List Reversal Task –reversing a list –e.g. [1,2,3] => [3,2,1] Specification –rev(L1,L2) –L1 and L2 lists –L2 is L1 reversed Base Case –rev([],[]). Recursive Case –rev([H|T],L) :- rev(T,L2), app(L2,[H],L). Example –?- rev([1,2,3],L) ?- rev([2,3],L2) L2 = [3,2] ?- app([3,2],[1],L) L = [3,2,1]

17 List Reversal Accumulating Parameter version –reverse([],L,L). (base case) –reverse([H|T],L,L2) :- reverse(T,[H|L],L2). (recursive case) Usage –reverse(L1,[],L2). –[] is the initial value of the accumulating parameters –accumulating parameter gets progressively instantiated (or filled out) Examples –?- reverse([1,2,3],[],L2). –?- reverse(L1,[], [1,2,3]). does it work?