Artificial Intelligence and Lisp Lecture 3 LiU Course TDDC65 Autumn Semester, 2010

Slides:



Advertisements
Similar presentations
Lisp. Versions of LISP Lisp is an old language with many variants Lisp is alive and well today Most modern versions are based on Common Lisp LispWorks.
Advertisements

C-LISP. LISP 2 Lisp was invented by John McCarthy in 1958 while he was at the Massachusetts Institute of Technology (MIT).John McCarthyMassachusetts Institute.
1 Copyright © 1998 by Addison Wesley Longman, Inc. Chapter 14 Functional Programming Languages - The design of the imperative languages is based directly.
1 Programming Languages (CS 550) Mini Language Interpreter Jeremy R. Johnson.
Intermediate Code Generation
CSE 3341/655; Part 4 55 A functional program: Collection of functions A function just computes and returns a value No side-effects In fact: No program.
1 Programming Languages and Paradigms Lisp Programming.
Lambda Calculus and Lisp PZ03J. Lambda Calculus The lambda calculus is a model for functional programming like Turing machines are models for imperative.
Chapter 3 Functional Programming. Outline Introduction to functional programming Scheme: an untyped functional programming language.
CS 355 – PROGRAMMING LANGUAGES Dr. X. Apply-to-all A functional form that takes a single function as a parameter and yields a list of values obtained.
Artificial Intelligence and Lisp #3 Characterization of Actions [Chapter 5] Representation Language [Chapter 2] Lab Assignment 2.
Lisp – Introduction יעל נצר מערכות נבונות סמסטר ב' תשס"ו.
Functional Programming COMP2003 A course on functional programming using Common Lisp Dr Eleni Mangina
Artificial Intelligence and Lisp Lecture 4 LiU Course TDDC65 Autumn Semester, 2010
Lisp. Versions of LISP Lisp is an old language with many variants –LISP is an acronym for List Processing language Lisp is alive and well today Most modern.
Artificial Intelligence and Lisp #12 The Programming Language LISP.
6.001 SICP SICP Sections 5 & 6 – Oct 5, 2001 Quote & symbols Equality Quiz.
Introductory Lisp Programming Lecture # 2 Main Topics –Basic Lisp data types –Lisp primitives –Details of list handling Cons cells (boxes) & their representation.
TES3111 Oct 2001 Data Structures S-Expression - Symbolic expression. It can be an Atom, a List or a collection of S- Expression enclosed by (…) Atom -
Artificial Intelligence and Lisp Lecture 6 LiU Course TDDC65 Autumn Semester, 2010
Functional programming: LISP Originally developed for symbolic computing First interactive, interpreted language Dynamic typing: values have types, variables.
Introduction to Logic for Artificial Intelligence Lecture 1 Erik Sandewall 2010.
TES3111 October 2001 Artificial Intelligence LISP.
Artificial Intelligence and Lisp Lecture 2 LiU Course TDDC65 Autumn Semester, 2010
Dr. Muhammed Al-Mulhem ICS An Introduction to Functional Programming.
LISP A brief overview. Lisp stands for “LISt Process” –Invented by John McCarthy (1958) –Simple data structure (atoms and lists) –Heavy use of recursion.
COMP 205 – Week 11 Dr. Chunbo Chu. Intro Lisp stands for “LISt Process” Invented by John McCarthy (1958) Simple data structure (atoms and lists) Heavy.
Lisp by Namtap Tapchareon Lisp Background  Lisp was developed by John McCarthy in  Lisp is derives from List Processing Language. 
LISP 1.5 and beyond A very quick tour. Data Atoms (symbols) including numbers – All types of numbers including Roman! (well, in the early days) – Syntactically.
RDF (Resource Description Framework) Why?. XML XML is a metalanguage that allows users to define markup XML separates content and structure from formatting.
CS 462: Introduction to Artificial Intelligence This course advocates the physical-symbol system hypothesis formulated by Newell and Simon in It.
Digital Electronics Data Structures LISP
Functional Programming Universitatea Politehnica Bucuresti Adina Magda Florea
PRACTICAL COMMON LISP Peter Seibel 1.
1 Lisp Functions –Built-in functions –Defining functions –Function Evaluation and Special Forms defun, if Control statements –Conditional if, cond –Repetition.
ISBN Chapter 15 Functional Programming Languages.
Functional Programming in Scheme and Lisp.
18-October-2002cse Symbols © 2002 University of Washington1 Symbols CSE 413, Autumn 2002 Programming Languages
ISBN Chapter 15 Functional Programming Languages.
LISP Data Types Functional Programming Academic Year Alessandro Cimatti
CS535 Programming Languages Chapter - 10 Functional Programming With Lists.
Introduction to LISP. Lisp Extensible: It lets you define new operators yourself Lisp programs are expressed as lisp data structures –You can write programs.
Python Primer 1: Types and Operators © 2013 Goodrich, Tamassia, Goldwasser1Python Primer.
1-1 An Introduction to Functional Programming Sept
Milos Hauskrecht (PDF) Hieu D. Vu (PPT) LISP PROGARMMING LANGUAGE.
1 Scheme (Section 11.2) CSCI 431 Programming Languages Fall 2003.
November 12, 2009Theory of Computation Lecture 17: Calculations on Strings II 1 Numerical Representation of Strings First, we define two primitive recursive.
1 FP Foundations, Scheme In Text: Chapter Chapter 14: FP Foundations, Scheme Mathematical Functions Def: A mathematical function is a mapping of.
Comparative Programming Languages Functional programming with Lisp/Scheme.
C H A P T E R E I G H T Functional Programming Programming Languages – Principles and Paradigms by Allen Tucker, Robert Noonan.
4 - Conditional Control Structures CHAPTER 4. Introduction A Program is usually not limited to a linear sequence of instructions. In real life, a programme.
Ch Ch jcmt CSE 3302 Programming Languages CSE3302 Programming Languages (n-n-n-notes) Summer 2003 Dr. Carter Tiernan.
Artificial Intelligence and Lisp Lecture 6 LiU Course TDDC65 Autumn Semester,
Functional Programming
CS314 – Section 5 Recitation 9
Functional Programming Languages
Functional Programming
History of Computing – Lisp
Artificial Intelligence and Lisp Lecture 3 LiU Course TDDC65 Autumn Semester,
Artificial Intelligence and Lisp #3
Modern Programming Languages Lecture 20 Fakhar Lodhi
Artificial Intelligence and Lisp Lecture 13 Additional Topics in Artificial Intelligence LiU Course TDDC65 Autumn Semester,
The Metacircular Evaluator
FP Foundations, Scheme In Text: Chapter 14.
Python Primer 1: Types and Operators
Announcements Quiz 5 HW6 due October 23
Modern Programming Languages Lecture 18 Fakhar Lodhi
Chapter 15 Functional Programming 6/1/2019.
Representations & Reasoning Systems (RRS) (2.2)
LISP primitives on sequences
Presentation transcript:

