Artificial Intelligence

Slides:



Advertisements
Similar presentations
Formal Models of Computation Part II The Logic Model
Advertisements

More Prolog test vs. find built-in predicates list operations: member, append, nth0, reverse, … not, default vs. logical negation comparison operators,
Part 1 The Prolog Language Chapter 3 Lists, Operators, Arithmetic
3. Lists, Operators, Arithmetic. Contents Representation of lists Some operations on lists Operator notation Arithmetic.
Logic Programming Lecture 9: Constraint logic programming.
Cs7120 (Prasad)L22-MetaPgm1 Meta-Programming
Computational Models The exam. Models of computation. –The Turing machine. –The Von Neumann machine. –The calculus. –The predicate calculus. Turing.
Notes for CS3310 Artificial Intelligence Part 5: Prolog arithmetic and lists Prof. Neil C. Rowe Naval Postgraduate School Version of July 2009.
Prolog.
© Patrick Blackburn, Johan Bos & Kristina Striegnitz Lecture 6: More Lists Theory –Define append/3, a predicate for concatenating two lists, and illustrate.
Introduction to PROLOG ME 409 Lab - 1. Introduction to PROLOG.
11/10/04 AIPP Lecture 6: Built-in Predicates1 Combining Lists & Built-in Predicates Artificial Intelligence Programming in Prolog Lecturer: Tim Smith Lecture.
Prolog: List © Patrick Blackburn, Johan Bos & Kristina Striegnitz.
CS344 : Introduction to Artificial Intelligence Pushpak Bhattacharyya CSE Dept., IIT Bombay Lecture 16- Prolog.
1 Introduction to Prolog References: – – Bratko, I., Prolog Programming.
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).
A Third Look At Prolog Chapter Twenty-TwoModern Programming Languages, 2nd ed.1.
Stacks Chapter 11.
COP4020 Programming Languages Expression and assignment Prof. Xin Yuan.
Prolog OR (disjunction) “;” is same as a logical OR “;” is same as a logical OR It is also equivalent to using separate clauses... It is also equivalent.
Bahar Pamuk. Outline Introduction Syntaxa Clauses, Programs and Queries List Manipulation Operators Backtracking, Cuts References.
About prolog  History  Symbolic Programming Language  Logic Programming Language  Declarative Programming Language.
TCP1211-Logic Programming Control and Side Effects Programming Faculty of Information Technology Multimedia University.
Meta-interpreters Interpreted languages like Prolog can easily treat program code as data Interpreted languages like Prolog can easily treat program code.
For Friday Read “lectures” 1-5 of Learn Prolog Now: prolog-now/
© Patrick Blackburn, Johan Bos & Kristina Striegnitz Lecture 9: A closer look at terms Theory –Introduce the == predicate –Take a closer look at term structure.
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering Lists, Operators, Arithmetic Notes for Ch.3 of Bratko For CSCE 580 Sp03 Marco.
CMPT 120 Lists and Strings Summer 2012 Instructor: Hassan Khosravi.
The ACL2 Proof Assistant Formal Methods Jeremy Johnson.
Basic Lisp CIS 479/579 Bruce R. Maxim UM-Dearborn.
1 Lecture Expert Systems &. 2 Operator Notation A programmer can define new operators by inserting into the program special kinds of clauses,
COP4020 Programming Languages Logical programming with Prolog Prof. Xin Yuan.
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.
Lecture 9: Constraint logic programming
Sequences and Summations
15/11/04 AIPP Lecture 14: Database Manipulation1 Database Manipulation Artificial Intelligence Programming in Prolog Lecturer: Tim Smith Lecture 14 15/11/04.
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.
Built-in Data Structures in Python An Introduction.
MB: 5 March 2001CS360 Lecture 41 Programming in Logic: Prolog Lists and List Operations Readings: Sections 3.1 & 3.2.
1 COMP 205 Introduction to Prolog Dr. Chunbo Chu Week 14.
1 Prolog and Logic Languages Aaron Bloomfield CS 415 Fall 2005.
Automated Reasoning Early AI explored how to automated several reasoning tasks – these were solved by what we might call weak problem solving methods as.
Operators in Prolog © Patrick Blackburn, Johan Bos & Kristina Striegnitz.
Basic Problem Solving Search strategy  Problem can be solved by searching for a solution. An attempt is to transform initial state of a problem into some.
Lists in Prolog Sections 3.1, 3.2. Lists n List = sequence of values –[1, 2, 3, 4, 5] –[bob, brian, cathy, mark, david, loretta] –[birds(4, calling),
Lecture course: Heuristics & Prolog for Artificial Intelligence Applications Notes on Prolog from Professor Bruce Batchelor, DSc.
Programming Language Concepts Lecture 17 Prepared by Manuel E. Bermúdez, Ph.D. Associate Professor University of Florida Logic Programming.
Cs774 (Prasad)L4ListProcessing1 List processing in Prolog
For Monday Exam 1 is Monday Takehome due Prolog Handout 3 due.
1 Artificial Intelligence CS370D Prolog programming List operations.
For Friday No reading Prolog Handout 2. Homework.
Prolog 3 Tests and Backtracking 1. Arithmetic Operators Operators for arithmetic and value comparisons are built-in to Prolog = always accessible / don’t.
07/10/04 AIPP Lecture 5: List Processing1 List Processing Artificial Intelligence Programming in Prolog Lecturer: Tim Smith Lecture 5 07/10/04.
Logic Programming Lecture 9: Constraint logic programming.
Chapter Three: Operators, Arithmetic 1. Chapter three: 3.3Operator notation 3.4Arithmetic 2.
Operators. Perl has MANY operators. –Covered in Chapter 3 of Camel –perldoc perlop Many operators have numeric and string version –remember Perl will.
Chapter 2 1. Chapter Summary Sets The Language of Sets - Sec 2.1 – Lecture 8 Set Operations and Set Identities - Sec 2.2 – Lecture 9 Functions and sequences.
OPERATORS IN C CHAPTER 3. Expressions can be built up from literals, variables and operators. The operators define how the variables and literals in the.
Section 16.5, 16.6 plus other references
Expressions and Assignment
For Friday No reading Prolog handout 3 Chapter 9, exercises 9-11.
For Wednesday Read “lectures” 7-10 of Learn Prolog Now:
Tests, Backtracking, and Recursion
CISC101 Reminders Quiz 2 this week.
Artificial Intelligence CS370D
Conditional Statements
Chapter 3: Prolog (Lists, Arithmetic, Operators)
Announcements Quiz 5 HW6 due October 23
CISC101 Reminders Assignment 2 due today.
Presentation transcript:

Artificial Intelligence Lecture 5

more Prolog test vs. find built-in predicates user-defined operators list operations: member, append, nth0, reverse, … not, default vs. logical negation comparison operators, arithmetic user-defined operators position, precedence, associativity

Test vs. find Prolog programs define relations: query w/ constants: "test" whether relation holds between the constants query w/ variables: "find" values for which the relation holds ?- member(X, [a, b, c]). X = a ; X = b ; X = c ; No ?- member(a, X). X = [a|_G260] ; X = [_G259,a|_G262] Yes ?- member(X, Y). X = _G209 Y = [_G209|_G270] ; Y = [_G275,_G209|_G278] with a variable as first argument, the query is used to "find" members of the given list with a variable as the second argument, the query is used to "find" lists that have the given item as member with both variables, the query is used to "find" general schemas for list membership

Append predicate another useful predefined predicate for list manipulation append(L1,L2,L3): L3 is the result of placing the items in L1 at the front of L2 can be used in reverse to partition a list ?- append([a,b], [c,d], L). L = [a,b,c,d] Yes ?- append(L1, L2, [a,b,c,d]). L1 = [] L2 = [a,b,c,d] ; L1 = [a] L2 = [b,c,d] ; L1 = [a,b] L2 = [c,d] ; L1 = [a,b,c] L2 = [d] ; L1 = [a,b,c,d] L2 = [] ; No

Other list predicates ?- is_list([]). Yes is_list(Term): succeeds if Term is a list length(List,Len): Len is the number of items in List nth0(Index,List,Item): Item is the item at index Index of List(starting at 0) nth1(Index,List,Item): Item is the item at index Index of List(starting at 1) reverse(List,RevList): RevList is List with the items in reverse order delete(List,Item,NewList): NewList is the result of deleting every occurrence of Item from List select(Item,List,Remain): Remain is the List with an occurrence of Item removed ?- is_list([]). Yes ?- L = [a,b,c,d], length(L, Len), nth1(Len, L, X). L = [a,b,c,d] Len = 4 X = d ?- reverse([a,b,a,c], Rev), delete(Rev, a, Del). Rev = [c,a,b,a] Del = [c,b] ?- select(a, [a,b,a,c], R). R = [b,a,c] ; R = [a,b,c] ; No

not predicate anything Prolog can't prove true it assumes to be false! ?- not(is_list([])). No ?- member(d, [a,b,c]). ?- not(member(d, [a,b,c])). Yes ?- member(X, [a,b,c]). X = a ?- not(member(X, [a,b,c])). ?- X = d, not(member(X, [a,b,c])). X = d ?- not(member(X, [a,b,c])), X = d. not defines the (default) negation of conditional statements when applied to relations with no variables, it is equivalent to logical negation () in reality, it returns the opposite of whatever its argument would return if X would succeed as a query, then not(X) fails if X would fail as a query, then not(X) succeeds anything Prolog can't prove true it assumes to be false!

Programming exercises suppose we want to define a relation to test if a list is palindromic palindrome(List): succeeds if List is a list whose elements are the same backwards & forwards

Programming exercises palindrome([]). palindrome(List) :- reverse(List, Rev), List = Rev. suppose we want to define relation to see if a list has duplicates has_dupes(List): succeeds if List has at least one duplicate element has_dupes([H|T]) :- member(H, T). has_dupes([_|T]) :- has_dupes(T). suppose we want the opposite relation, that a list has no dupes no_dupes(List): succeeds if List has no duplicate elements no_dupes(List) :- not( has_dupes(List) ).

Built-in comparison operators ?- foo = foo. Yes ?- X = foo. X = foo ?- [H|T] = [a,b,c]. H = a T = [b,c] ?- foo \= bar. ?- X \= foo. No ?- 4+2 = 6. X = Y does more than test equality, it matches X with Y, instantiating variables if necessary X \= Y determines whether X & Y are not unifiable for ground terms, this means inequality can think of as: not(X = Y) again, doesn't make a lot of sense for variables Note: arithmetic operators (+, -, *, /) are not evaluated 4 + 2  +(4, 2) can force evaluation using 'is' ?- X = 4 + 2. ?- X is 4 + 2. X = 4+2 X = 6 Yes Yes

Programming exercise suppose we want to define relation to see how many times an item occurs in a list num_occur(Item,List,N): Item occurs N times in List num_occur(_,[],0). num_occur(H, [H|T], N) :- num_occur(H, T, TailN), N is TailN+1. num_occur(H, [_|T], N) :- num_occur(H, T, TailN), N is TailN. is the first answer supplied by this relation correct? are subsequent answers obtained via backtracking correct?

User-defined operators it is sometimes convenient to write functors/predicates as operators predefined: +(2, 3)  2 + 3 user defined? likes(dave, cubs)  dave likes cubs operators have the following characteristics position of appearance prefix e.g., -3 infix e.g., 2 + 3 postfix e.g., 5! precedence 2 + 3 * 4  2 + (3 * 4) associativity 8 – 5 - 2  8 – (5 – 2)

op new operators may be defined as follows :- op(Prec, PosAssoc, Name). Name is a constant Prec is an integer in range 0 – 1200 (lower number binds tighter) PosAssoc is a constant of the form xf, yf (postfix) fx, fy (prefix) xfx, xfy, yfx, yfy (infix) the location of f denotes the operator position x means only operators of lower precedence may appear here y allows operators of lower or equal precedence Example: :- op(300, xfx, likes).

Operator example %%% likes.pro likes(dave, cubs). likes(kelly, and(java, and(scheme,prolog))). %%% likes.pro :- op(300, xfx, likes). :- op(250, xfy, and). dave likes cubs. kelly likes java and scheme and prolog. ?- likes(dave, X). X = cubs Yes ?- likes(Who, What). Who = dave What = cubs ; Who = kelly What = and(java, and(scheme,prolog)) ; No ?- dave likes X. X = cubs Yes ?- Who likes What. Who = dave What = cubs ; Who = kelly What = java and scheme and prolog ; No by defining functors/predicates as operators, can make code more English-like

IQ Test choose the most likely answer by analogy Question 1: IQ Test choose the most likely answer by analogy Question 3: Question 2:

Next week… AI as search Be prepared for a quiz on problem states, state spaces uninformed search strategies depth first search breadth first search iterative deepening Be prepared for a quiz on this week’s lecture (moderately thorough) the reading (superficial)

Questions & Answers ???????