Lisp and Prolog Background Thank you to Prof. Roosen-Runge and Prof. Gotshalks for the slides that I will be using throughout the course. Lisp History Lisp - invented (about 1958) by the logician and AI researcher John McCarthy Widely used for applications in AI for over 30 years Used in industry To develop expert systems and other AI applications For Rapid Application Development (RAD) 1 2 Lisp Use Lisp is used as an embedded language Found inside applications like Emacs (Mlisp) and AutoCad (AutoLisp) Emacs supports Lisp as a language for developing programs As well as embedded language for controlling and customizing the editor itself Lisp Availability On all major and many minor platforms Numerous free and shareware versions Standard: Common Lisp 3 4
Prolog History Prolog invented ( 1972) by the AI researcher Alan Colmeraurer Widely used to develop expert systems & other AI applications including natrual language processing Used at York in the Student Information System to check applications for input errors Early ideas developed at the University of Montreal; then University of Marseilles Prolog Use and Availability Prolog rumored to be embedded in MS Office On all major and many minor platforms Several free and shareware versions Standard: 'ISO Standard' 5 6 Low and High Level (1) Lisp became the 'assembler language' - lower-level - for AI programmers Used to build higher level systems Wilensky chapters 21 and 22 give the basis for C Prolog! ommon Lisp = union of the techniques and tools people have found useful Low and High Level (2) Prolog is a higher-level language for knowledge-based programming More powerful, not necessarily as efficient More compact More understandable programs 7 8
Symbolic Computing Computing on non-numbers non-character-string use atoms instead of numbers and strings Building structures from atoms lists, trees, terms, clauses, propositions, etc. Operational vs Denotational Programming 9 10 Operational Programming Basic, Pascal, C, Java, etc. Require describing how something is computed Program describes a sequence of operations Not describing what is computed j <-- 1 While j max { print item (j) j <-- j + 1 Denotational Programming (1) Denotation = object described by an expression or referred to by a name Describes what to compute Denotational program has a mathematical meaning Uses mathematical objects such as functions, relations, etc. } 11 12
Denotational Programming (2) Examples of denotational languages: Lisp Prolog APL ML Timeless vs. State-change Denotational semantics uses mathematical language Timeless propositions Nothing changes x = x + 1 is false Operational semantics uses Language of states (memory) and change-of-state x x + 1 describes a change in state of x = in C/C++, Java, Fortran := in Pascal and Eiffel 13 14 Denotational History Concept of denotation comes from the theories of how logic connects to mathematics worked out by Bertrand Russell & Albert North Whitehead at the turn of the century (famous book: Principia Mathematica) Based on ideas from German logician Gottlob Frege Denotational vs. Operational Programming Denotational: describes what to compute Operational: describes how to compute Invented the concepts of the predicate calculus and quantifiers: (for all, there exists) 15 16
Description and Prescription Programs are both descriptions and prescriptions x = y + 3 Interpreted operationally (prescription) Program = instructions to underlying machine as to what to do Add 3 to y and store result in x Interpreted denotationally (description) Program = desription of mathematical relationship between input and output When executed, value of x equals value of y+3 17 Prescription Example palindrome ( String x ) : boolean is int half x.length div 2 for i : 0.. half do if x.charat ( i ) x.charat ( x.length - 1 - i ) ) return false fi end for return true end palindrome 18 Description Example // Given the following two functions. // Result = (x = y) match ( String x, String y ) : boolean // Result is the string reversal of x. reverse ( String x ) : String // Then... palindrome ( String x ) : boolean is return match ( x, reverse (x) ) end palindrome Functional vs. Declarative Functional (Lisp-like) palindrome ( x ) is x = rev (x) where rev ( [] ) is [] -- reversal of empty is empty and rev ( w ^ x ) is append ( rev (x), w ) Declarative (Prolog-like) palindrome ( x ) if rev ( x, x ) where rev ( [], [] ) -- Empty is the reversal of empty and rev ( w ^ x, y ) if rev (x, z) and append ( z, w, y ) 19 20
Pure Lisp Denotational and functional rather than operational No states: just a mapping between arguments and result or, from input to output 'Pure' Lisp is all we will have time to discuss in this course It is what makes Lisp distinctive Pure Prolog 'Pure' Prolog: denotational and declarative Just 1 state T A 'knowledge' base = database for facts his turned out to be a very big advance! 21 22 Lisp vs. Prolog? Which AI language an AI researcher uses often depends on where they studied. At MIT and and Stanford, At Edinburgh, almost all almost all Lisp Prolog MIT has used a dialect of Lisp called Scheme in their first year programming course for many years. At York? We have been more a 'Prolog shop' than a 'Lisp shop' in this department Prof. Stachniak teaches a 4th year course on Logic Programming which includes a more advanced look at Prolog 23 24
Other Choices There are many denotational, functional languages other than Lisp ML is popular in British and some European universities American universities tend to use Lisp No strong competitors to Prolog at present, mainly variants, extensions and dialects Object-oriented add-ons available for both languages Lisp in 'Production' Work Programmers tend to use operational features This is not good; it is the fault of poor softwaredevelopment tools There are claims that 90% of function calls in Lisp programs are to assignment functions - like setq and rplaca! Assignment changes state and is sure sign of an operational description Compare the palindrome programs 25 26 General Goals Understand important ideas and historical context in computer science Extend understanding of programming concepts and vocabulary Learn to adapt to a new mindsets - actually two new mindsets! pure functional programming - Lisp declarative programming - Prolog 27