sequential abstract state machines capture sequential algorithms

50
SEQUENTIAL ABSTRACT STATE MACHINES CAPTURE SEQUENTIAL ALGORITHMS

Post on 22-Dec-2015

238 views

Category:

Documents


4 download

TRANSCRIPT

Page 1: SEQUENTIAL ABSTRACT STATE MACHINES CAPTURE SEQUENTIAL ALGORITHMS

SEQUENTIAL ABSTRACT STATE

MACHINESCAPTURE

SEQUENTIAL ALGORITHMS

Page 2: SEQUENTIAL ABSTRACT STATE MACHINES CAPTURE SEQUENTIAL ALGORITHMS

•The “official" Turing thesis is that every computable function is Turing computable.

•Turing stronger thesis: every algorithm can be simulated by a Turing machine.

•Can one generalize Turing machines so that any algorithm, never mind how abstract, can be modeled by a generalized machine very closely and faithfully?

Page 3: SEQUENTIAL ABSTRACT STATE MACHINES CAPTURE SEQUENTIAL ALGORITHMS

The obvious answer seems to be NO..

• Suppose such generalized Turing machines exist..

• What would their states be?• What instructions should the

generalized machines have? • Can one get away with only a

bounded set of instructions?

Page 4: SEQUENTIAL ABSTRACT STATE MACHINES CAPTURE SEQUENTIAL ALGORITHMS

“A New Thesis” [Gurevich 1985]

If we stick to one abstraction level (abstracting from low-level details and being oblivious to a possible higher-level picture)

And if the states of the algorithm reflect all the pertinent information

Then a particular small instruction set suffices in all cases.

Page 5: SEQUENTIAL ABSTRACT STATE MACHINES CAPTURE SEQUENTIAL ALGORITHMS

• First-order structures with purely functional vocabulary are called algebras.

• Accordingly, the new machines were called dynamic structures/ dynamic algebras/ evolving algebras.

• The evolving-algebra-community changed it to abstract state machines, or ASMs.

Page 6: SEQUENTIAL ABSTRACT STATE MACHINES CAPTURE SEQUENTIAL ALGORITHMS

The Original Sequential ASM Thesis

“Every sequential algorithm can be step-

for-step simulated by an appropriate sequential

ASM.”

Page 7: SEQUENTIAL ABSTRACT STATE MACHINES CAPTURE SEQUENTIAL ALGORITHMS

What are sequential algorithms exactly?

A sequential algorithm is any object that satisfies the next three postulates:

• The Sequential Time Postulate.• The Abstract-State Postulate.• The Bounded-Exploration Postulate.

Page 8: SEQUENTIAL ABSTRACT STATE MACHINES CAPTURE SEQUENTIAL ALGORITHMS

The First Postulate:

SEQUENTIAL TIME

Page 9: SEQUENTIAL ABSTRACT STATE MACHINES CAPTURE SEQUENTIAL ALGORITHMS

Syntax

• Any algorithm A can be given by a finite text.

• We will concentrate on the behavior of algorithms, and not on the language it’s programmed in.

Page 10: SEQUENTIAL ABSTRACT STATE MACHINES CAPTURE SEQUENTIAL ALGORITHMS

Behavior

Let A be a sequential algorithm.A is associated with:• A set S(A) whose elements will be

called states of A.• A subset I(A) of S(A) whose elements

will be called initial states of A.• A map TA: S(A) S(A) that will be

called the one-step transformation of A.

Page 11: SEQUENTIAL ABSTRACT STATE MACHINES CAPTURE SEQUENTIAL ALGORITHMS

Some Definitions For The Future..

• A run (or computation) of A is a finite or infinite sequence X0,X1,X2,….. where X0 is an initial state and every Xi+1 =TA(Xi).The computation steps of A form a sequence. In that sense the computation time is sequential.

• Algorithms A and B are equivalent ifS(A)=S(B), I(A)=I(B),TA=TB.

Equivalent algorithms have the same runs.

Page 12: SEQUENTIAL ABSTRACT STATE MACHINES CAPTURE SEQUENTIAL ALGORITHMS

• States are Full instantaneous descriptions of the algorithm.

• A state X of an algorithm A reachable if X occurs in some run of A.

• we do not require that an algorithm halts on all inputs.

• We stipulate that TA(X) = X if A terminates in a state X.

Page 13: SEQUENTIAL ABSTRACT STATE MACHINES CAPTURE SEQUENTIAL ALGORITHMS

Why do we need the other 2 postulates?

• Example 1

do for all x,y with Edge(x,y) R(x) R(y)

R(y):=true;

The algorithm is sequential-time but it is highly parallel.

A sequential algorithm should make only local changes.

