UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering Using Definite Knowledge: Lists and Difference Lists Notes for Ch.3 of Poole.

Slides:



Advertisements
Similar presentations
CS2303-THEORY OF COMPUTATION Closure Properties of Regular Languages
Advertisements

Prolog Programming (Volume 2) Dr W.F. Clocksin. Lists Lists are the same as other languages (such as ML) in that a list of terms of any length is composed.
PROLOG 8 QUEENS PROBLEM.
C. Varela; Adapted w/permission from S. Haridi and P. Van Roy1 Declarative Programming Techniques Accumulators, Difference Lists (VRH ) Carlos Varela.
ML Lists.1 Standard ML Lists. ML Lists.2 Lists  A list is a finite sequence of elements. [3,5,9] ["a", "list" ] []  ML lists are immutable.  Elements.
Declarative Programming Lists in PROLOG Autumn 2014.
© 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.
Prolog Programming (Volume 5) Dr W.F. Clocksin. List cells + Unification = Great Idea Normally we use ‘proper lists’, which are defined according to the.
© 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.
Functional Programming. Pure Functional Programming Computation is largely performed by applying functions to values. The value of an expression depends.
Patterns in ML functions. Formal vs. actual parameters Here's a function definition (in C): –int add (int x, int y) { return x + y; } –x and y are the.
Finite Automata Great Theoretical Ideas In Computer Science Anupam Gupta Danny Sleator CS Fall 2010 Lecture 20Oct 28, 2010Carnegie Mellon University.
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering CSCE 580 Artificial Intelligence Ch.5 [P]: Propositions and Inference Sections.
1 Design Theory. 2 Let U be a set of attributes and F be a set of functional dependencies on U. Suppose that X  U is a set of attributes. Definition:
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering Controlling Backtracking Notes for Ch.5 of Bratko For CSCE 580 Sp03 Marco Valtorta.
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 18 Program Correctness To treat programming.
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering Using Definite Knowledge Notes for Ch.3 of Poole et al. CSCE 580 Marco Valtorta.
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering CSCE 580 Artificial Intelligence Ch.12 [P]: Individuals and Relations Proofs.
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering Using Definite Knowledge: Two Short Examples Notes for Ch.3 of Poole et al.
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering Using Definite Knowledge Notes for Ch.3 of Poole et al. CSCE 580 Marco Valtorta.
Regular Languages Sequential Machine Theory Prof. K. J. Hintz Department of Electrical and Computer Engineering Lecture 3 Comments, additions and modifications.
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering CSCE 330 Programming Language Structures Haskell Fall 2005 Marco Valtorta
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering Using Definite Knowledge: Axiomatizing the Natural Numbers Notes for Ch.3 of.
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering A Hole in Goal Trees Notes for: D.W. Loveland and M. Stickel. “A Hole in Goal.
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering Using Definite Knowledge Notes for Ch.3 of Poole et al. CSCE 580 Marco Valtorta.
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering Lists, Operators, Arithmetic Notes for Ch.3 of Bratko For CSCE 580 Sp03 Marco.
Functional programming: LISP Originally developed for symbolic computing First interactive, interpreted language Dynamic typing: values have types, variables.
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering Introduction to Functional Programming Notes for CSCE 190 Based on Sebesta,
1 Homework #1 Solutions 2 #1. True or False a)Given a language (set of strings) L, the question: “Is string w  L” is a decision problem: T F b)  =
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering CSCE 580 Artificial Intelligence Ch.12 [P]: Individuals and Relations Datalog.
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering Operations on Data Structures Notes for Ch.9 of Bratko For CSCE 580 Sp03 Marco.
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering Using Definite Knowledge: NLP and nl_interface.pl Notes for Ch.3 of Poole et.
Lecture 1 String and Language. String string is a finite sequence of symbols. For example, string ( s, t, r, i, n, g) CS4384 ( C, S, 4, 3, 8) (1,
Comp. Eng. SW Lab II: FP with Scheme 1 Computer Eng. Software Lab II , Semester 2, Who I am: Andrew Davison CoE, WiG Lab Office.
FATIH UNIVERSITY Department of Computer Engineering Programming Style and Technique Notes for Ch.8 of Bratko For CENG421&553 Fall03.
1 Chapter 1 Automata: the Methods & the Madness Angkor Wat, Cambodia.
COP4020 Programming Languages Logical programming with Prolog Prof. Xin Yuan.
Recursion. L162 Agenda Recursion and Induction Recursive Definitions Sets Strings.
Set, Combinatorics, Probability & Number Theory Mathematical Structures for Computer Science Chapter 3 Copyright © 2006 W.H. Freeman & Co.MSCS Slides Set,
Construction Techniques (1) - 1ICOM 4075 (Fall, 2010) UPRM Department of Electrical and Computer Engineering University of Puerto Rico at Mayagüez 2005.
Divide & Conquer  Themes  Reasoning about code (correctness and cost)  recursion, induction, and recurrence relations  Divide and Conquer  Examples.
1 Exercise: Prove that the set S = { π : π is a permutation of {1, 2, 3, …, n} for some integer n ≥ 1 } is countable.
Chapter 9: Functional Programming in a Typed Language.
Semantics. Semantics is a precise definition of the meaning of a syntactically and type-wise correct program. Ideas of meaning: –Operational Semantics.
Regular Expressions and Languages A regular expression is a notation to represent languages, i.e. a set of strings, where the set is either finite or contains.
PZ03EX Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, PZ03EX - ML Programming Language Design and Implementation.
Recursive Data Structures and Grammars  Themes  Recursive Description of Data Structures  Recursive Definitions of Properties of Data Structures  Recursive.
Resolution Strategies One common strategy for applying resolution is called level saturation. Here you try to resolve every pair of clauses from the original.
Programming Languages Third Edition Chapter 4 Logic Programming.
Full Logic Programming. Data structures Pure LP allows only to represent relations (=predicates) To obtain full LP we will add functors (=function symbols)
Recursive Data Structures and Grammars  Themes  Recursive Description of Data Structures  Recursive Definitions of Properties of Data Structures  Recursive.
INM175 Topic 8 1 Module INM175 Discrete Mathematics Topic 8 Algebraic Theories.
1 First order theories (Chapter 1, Sections 1.4 – 1.5) From the slides for the book “Decision procedures” by D.Kroening and O.Strichman.
Kyung-Goo Doh Hanyang University - ERICAComputer Science & Engineering Functional Programming / Imperative Programming CSE215 Fundamentals of Program Design.
07/10/04 AIPP Lecture 5: List Processing1 List Processing Artificial Intelligence Programming in Prolog Lecturer: Tim Smith Lecture 5 07/10/04.
Functional Programming Lecture 3 - Lists Muffy Calder.
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering CSCE 330 Programming Language Structures Operational Semantics (Slides mainly.
CS 152: Programming Language Paradigms February 12 Class Meeting Department of Computer Science San Jose State University Spring 2014 Instructor: Ron Mak.
Copyright © Zeph Grunschlag,
A lightening tour in 45 minutes
ML Programming Language Design and Implementation (4th Edition)
Programming Languages 2nd edition Tucker and Noonan
Prolog Programming (Volume 2)
Introduction to Finite Automata
Madhusudan Parthasarathy
Announcements Quiz 5 HW6 due October 23
Copyright © Zeph Grunschlag,
Presentation transcript:

UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering Using Definite Knowledge: Lists and Difference Lists Notes for Ch.3 of Poole et al. CSCE 580 Marco Valtorta

UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering Lists An example of abstract knowledge: lists (lists.pl) We will concentrate on the traditional representation that uses the constant nil and the function symbol cons. –analogy with 0 and succ in Peano arithmetic. Other representations are possible, e.g.: –Elt(L,I,E)E is the I-th element of list L –Size(L,N) List L has N elements

UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering nil and cons The constant nil denotes the empty list The function symbol cons is defined so that cons(H,T) denotes the list whose first element (head of the list) is H and whose remaining elements are in the list (tail) T nil and cons are not predefined symbols. We could use, say “empty” and “attach,” with no change for the computer. Ex.: cons(a, cons(b, cons(c, cons(d, nil)))) denotes [a,b,c,d].

UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering Some Predicates on Lists list(nil). list(cons(H,T)) <- list(T). –Our lists are not typed. append(nil,Z,Z). append(cons(A,X), Y, cons(A,Z)) <- append(X,Y,Z). We axiomatize on each case of the first argument. Correctness is proved by induction; when the clauses are used in a top-down proof procedure, a recursive computation occurs.

UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering List Notation nil is written [] cons(H,T) is written [H|T] cons(a,cons(b,nil)) is written [a,b] (etc.) –This is just syntactic sugar! append([],Z,Z). append([A|X], Y, [A|Z]) <- append(X,Y,Z).

UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering Member and notin member(X, [X|L]). member(X, [H|R]) <- member(X,R). notin(A, []). notin(A, [H|T]) <- different(A,H) & notin(A,T). different can be hard to axiomatize!

UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering Naïve Reverse rev([],[]). rev([H|T], R) <- rev(T,RT) & append(RT,[H],R). A proof for rev has length quadratic in the length of the first argument, since a proof of append is linear in the size of its first argument.

UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering Linear-Time Reverse reverse(L,R) <- rev3(L,[],R). rev3([],R,R). rev3([H|T],A,R) <- rev3(T,[H|A],R). A proof using reverse has length linear in the size of L (the list being reversed). The second argument of rev3, A, is used as an accumulator: as elements are stripped off the first list, they are added to the accumulator.

UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering Reverse with an accumulator in ML Fun rev1(nil, M) = M | rev1(x::xs, ys) = rev1(xs, x::ys); Fun reverse(L) = rev1(L,nil); Consider: –rev1([a1,a2,…,an],[b1,b2,…,bm]) After the call: –rev1([a2,a3,…,an],[a1,b1,b2,…,bm] On our way to –[an,an-1,…a1,b1,b2,…,bm]

UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering Difference Lists The difference list L-E contains the elements of L that occur before E. E is a suffix of L. E.g., [a,b,c,d] – [c,d] is [a,b] Trick: [a,b,c,d|E] – E is [a,b,c,d]! Difference lists allow concatenation of lists in constant time, as in imperative languages.

UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering Append and Difference Lists Difference lists can be concatenated in constant time by using append_dl: ?append_dl([a,b|A] – A, [c,d|C] – C, Result) unify with append_dl(X – Y, Y – Z, X – Z): {X / [a,b|A]} {Y / A} {A / [c,d|C]} {Z / C} {Result / X – Z}, i.e. {Result / [a,b|A] – C}, i.e. {Result / [a,b,c,d|C} – C}

UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering Some Caveats While the result of append_dl has an uninstatiated tail, the first argument does not. –You cannot use it as an argument to append_dl in the same clause. “Difference lists are powerful but counterintuitive. They appear most often in procedures that were first implemented with conventional lists and then carefully rewritten for efficiency” [Covington, p.183].

UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering Rev3 and Difference Lists In rev3, R-A is a difference list that contains the elements of L in reverse order: A is an ending of R, and the elements of R before A are the elements of L in reverse order. When A is the empty list, R contains the reverse of list L. (See text for full argument.) It is more natural to view A as an accumulator, but difference lists become important in natural language processing, because you do not want to reverse lists of words!