specification formalisms

30
Specification Formalisms Book: Chapter 5

Upload: orenda

Post on 21-Jan-2016

43 views

Category:

Documents


0 download

DESCRIPTION

Specification Formalisms. Book: Chapter 5. Properties of formalisms. Formal. Unique interpretation. Intuitive. Simple to understand (visual). Succinct. Spec. of reasonable size. Effective. Check that there are no contradictions. Check that the spec. is implementable. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Specification Formalisms

Specification Formalisms

Book: Chapter 5

Page 2: Specification Formalisms

Properties of formalisms Formal. Unique interpretation. Intuitive. Simple to understand (visual). Succinct. Spec. of reasonable size. Effective.

Check that there are no contradictions. Check that the spec. is implementable. Check that the implementation satisfies spec.

Expressive. May be used to generate initial code.Specifying the implementation or its properties?

Page 3: Specification Formalisms

A transition system

A (finite) set of variables V. A set of states . A (finite) set of transitions T, each transition e

t has an enabling condition e and a

transformation t. An initial condition I. Denote by R(s, s’) the fact that s’ is a

successor of s.

Page 4: Specification Formalisms

The interleaving model

An execution is a finite or infinite sequence of states s0, s1, s2, …

The initial state satisfies the initial condition, i.e., I(s0).

Moving from one state si to si+1 is by executing a transition e t: e(si), i.e., si satisfies e. si+1 is obtained by applying t to si.

Page 5: Specification Formalisms

LTL: Syntax

::= () | ¬ | Æ Ç U¤} |O | p

¤Always ( = “Henceforth ”)

} Eventually (= “in the future”)

O “next-time ”

U“until ”

W“Waiting for ”

Page 6: Specification Formalisms

Semantics

¤

}

O

U

WUÇ ¤

Page 7: Specification Formalisms

Combinations

¤} p “p will happen infinitely often”

}¤ p “p will happen from some point forever”.

(¤} p) --> (¤} q) “If p happens infinitely often, then q also happens infinitely often”.

Page 8: Specification Formalisms

A Spring Example

s1 s3s2pull

release

release

extended malfunction

r0 = s1 s2 s1 s2 s1 s2 s1 …

r1 = s1 s2 s3 s3 s3 s3 s3 …

r2 = s1 s2 s1 s2 s3 s3 s3 …

Page 9: Specification Formalisms

LTL satisfaction by a single sequence

malfunction

s1 s3s2pull

release

releaseextende

d

r2 = s1 s2 s1 s2 s3 s3 s3 …

r2 ² extended ??

r2 ² O extended ??

r2 ² O O extended ??

r2 ² } extended ??

r2 ² ¤ extended ??

r2 ² } ¤ extended ??

r2 ² } ¤ malfunction ??

r2 ² ¬ } ¤ extended ??

r2 ² (¬extended) U malfunction ??

r2 ² ¤ (¬extended ! O extended) ??

Page 10: Specification Formalisms

LTL satisfaction by a system

malfunction

s1 s3s2pull

release

releaseextende

d

A ² extended ??

A ² O extended ??

A ² O O extended ??

A ² } extended ??

A² ¤ extended ??

A ² } ¤ extended ??

A ² } ¤ malfunction ??

A ² ¬ } ¤ extended ??

A ² (¬extended) U malfunction ??

A ² ¤(¬extended->O extended) ??

A:

Page 11: Specification Formalisms

Automata over finite words

A=<, S, , I, F> Alphabet (finite). S: States (finite). : S x x S ) S is the transition relation. I µ S are the Initial states. F µ S are the Final (accepting) states.

A

A

B BS0 S1

Page 12: Specification Formalisms

Equivalently: A Kripke structure

A convenient model for describing reactive systems

There exists a 1-1 translation between a Kripke structure and an automaton

A=<S, , I, L> S: States (finite). µ S x S is the transition relation. I µ S are the Initial states. L: S ) 2AP (where AP is a set of atomic propositions)

S0 S1

Page 13: Specification Formalisms

The transition relation

(S0, A, S0) (S0, B, S1) (S1, A, S0) (S1, B, S1)

A

A

B BS0 S1

Page 14: Specification Formalisms

A run over a word

A word over , e.g., ABAAB. A sequence of states, e.g. S0 S0 S1 S0

S0 S1. Starts with an initial state. Accepting if ends at accepting state.

A

A

B BS0 S1

Page 15: Specification Formalisms