Artificial Intelligence and Lisp Lecture 3 LiU Course TDDC65 Autumn Semester,

Today's topics Evaluation of terms, in two modes: - Computational evaluation - Representational evaluation Evaluation of conditions/propositions Operations on actions: - Evaluation - Execution

Today's topics Evaluation of terms, in two modes: - Computational evaluation - Representational evaluation Examples: (+.a 5) (father-of sven) (age (father-of sven)) Evaluation of conditions/propositions Example: [less-than (age (father-of sven)) 50] Operations on actions: - Evaluation - Execution Examples: [call-by-phone sven (father-of sven)] [call-by-phone.p (father-of.p)]

Computational vs representational evaluation of terms Recall: terms formed from symbols, strings, and numbers, composed using functions and set and sequence operators Strings always evaluate to themselves Numbers also Symbols evaluate to themselves computationally, and to a thing in the world representationally (modif. will follow) Set and sequence expressions evaluate element by element Functions evaluate using knowledgebase computationally Functions representationally: according to facts in the world if some argument is in the world, otherwise use computational evaluation (modif. will follow)

The examples Terms: (+.a 5) (father-of sven) (age (father-of sven)) Proposition: [less-than (age (father-of sven)) 50] Actions: [call-by-phone sven (father-of sven)] [call-by-phone.p (father-of.p)] Consider the arguments of the action expressions. - Computational evaluation: symbols sven, lars - Representational evaluation: these respective persons Function 'age' maps - Computationally: symbol to number - Representationally: person to number Analyze function 'father-of' similarly Function + maps number to number in both modes

