artificial intelligence and lisp lecture 3 liu course tddc65 autumn semester, 2010

28
Artificial Intelligence and Lisp Lecture 3 LiU Course TDDC65 Autumn Semester, 2010 http://www.ida.liu.se/ext/TDDC65/

Post on 21-Dec-2015

217 views

Category:

Documents


1 download

TRANSCRIPT

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

Artificial Intelligence and LispLecture 3

LiU Course TDDC65Autumn Semester, 2010

http://www.ida.liu.se/ext/TDDC65/

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

Today's topics

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

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

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)]

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

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)

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

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

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

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

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

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]

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

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)

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

Computational evaluationof 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

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

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.

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

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]

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

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

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

Reification

Compare

[has-phonenumber sven "013-459120"]

[equal (phonenumber sven) "013-459120"]

[Holds (phoneof: sven) "013-459120"]

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)) "013-459120"]

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

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

List Processing in CEL

Operations on recursively nested sequences, called lists Functions: (e1 <a b c>) = a

(e2 <a b c>) = b etc

(en 4 <a b c d e f g>) = d

(t1 <a b c>) = <b c>

(t2 <a b c>) = <c>

(cons a <a b c>) = <a a b c>

(concat <a b> <c d>) = <a b c d>

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

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

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

Lab2a addresses information aggregatesand representation issues

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

Introduction to

KR framework

KnowledgeRepresentation(several parts)

Leonardoinstallation

Software forIntelligent

AgentsManaging

InfoAggregates

Goals of AILogic notes

LeonardoDocument:n

ProgrammingLanguage

Lisp

Lisp in LeoEnvironment

LeonardoFacilities

List Processing

Reading Matter for the course

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

List processing

Recursively nested sequences as the only composite expressions, with symbols, strings, numbers as elements

Functions on sequences (no side-effects!)

(e1 <a b c>) = a (e2 <a b c>) = b

(en 4 <a b c d e f>) = d

(t1 <a b c>) = <b c>

t2, tn similarly

(cons g <a b c>) = <g a b c>

Notice: (cons (e1 .x) (t1 .x)) = x

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

List processing

Predicates on lists

(equal <a b c> <a b c>) = 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

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

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)) )))

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

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 <a b c>) (e1 (quote (a b c))) ssv .a <red green> (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.

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

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' cellThis was the origin of the method of garbage collection.

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

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.

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

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)) )))

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

Information aggregates, continuedWorking 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

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

Small Example

----------------------------------------------------------- demofil

[: type entityfile][: latest-written "2010-09-01/07:46.+02"][: contents <demofil Groucho>][: changed-since-archived t]

----------------------------------------------------------- Groucho

[: type animal][: in-species gorilla][: sex male][: has-age 15]

ooooooooooooooooooooooooooooooooooooooooooooooooooooooooo

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

Small Example - Type definition

----------------------------------------------------------- ontofil

[: type entityfile][: latest-written "2010-09-01/07:38.+02"][: contents <ontofil animal>][: changed-since-archived t]

----------------------------------------------------------- animal

[: type Type][: attributes {in-species sex has-age}]

ooooooooooooooooooooooooooooooooooooooooooooooooooooooooo

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

Small Example - Technical additions----------------------------------------------------------- demofil

[: type entityfile][: latest-written "2010-09-01/07:46.+02"][: contents <demofil Groucho>][: 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