The total change should be bounded.

Page 14: SEQUENTIAL ABSTRACT STATE MACHINES CAPTURE SEQUENTIAL ALGORITHMS

• Example 2 If x y Edge(x,y) then Output:=false; else Output:=true;

The algorithm changes only one Boolean but it explores the whole graph in one step.

A sequential algorithm should be not only bounded change, but also bounded-exploration.

Page 15: SEQUENTIAL ABSTRACT STATE MACHINES CAPTURE SEQUENTIAL ALGORITHMS

The Second Postulate:

ABSTRACT

STATE

Page 16: SEQUENTIAL ABSTRACT STATE MACHINES CAPTURE SEQUENTIAL ALGORITHMS

Lets talk a bit more about the notion

STATE

Page 17: SEQUENTIAL ABSTRACT STATE MACHINES CAPTURE SEQUENTIAL ALGORITHMS

Until now, states were merely elements of the set of states.

Now, we argue that states can be viewed as (first-order) structures of mathematical logic.

What exactly is this structure? We will describe its syntax and its semantics.

Page 18: SEQUENTIAL ABSTRACT STATE MACHINES CAPTURE SEQUENTIAL ALGORITHMS

Syntax• A vocabulary is a finite collection of

function names. Some function names may be marked

as relational. Every vocabulary contains:

* The equality sign.* true, false and undef.* The unary name Boole.* the names of the usual

Boolean operations.

Page 19: SEQUENTIAL ABSTRACT STATE MACHINES CAPTURE SEQUENTIAL ALGORITHMS

• Terms are defined by the usual induction.

A nullary function is a term.

If f is a function name of positive arity j and if t1,…,tj are terms, then f(t1,…, tj) is a term.

If the outermost function name is

relational, then the term is Boolean.

Page 20: SEQUENTIAL ABSTRACT STATE MACHINES CAPTURE SEQUENTIAL ALGORITHMS

Semantics• A structure X of vocabulary is a

nonempty set S (the base set of X), together with interpretations of the function names in over S.

• A j-ary function name is interpreted as afunction from S to S, a basic function of X.

• We identify a nullary function with its value.

• A j-ary relation R is a function from S to {true,false}, a basic relation of X.

j

j

Page 21: SEQUENTIAL ABSTRACT STATE MACHINES CAPTURE SEQUENTIAL ALGORITHMS

Example of states as structures:The Euclidean algorithm

The goal is to find greatest common divisor (gcd) of two natural numbers a and b.

One step of the algorithm can be described as:if b=0 then d:=a;else if b=1 then d:=1;else

para := b;b := a mod b;

The base set of any state X of the algorithm includes: *Set of natural numbers (which comes with 0,1 as

distinguished elements). *The binary operation mod.*Three dynamic distinguished elements a, b and d.

Page 22: SEQUENTIAL ABSTRACT STATE MACHINES CAPTURE SEQUENTIAL ALGORITHMS

Isomorphism

Let X and Y be structures of the same vocabulary .

Recall that an isomorphism from X onto Y is a one-to-one function from the base set of X onto the base set of Y, such that f( x1,…, xj) = x0 in Y whenever f(x1,…, xj) = x0 in X.

Page 23: SEQUENTIAL ABSTRACT STATE MACHINES CAPTURE SEQUENTIAL ALGORITHMS

Up-to-Isomorphism Abstraction

• Distinct isomorphic structures are just different representations of the same isomorphic type

• Isomorphic structures have the same computational power.

• Suppose that X and Y are distinct states of the algorithm A and is an isomorphism from X onto Y, maps the base set of X onto the base set of Y, and preserves all functions of X.

Page 24: SEQUENTIAL ABSTRACT STATE MACHINES CAPTURE SEQUENTIAL ALGORITHMS

In a more graphic way…

x

x’

f( x)

f ’( x’)

f A

Mapping A ~ A’

f ’ A’

“101”

5

“110”

6

f

f ’

Page 25: SEQUENTIAL ABSTRACT STATE MACHINES CAPTURE SEQUENTIAL ALGORITHMS

Fixed Vocabulary

• In logic, the vocabularies are not necessarily finite.

• In our case, by definition, vocabularies are finite.

• The vocabulary does not change during that evolution.

Page 26: SEQUENTIAL ABSTRACT STATE MACHINES CAPTURE SEQUENTIAL ALGORITHMS

The Base Set• The base set can change from one initial

state to another.• The base set does not change during the

computation.• All states of a given run have the same

base set.

Does it make any sense??

Page 27: SEQUENTIAL ABSTRACT STATE MACHINES CAPTURE SEQUENTIAL ALGORITHMS

The Environment

• The initial state contains an infinite set, the reserve.