Additional examples [member sven (friends-of gunnar)] [member sven {maria sture hubert... }] Notice that literals (i.e. elementary propositions) evaluate similarly to functions, but they have a truth-value Composite propositions, formed using and, or, not, etc, also evaluate similarly to functions, with standard truth-tables 'Numbers evaluate to themselves': a mathematician make take issue on this, and the system implementor as well, but for our purpose it is sufficient 'Set expressions evaluate to themselves': similar observation

Evaluation vs execution of actions (More exactly, action expressions) Evaluation of action: arguments and parameters elementwise, like for sets and sequences Execution of (evaluated) action: computationally in simulated world, representationally in real world A robot will do computational evaluation followed by representational execution (leads to grounding problem) Examples: [call-by-phone sven (father-of sven)] [call-by-phone.p (father-of.p)] Evaluation result: [call-by-phone sven lars-erik]

Execution vs statements about actions Examples: [call-by-phone sven (father-of sven)] [call-by-phone.p (father-of.p)] Evaluation result: [call-by-phone sven lars-erik] Actually in the world: representational evaluation and execution Performed by robot: comput. evaluation, repres. execution (modif. example as [call-by-phone sven (father-of sven)] ) In memory: use a proposition like [do time-4983 time-4992 [call-by-phone sven lars-erik]] In a plan: similarly (but ending time yet undetermined)

Computational evaluation of terms and propositions Possibilities: One attached procedure for each function and predicate, without stored data (examples: plus, less-than, concat) Make a table of argument combinations and corresponding values, for each function and predicate For predicates: make a list of those combinations of arguments where it is true, omit the others Representation using attribute values of one or more of the arguments, for example [are-friends lars sven] using a set- valued attribute for one or both of the arguments

Correspondence between a symbol and its representational value The following conventions are sometimes applicable: Unique names assumption: Never two different symbols that have the same representational value in the 'world' Closed world assumption: Each thing in the 'world' has a symbol whose representational value it is. Called closed world assumption because... Modified unique names assumption: make statements [equal foo fie] in those cases where two symbols refer to the same thing. If no such statement is in the knowledgebase, then take for granted that they refer to two different things.

Composite entities Compare the following representations, where area1 and area2 are given entities: [has-type border-area1-area2 border] [delimits border-area1-area2 area1] [delimits border-area1-area2 area2] [marked-by border-area1-area2 wooden-fence] [marked-by (border-between area1 area2) wooden-fence] [marked-by (border-between area1 area2)(made-by fence wood)] where also [subsumed-by wooden-fence fence] [material-for wooden-fence wood]

Use of composite entities Convenient both notationally and implementationwise May apply to specific things, e.g. area1, or to classes or other abstract entities, e.g. fence Do not admit multiple values, but may have a set as a value. (What about occasional multiple values?) Must use a reserved value such as nil when no actual value exists Equality issue is important when composite entities are used. Example: lars-erik vs (father-of sven) vs... One may wish to use unique names assumption for atomic entities only

Reification Compare [has-phonenumber sven " "] [equal (phonenumber sven) " "] [Holds (phoneof: sven) " "] The third construct allows you to also write e.g. [knows lars (phoneof: sven)] The entity (phoneof: sven) is called a reification The function the complements Holds, for forming subexpressions, as in [equal (the (phoneof: sven)) " "] Reifications are usually subject to a complete unique names assumption If phone number is time dependent, then make time an additional argument of phonenumber, the, and Holds

List Processing in CEL Operations on recursively nested sequences, called lists Functions: (e1 ) = a (e2 ) = b etc (en 4 ) = d (t1 ) = (t2 ) = (cons a ) = (concat ) =

Information aggregates Information elements, in different approaches: - Logic programming: propositions - OWL: triple of entities - KRF: an entity with its attribute values Information aggregates are the structures that are used for organizing large numbers of information elements In KRF: entityfiles, knowledgeblocks, agents, individuals An entityfile is a textfile containing a sequence of entity descriptions A knowledgeblock is a set of entityfiles Each agent contains a number of knowledgeblocks, and may also access knowledgeblocks of other agents in the same individual, to a limited extent