The language of an automaton

The words that are accepted by the automaton.

Includes AABBBA, ABBBBA. Does not include ABAB, ABBB. What is the language?

A

A

B BS0 S1

Page 16: Specification Formalisms

Nondeterministic automaton

Transitions: (S0,A,S0), (S0,B,S0), (S0,A,S1),(S1,A,S1).

What is the language of this automaton?

A,B A AS0 S1

Page 17: Specification Formalisms

Equivalent deterministic automaton

A,B A AS0 S1

B

AA

S0 S1B

Page 18: Specification Formalisms

Automata over infinite words

Similar definition. Runs on infinite words over . Accepts when an accepting state

occurs infinitely often in a run.

A

A

B BS0 S1

Page 19: Specification Formalisms

Automata over infinite words

Consider the word A B A B A B A B… There is a run S0 S0 S1 S0 S1 S0 S1

… This run is accepting, since S0 appears

infinitely many times.

A

A

B BS0 S1

Page 20: Specification Formalisms

Other runs

For the word B B B B B… the run is S0 S1 S1 S1 S1… and is not accepting.

For the word A A A B B B B B …, therun is S0 S0 S0 S0 S1 S1 S1 S1 …

What is the run for A B A B B A B B B …?

A

A

B BS0 S1

Page 21: Specification Formalisms

Nondeterministic automaton

What is the language of this automaton? What is the LTL specification if

B = (pc0=cr0), A=¬B?

A,B A AS0 S1

Page 22: Specification Formalisms

Specification using Automata

Let each letter correspond to some propositional property.

Example: A = P0 enters critical section B = P0 does not enter critical section.

¤ } pc0=cr0

BA

A

BS0 S1

Page 23: Specification Formalisms

Mutual Exclusion

¬(pc0=cr0 Æ pc1=cr1)

A: pc0=cr0 Æ pc1=cr1 B: ¬(pc0=cr0 Æ pc1=cr1) C: TRUE

B A CS0 S1

Page 24: Specification Formalisms

L0:While True do

nc0:wait (Turn=0);

cr0:Turn=1

T0:pc0=L0 ! pc0:=nc0

T1:pc0=nc0 Æ Turn=0 ! pc0:=cr0

T2:pc0=cr0 ! (pc0,Turn):=(L0,1)

T3:pc1=L1 ! pc1=nc1

T4:pc1=nc1Æ Turn=1 ! pc1:=cr1

T5:pc1=cr1 ! (pc1,Turn):=(L1,0)

Initially: pc0=L0 Æ pc1=L1

L1:While True do

nc1:wait (Turn=1);

cr1:Turn=0

||

Possible transitions:

Page 25: Specification Formalisms

The state space

Turn=0L0,L1

Turn=0L0,nc1

Turn=0nc0,L1

Turn=0cr0,nc1

Turn=0nc0,nc1

Turn=0cr0,L1

Turn=1L0,cr1

Turn=1nc0,cr1

Turn=1L0,nc1

Turn=1nc0,nc1

Turn=1nc0,L1

Turn=1L0,L1

Page 26: Specification Formalisms

Turn=0L0,L1

Turn=0L0,nc1

Turn=0nc0,L1

Turn=0cr0,nc1

Turn=0nc0,nc1

Turn=0cr0,L1

Turn=1L0,cr1

Turn=1nc0,cr1

Turn=1L0,nc1

Turn=1nc0,nc1

Turn=1nc0,L1

Turn=1L0,L1

:(pc0=cr0 Æ pc1=cr1)

Page 27: Specification Formalisms

Turn=0L0,L1

Turn=0L0,nc1

Turn=0nc0,L1

Turn=0cr0,nc1

Turn=0nc0,nc1

Turn=0cr0,L1

Turn=1L0,cr1

Turn=1nc0,cr1

Turn=1L0,nc1

Turn=1nc0,nc1

Turn=1nc0,L1

Turn=1L0,L1

(Turn=0 ! } Turn=1)

Page 28: Specification Formalisms

Correctness condition

We want to find a correctness condition for a model to satisfy a specification.

Language of a model: L(Model) Language of a specification:

L(Spec).

We need: L(Model) L(Spec).

Page 29: Specification Formalisms

Correctness

All sequences

Sequences satisfying Spec

Program executions

Page 30: Specification Formalisms

Incorrectness

All sequences

Sequences satisfying Spec

Program executions

Counter

examples