• The environment’s job is to get the elements from the reserve.

• We can use a special external function to fish out an element from the reserve.

• That function is controlled by the environment.

Page 28: SEQUENTIAL ABSTRACT STATE MACHINES CAPTURE SEQUENTIAL ALGORITHMS

More exact wording of the second postulate

• States of A are first-order structures.• All states of A have the same

vocabulary.• The one-step transformation TA does

not change the base set of any state.• S(A) and I(A) are closed under

isomorphism. Further, any isomorphism from a state X onto a state Y is also an isomorphism from TA(X) onto TA(Y ).

Page 29: SEQUENTIAL ABSTRACT STATE MACHINES CAPTURE SEQUENTIAL ALGORITHMS

The third Postulate:

BOUNDED

EXPLORATION

Page 30: SEQUENTIAL ABSTRACT STATE MACHINES CAPTURE SEQUENTIAL ALGORITHMS

States as Memories• If f is a j-ary function name and a is a j-tuple of

elements of X, then the pair (f,a) is a location.• ContentX(f,a) is the element f(a) in X.• If (f,a) is a location of X and b is an element of

X, then (f,a,b) is an update of X.• Two updates clash if they refer to the same

location but are distinct.• A set of updates is consistent if it has no

clashing updates.• The result of executing an update set over X

will be denoted X+ .

Page 31: SEQUENTIAL ABSTRACT STATE MACHINES CAPTURE SEQUENTIAL ALGORITHMS

LEMMA: If X,Y are structures of the same vocabulary and with the same base set, then there is a unique consistent set of nontrivial updates of X such that Y = X+ .

PROOF:X and Y have the same locations. The desired set is:

{(f,a,b)| b=ContentY(f,a) ContentX(f,a)}.

THE SET WILL BE DENOTED Y-X

Page 32: SEQUENTIAL ABSTRACT STATE MACHINES CAPTURE SEQUENTIAL ALGORITHMS

The Update Set of an Algorithm at a State

Let X be a state of an algorithm A.

By the abstract-state postulate, X and TA(X)have the same elements and the same

locations. Define: (A,X) TA(X)-Xso that TA(X)=X+ (A,X).

Page 33: SEQUENTIAL ABSTRACT STATE MACHINES CAPTURE SEQUENTIAL ALGORITHMS

The Accessibility Principle

• According to the abstract-state postulate, an algorithm A does not distinguish between isomorphic states.

• A state X of A is just a particular implementation of its isomorphism type.

• How can A access an element a of X? One way is to produce a ground term that

evaluates to a in X. • The assertion that this is the only way can

be called the sequential accessibility principle.

Page 34: SEQUENTIAL ABSTRACT STATE MACHINES CAPTURE SEQUENTIAL ALGORITHMS

• An element a of a structure X is accessible if a = Val (t,X) for some ground term t in the vocabulary of X.

• A location (f,a) is accessible if every member of the tuple a is accessible.

• An update (f,a,b) is accessible if both the location (f,a) and the element b are accessible.

Page 35: SEQUENTIAL ABSTRACT STATE MACHINES CAPTURE SEQUENTIAL ALGORITHMS

The accessibility principle and the informal assumption that

any algorithm has a finite program indicate that any

given algorithm A examines only a bounded number of

elements in any state.

Page 36: SEQUENTIAL ABSTRACT STATE MACHINES CAPTURE SEQUENTIAL ALGORITHMS

And yet another definition..

We say that two structures X and Y of the

same vocabulary coincide over a set T

of -terms if Val(t,X)=Val(t,Y) for all t T.

Page 37: SEQUENTIAL ABSTRACT STATE MACHINES CAPTURE SEQUENTIAL ALGORITHMS

More exact wording of the third postulate

• There exists a finite set T of termsin the vocabulary of A such that (A,X)= (A,Y) whenever states X,Y of Acoincide over T.

• Intuitively, the algorithm A examines only the part of the given state which is given by means of terms in T.

• The set T itself is a bounded-exploration witness for A.

Page 38: SEQUENTIAL ABSTRACT STATE MACHINES CAPTURE SEQUENTIAL ALGORITHMS

ANALYSIS OF THE

POSTULATES

ANDTHE MAIN THEOREM

Page 39: SEQUENTIAL ABSTRACT STATE MACHINES CAPTURE SEQUENTIAL ALGORITHMS

• Let T be a bounded-exploration witness for algorithm A. Without loss of generality, we assume the following:

*T is closed under subterms.*T contains the logical terms true,

false, undef.

• Call terms in T critical.

• For every state X, the values of critical terms in X will be called critical elements of X.

Page 40: SEQUENTIAL ABSTRACT STATE MACHINES CAPTURE SEQUENTIAL ALGORITHMS