Lab2a addresses information aggregates and representation issues

Introduction to KR framework Knowledge Representation (several parts) Leonardo installation Software for Intelligent Agents Managing Info Aggregates Goals of AI Logic notes Leonardo Document:n Programming Language Lisp Lisp in Leo Environment Leonardo Facilities List Processing Reading Matter for the course

List processing Recursively nested sequences as the only composite expressions, with symbols, strings, numbers as elements Functions on sequences (no side-effects!) (e1 ) = a (e2 ) = b (en 4 ) = d (t1 ) = t2, tn similarly (cons g ) = Notice: (cons (e1.x) (t1.x)) = x

List processing Predicates on lists (equal ) = true Control operators, for example (if (equal.a <>).b.a) Other necessary function (type-of.a) The value is either symbol, string, integer, real, sequence Other functions can be defined in terms of these, for example and, or, not

List Processing - Recursive Functions (length.s) == (if [equal.s <>] 0 (+ 1 (length (t1.s)))) (replace.a.b.s) == (if [equal.s.a].b (if [atom.s] s (cons (replace.a.b (e1.s)) (replace.a.b (t1.s)) )))

Lisp Programming Lisp uses S-expression style, all data are formed as recursively nested expressions with round parentheses Using function names such as e1 and t1, rewrite as follows (e1 ) (e1 (quote (a b c))) ssv.a (setq a (quote (red green))) (e1.a) (e1 a) General rule: a list (g a b c) is considered as a term with g as a function and the rest as arguments, except for a small number of special operators, such as quote, if,... This results in the simplest possible system, but at some expense of readability. KRE / CEL is closer to the standard notation of logic and mathematics.

Lisp Systems - Data Structure (red green blue) represented as red nil bluegreen The e1 and t1 operations follow a pointer (but they are actually called car and cdr in Lisp) The cons operation constructs a new 'yellow' cell This was the origin of the method of garbage collection.

What datastructure for KRE? One possibility: reimplement from scratch (not a very attractive idea) Other possibility: implement "on top of" Lisp (or another similar language). This is a standard approach in the field. Lisp is used as a "high level implementation language". Other languages that are similar to Lisp and that are well suited for the same purpose: Scheme (also S-expression style), Python.

List Processing - Recursive Functions (length.s) == (if [equal.s <>] 0 (+ 1 (length (t1.s)))) (replace.a.b.s) == (if [equal.s.a].b (if [atom.s] s (cons (replace.a.b (e1.s)) (replace.a.b (t1.s)) )))

Information aggregates, continued Working with entityfiles Commands: crek zoo-kb create new knowledgeblock, directory Zoo setk zoo-kb select as current knowledgeblock crefil animals-catal create entityfile in this block loadfil animals-catal load the textual file into session writefil animals-catal write back textual file from session loadk zoo-kb loadfil zoo-kb + loadfil of its 'mustload' For lab2a, recommended to work in 'loadfil mode': text-edit the file and load it from time to time For some purposes the 'writefil' mode is appropriate Directory Zoo contains entityfile zoo-kb which contains info about the other entityfiles in the knowledgeblock

Small Example demofil [: type entityfile] [: latest-written " /07:46.+02"] [: contents ] [: changed-since-archived t] Groucho [: type animal] [: in-species gorilla] [: sex male] [: has-age 15] ooooooooooooooooooooooooooooooooooooooooooooooooooooooooo

Small Example - Type definition ontofil [: type entityfile] [: latest-written " /07:38.+02"] [: contents ] [: changed-since-archived t] animal [: type Type] [: attributes {in-species sex has-age}] ooooooooooooooooooooooooooooooooooooooooooooooooooooooooo

Small Example - Technical additions demofil [: type entityfile] [: latest-written " /07:46.+02"] [: contents ] [: changed-since-archived t] [: nullvalued {has-purpose has-author requires mustload leos-extension has-profile overlay-on overlay-types overlay- own leos-use dont-display sections local-ents purpose author latest-archived-entity latest-rearchived}] Groucho [: type animal] [: in-species gorilla] [: sex male] [: has-age 15] [: latest-rearchived nil] ooooooooooooooooooooooooooooooooooooooooooooooooooooooooo