© enn tyugu1 algorithms of artificial intelligence lecture 8: synthesis of algorithms and plans e....

35
© Enn Tyugu 1 Algorithms of Artificial Intelligence Lecture 8: Synthesis of algorithms and plans E. Tyugu

Upload: pamela-burke

Post on 03-Jan-2016

217 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: © Enn Tyugu1 Algorithms of Artificial Intelligence Lecture 8: Synthesis of algorithms and plans E. Tyugu

© Enn Tyugu 1

Algorithms of Artificial Intelligence

Lecture 8: Synthesis of algorithms and plans

E. Tyugu

Page 2: © Enn Tyugu1 Algorithms of Artificial Intelligence Lecture 8: Synthesis of algorithms and plans E. Tyugu

© Enn Tyugu 2

Where• Behavior of robots

• Simulation of complex systems

• CAD

• HW/SW synthesis and codesign

• Reconfigurable computing

• Flexible OO interfaces

• Active networks (metaprotocols)

• Context-aware computing

• Just-in-time-synthesis of services

Page 3: © Enn Tyugu1 Algorithms of Artificial Intelligence Lecture 8: Synthesis of algorithms and plans E. Tyugu

© Enn Tyugu 3

How

• Transformational synthesis• Inductive Synthesis• Deductive synthesis• Nonmonotonic planning

Page 4: © Enn Tyugu1 Algorithms of Artificial Intelligence Lecture 8: Synthesis of algorithms and plans E. Tyugu

© Enn Tyugu 4

Transformational synthesis

Specification --------------> program rewriting

R. M. Burstall, J. Darlington. A transformation system for developing recursive programs. J. ACM, 24(1), 1977, 44-67.

+ many theoretical works continuously

Page 5: © Enn Tyugu1 Algorithms of Artificial Intelligence Lecture 8: Synthesis of algorithms and plans E. Tyugu

© Enn Tyugu 5

Inductive synthesis

Examples of input-output pairs are used as specifications:

1. (A B C D) gives (D C B A), construct a Lisp program for lists.

2. 1 gives 1, 2 gives 4, 3 gives 9, …, construct an arithmetic program.

A.W. Biermann, R. Kirshnaswany. Constructing programs from example computations. IEEE Trans. On Software Engineering, vol. 2, Sept.1976, 141 -153

More recently -- inductive logic programming (S. Muggleton)

Page 6: © Enn Tyugu1 Algorithms of Artificial Intelligence Lecture 8: Synthesis of algorithms and plans E. Tyugu

© Enn Tyugu 6

Deductive synthesis 1.Prove the theorem: “a solution of the given problem

exists”

2. Extract a program from the proof.

Z. Manna, R. Waldinger. Towards automatic program synthesis. Comm.ACM, 14(3), 1971, 151 -164.

(C. Green did it already in 1969 at IJCAI no. 1.)

Page 7: © Enn Tyugu1 Algorithms of Artificial Intelligence Lecture 8: Synthesis of algorithms and plans E. Tyugu

© Enn Tyugu 7

Idea of structural synthesis of programs

• Problem: Given programs p1,…,pn with specifications A1,…An, and a

specification G called a goal, find a program p that satisfies G.

• Solution: 1) find a (constructive) proof of G from A1,…,An. 2) extract the required program p from the proof.

Page 8: © Enn Tyugu1 Algorithms of Artificial Intelligence Lecture 8: Synthesis of algorithms and plans E. Tyugu

© Enn Tyugu 8

Intuitionistic logic

• Main intuitionistic requirement: a proof of existence of an entity (e.g. of a solution of a

problem) must include construction of such an entity.

• Examples of formulas not valid in intuitionistic logic:

A ~A~ ~A A

Page 9: © Enn Tyugu1 Algorithms of Artificial Intelligence Lecture 8: Synthesis of algorithms and plans E. Tyugu

© Enn Tyugu 9

Example

Are there irrational numbers a and b such that ab is rational?

Classical proof:

Take a=b=2, if 2 is rational, or

a = and b = 2, in the other case - then ab=2 is rational.

This is not a proof in intuitionistic logic, because one can not show the required irrational numbers.

2

22

Page 10: © Enn Tyugu1 Algorithms of Artificial Intelligence Lecture 8: Synthesis of algorithms and plans E. Tyugu

© Enn Tyugu 10

Some inference rules (natural deduction)

A1 … An A

A (& +) Ai (& -)

A

:

B A A B

A B ( +) B ( -)

A1,…,An, B denote formulas, A is an abbreviation for A1&…&An

Page 11: © Enn Tyugu1 Algorithms of Artificial Intelligence Lecture 8: Synthesis of algorithms and plans E. Tyugu

© Enn Tyugu 11

Realizations of formulas In the intuitionistic logic, every formula has a realization

(meaning) in a functional language:

• propositional variables mean objects, or object variables (if they are assumptions)

• if A1, …,An have realizations a1,…,an, then A has the realization (a1,…,an)

• realization of A B is a function f for computing a realization of B from any given realization of A.