• An update rule of vocabulary has the form f(t1,…, tj) := t0 where f is a j-ary function symbol in and t0,…, tj are terms over .

• Every update in (A,X) can be programmed as an update rule.

• To execute all updates in (A,X) in parallel, as a single transaction, we’ll use the par construct:

parR1..

Rk

endpar

• The par rules are called blocks. • The empty block is abbreviated to skip.

Page 41: SEQUENTIAL ABSTRACT STATE MACHINES CAPTURE SEQUENTIAL ALGORITHMS

• If R is an update rule f(t1,…, tj) := t0 and ai = Val (ti,X) for i = 0,…, j then (R,X) {(f,(a1,…, aj), a0)}

• If R is a par rule with constituents R1,…,Rk then (R,X) (R1,X) (Rk,X).

• For every state X, there exists a rule R such that:

*R uses only critical terms.* (R ,X) = (A,X).

X

X

X

Page 42: SEQUENTIAL ABSTRACT STATE MACHINES CAPTURE SEQUENTIAL ALGORITHMS

LEMMA

If states X and Y coincide over the set T of critical terms, then (R ,Y)= (A, Y).

(R ,Y)= (R ,X)= (A,X)= (A,Y).

PROOF

x

XX

X and Y has the same critical terms.

By the definition of R

X and Y coincide

x

Page 43: SEQUENTIAL ABSTRACT STATE MACHINES CAPTURE SEQUENTIAL ALGORITHMS

Lemma:Suppose that X,Y are states and (R ,Z) = (A,Z)

for some state Z isomorphic to Y,Then (R ,Y)= (A, Y).

Definition:At each state X, the equality relation between

critical elements induces an equivalence relation EX(t1, t2) Val (t1,X) = Val (t2,X) over critical terms. Call states X,Y T-similar if EX = EY .

Lemma: (R ,Y )= (A,Y) for every state Y T-similar to X.

x

x

x

Page 44: SEQUENTIAL ABSTRACT STATE MACHINES CAPTURE SEQUENTIAL ALGORITHMS

• For every state X, there exists a Boolean term that evaluates to true in a structure Y if and only if Y is T-similar to X.

• There is a finite set {X1,…,Xm} of states such that every state is T-similar to one of the states Xi.

• To program A on all states, we need a single rule that is applied to every state X and has the effect of R at X.

x

x

Page 45: SEQUENTIAL ABSTRACT STATE MACHINES CAPTURE SEQUENTIAL ALGORITHMS

CONDITIONAL RULESIf is a Boolean term over vocabulary

and R1,R2 are rules of vocabulary thenif then R1

else R2

endif

is a rule of vocabulary .To fire R at any -structure X, evaluate at

X. If the result is true then (R,X)= (R1,X)

otherwise (R,X) = (R2,X).

Page 46: SEQUENTIAL ABSTRACT STATE MACHINES CAPTURE SEQUENTIAL ALGORITHMS

MAIN LEMMAFor every sequential algorithm A of

vocabulary , there is an ASM program of vocabulary such that ( ,X)= (A,X) for all states X of A.

PROOF

Let X1,…,Xm be states. The desired is:par if then R . .

if then Rendpar

Given a program , T (X) X+ ( ,X).

1x 1x

mxmx

Page 47: SEQUENTIAL ABSTRACT STATE MACHINES CAPTURE SEQUENTIAL ALGORITHMS

One Last DefinitionA sequential abstract state machine B of

vocabulary is given by:* a program of vocabulary .* a set S(B) of -structures closed under isomorphisms and under the map T .* a subset I(B) S(B) that is closed under

isomorphisms.* the map TB which is the restriction of

T to S(B).

Page 48: SEQUENTIAL ABSTRACT STATE MACHINES CAPTURE SEQUENTIAL ALGORITHMS

• It is easy to see that an abstract state machine satisfies the sequential-time,abstract-state and bounded-exploration postulates.

• By Definition, it is an algorithm.• Recall the definition of equivalent

algorithms : Algorithms A and B are equivalent ifS(A)=S(B), I(A)=I(B),TA=TB.

Page 49: SEQUENTIAL ABSTRACT STATE MACHINES CAPTURE SEQUENTIAL ALGORITHMS

MAIN THEOREM“For every sequential algorithm A, there

exists an equivalent sequential abstract state machine B.”

PROOF

By the Main Lemma, there exists an ASM program such that ( ,X) = (A ,X) for all states X of A.Set S(B) = S(A) and I(B) = I(A).

Page 50: SEQUENTIAL ABSTRACT STATE MACHINES CAPTURE SEQUENTIAL ALGORITHMS

The end!!

(Finally.. )