Page 12: © Enn Tyugu1 Algorithms of Artificial Intelligence Lecture 8: Synthesis of algorithms and plans E. Tyugu

© Enn Tyugu 12

Building new realizations

A1 a1 … An an A a A a Ai ai

A x : B e A a A B f A B x.e B f(a)

Page 13: © Enn Tyugu1 Algorithms of Artificial Intelligence Lecture 8: Synthesis of algorithms and plans E. Tyugu

© Enn Tyugu 13

Implicative fragment of IPL

• Propositional variables: A, B, Ai,… are formulas

• Conjunctions: if A1,…,An are formulas, then

A1&…&An is a formula (we denote this also by A, if the formulas differ only by indices).

• Implications: if A, B are formulas, then

A B is a formula.

Page 14: © Enn Tyugu1 Algorithms of Artificial Intelligence Lecture 8: Synthesis of algorithms and plans E. Tyugu

© Enn Tyugu 14

Language of the structural synthesis of programs (SSP)

The general form of formulas of SSP is as follows (A, B, C, D denote propositional variables)

(A B) & C D

The implications A B are called subtasks.

Page 15: © Enn Tyugu1 Algorithms of Artificial Intelligence Lecture 8: Synthesis of algorithms and plans E. Tyugu

© Enn Tyugu 15

Subtasks explained

(A B) & … & (C D) & X Y f . . . g f…g x . h

realizations of subtasks, and of the whole axiom.

This can be read as follows:

h computes y from f, … ,g, x, where f computes b from a, … , g computes d from c.

NB! f, …, g are functional variables, h is a higher-order function.

Page 16: © Enn Tyugu1 Algorithms of Artificial Intelligence Lecture 8: Synthesis of algorithms and plans E. Tyugu

© Enn Tyugu 16

Using preprogrammed control structures in SSP

SSP:

(A B) & … & (C D) (X Y) f ….. g h

Prolog:

P :- Q, …, R

Page 17: © Enn Tyugu1 Algorithms of Artificial Intelligence Lecture 8: Synthesis of algorithms and plans E. Tyugu

© Enn Tyugu 17

Two examples

1. h computes maximal value of a function f given as a realization of subtask arg res :

(arg res) max f f.h

n 2. h computes the sum s = ab

b=1

(b a) & n s f f.h

(here we use same notations for propositional variables and respective object variables)

Page 18: © Enn Tyugu1 Algorithms of Artificial Intelligence Lecture 8: Synthesis of algorithms and plans E. Tyugu

© Enn Tyugu 18

Proof rules of SSP

Proof rules of SSP are introduction and elimination rules of conjunction and implication, and the following admissible rule:

(A B) & C D A & F B C & F D

Page 19: © Enn Tyugu1 Algorithms of Artificial Intelligence Lecture 8: Synthesis of algorithms and plans E. Tyugu

© Enn Tyugu 19

An example(Y A) B(A B) XX & Y A

Goal: B

(Y A) B A A (A B) X A B

X & Y A X Y Y (Y A) B Y A

B

Page 20: © Enn Tyugu1 Algorithms of Artificial Intelligence Lecture 8: Synthesis of algorithms and plans E. Tyugu

© Enn Tyugu 20

Simple program extraction

A1 x1 … An xn :

f A B A a B f B f(a) A B x.f(x)

F (A B) & C D A B f C B F(f(a),z)

where z are variables for C.

Page 21: © Enn Tyugu1 Algorithms of Artificial Intelligence Lecture 8: Synthesis of algorithms and plans E. Tyugu

© Enn Tyugu 21

Program extraction(general case)

F (A B)&C D A & G B f C & G D F(f(a,y),z)

where y, z are variables for G and C respectively.

Page 22: © Enn Tyugu1 Algorithms of Artificial Intelligence Lecture 8: Synthesis of algorithms and plans E. Tyugu

© Enn Tyugu 22

ExampleAxioms: i, j, val e

(j e) max (i max) minimaxGoal: val minimax

Proof: (j e) max i, j, val e

(i max) minimax i, val max

val min

j

i eval

Page 23: © Enn Tyugu1 Algorithms of Artificial Intelligence Lecture 8: Synthesis of algorithms and plans E. Tyugu

© Enn Tyugu 23

Example of program extraction

Axioms: (j e) max f (i max) minimax g i, j, val e i,j,v. selectGoal: val min

Proof: (j e) max i, j, val e (i max) minimax i, val max v,i. g( j.select) val min v. f(i. g( j.

select))

Page 24: © Enn Tyugu1 Algorithms of Artificial Intelligence Lecture 8: Synthesis of algorithms and plans E. Tyugu

© Enn Tyugu 24

Proof strategy

• Use the subtasks as late as possible

• Use connection graph for axioms

• Do goal-driven (backward) search for choosing axioms with subtasks

• Do forward search for simple implications

Page 25: © Enn Tyugu1 Algorithms of Artificial Intelligence Lecture 8: Synthesis of algorithms and plans E. Tyugu

© Enn Tyugu 25

Extended structural synthesis

It appeared that also disjunction can be handled efficiently in practical proofs. So one has extended the SSP with disjunnctions, and got ESSP with formulas of the form

(A B) & C D F G Programs derived in ESSP include branching, beause a

realization of a disjunction F G is of the form

if left then f else g,

where f and g are realizations of F and G respectively.

Page 26: © Enn Tyugu1 Algorithms of Artificial Intelligence Lecture 8: Synthesis of algorithms and plans E. Tyugu

© Enn Tyugu 26

Spec language 1) specification of an objectid : type [binging, ...] Examples: i: num;

I1: Integrator T =0.01;

2) axiomprecondition -> postcondition{implementation}Example: (i -> u)& I1.T -> delta; 3) equationexp1 = exp2Example: I * U = R;

Page 27: © Enn Tyugu1 Algorithms of Artificial Intelligence Lecture 8: Synthesis of algorithms and plans E. Tyugu

© Enn Tyugu 27

Translation of specs

• Let a type of Q have the semantics given by a set of formulae FQ. Then

the translation of a statement x : Q is the set of formulae obtained from FQ by prefixing all propositional variables occuring in formulae with

the prefix “x.”

• Semantics of primitive types is empty set of formulae.

• An equation is translated (has semantics) as a set of formulae showing what is computable from what by the equation.

Page 28: © Enn Tyugu1 Algorithms of Artificial Intelligence Lecture 8: Synthesis of algorithms and plans E. Tyugu

© Enn Tyugu 28

Spec language continued

Example:

x1: Oscillator1;

x2: Oscillator2;

process: RungeKutta

model1 = x1,

model2 = x2,

from = 0,

to = 115;

Page 29: © Enn Tyugu1 Algorithms of Artificial Intelligence Lecture 8: Synthesis of algorithms and plans E. Tyugu

© Enn Tyugu 29

Example of synthesis of schemes

I1 : integral to = 1;I2 : integral res = I1.val;F1:I1.arg & I2.arg -> I1.res {a realization of this axiom};F2:I1.arg -> I2.to {a realization of this axiom};Goal: -> I2.val;

I1

I2

F1

F2

fA

BC

A & B C (U V) & X Y

Y

U V

X

Page 30: © Enn Tyugu1 Algorithms of Artificial Intelligence Lecture 8: Synthesis of algorithms and plans E. Tyugu

© Enn Tyugu 30

Planning

Planning is synthesis of an algorithm for achieving a given goal. It can be, in principle, done by means of program synthesis methods. However, there are several special features of planning that prevent the usage of conventional program synthesizers:

• nonmonotous character of achieved subgoals

• frame problem.

Page 31: © Enn Tyugu1 Algorithms of Artificial Intelligence Lecture 8: Synthesis of algorithms and plans E. Tyugu

© Enn Tyugu 31

Planning continuedPlans tend to be shorter and with simpler structure than

computational algorithms.

Common formalisms for planning are

• first-order logic and

• situation calculus.

Quite helpful is hierarchical planning.

Quite conventional are linear and branching plans, iterative and recursive plans appear very seldom.

Page 32: © Enn Tyugu1 Algorithms of Artificial Intelligence Lecture 8: Synthesis of algorithms and plans E. Tyugu

© Enn Tyugu 32

Planning continued Naive planning (that is the most common planing method) uses knowledge

about a set of possible actions where, for each action, its pre- and postconditions are given.

A common example is planning in a block world where actions are for moving blocks:

PICKUP, PUTDOWN, STACK, UNSTACK.

More precise example with pre- and postconditions:

PICKUP (block) possible when ONTABLE(block) CLEAR(block) gives HOLDING(block) NOT CLEAR(block) NOT ONTABLE(block)

We can see the similarity to a rule-based knowledge representation. The planning algorithm is similar to application algorithm of rules.

Page 33: © Enn Tyugu1 Algorithms of Artificial Intelligence Lecture 8: Synthesis of algorithms and plans E. Tyugu

© Enn Tyugu 33

Planning continued

Example of a planning problem:

A B

A

B

C

C

Initial state: Goal state

Page 34: © Enn Tyugu1 Algorithms of Artificial Intelligence Lecture 8: Synthesis of algorithms and plans E. Tyugu

© Enn Tyugu 34

Situation calculus

Situation calculus uses predicate logic extended with situation constants. Each literal, e.g.

Above(x,y)

is extended with an argument showing the situation, e.g. (time moment usually) when this literal is valid:

Above(x,y,s1)

This adds much information and creates the frame problem:

when proceeding from one situation to another, all literals must be recomputed, or there must be some rules for deciding which literals remain unchanged.

Page 35: © Enn Tyugu1 Algorithms of Artificial Intelligence Lecture 8: Synthesis of algorithms and plans E. Tyugu

© Enn Tyugu 35

Hierarchical plans

To avoid large amount of search, planning can be performed in several stages: first rough planning that produces a plan including macro actions that must be made precise either by more planning or by macro substitution.

Planning with time constraints is scheduling. Impressive examples of automatic scheduling by means of program synthesis technique exist, e.g. PLANWARE developed in the Kestrel Institute for scheduling military air transportation in the Pacific area.