Relational Interfaces Relational Interfaces Stavros Tripakis UC - - PowerPoint PPT Presentation

relational interfaces relational interfaces
SMART_READER_LITE
LIVE PREVIEW

Relational Interfaces Relational Interfaces Stavros Tripakis UC - - PowerPoint PPT Presentation

Relational Interfaces Relational Interfaces Stavros Tripakis UC Berkeley Joint work with Ben Lickly, Joint work with Ben Lickly, Tom Henzinger and Edward Lee UC Berkeley, Feb 2010 Component Based Design Component Based Design How can we


slide-1
SLIDE 1

Relational Interfaces Relational Interfaces

Stavros Tripakis

UC Berkeley

Joint work with Ben Lickly, Joint work with Ben Lickly, Tom Henzinger and Edward Lee

UC Berkeley, Feb 2010

slide-2
SLIDE 2

Component‐Based Design Component Based Design

  • How can we build large, complex systems

How can we build large, complex systems from smaller, simpler systems?

– We call the latter components

  • Raises many interesting questions:

– What kind of components do we need?

  • What are the right building blocks?

– Which components to use and how to connect them? connect them? – What is a component? How to reason about components?

2

slide-3
SLIDE 3

Interface theories [e.g., Alfaro, Henzinger, et al.] Interface theories [e.g., Alfaro, Henzinger, et al.]

  • Interface = component abstraction

Interface = component abstraction

  • Interface composition: A • B = C

f f ’

  • Interface refinement: A’ ≤ A
  • Theorems:

(1) If A’ ≤ A and A satisfies P then A’ satisfies P. (2) If A’ ≤ A and B’ ≤ B, then A’ • B’ ≤ A • B.

3

slide-4
SLIDE 4

Substitutability Substitutability

  • Incremental design

T d d i

B A

  • Top‐down design

A’ B’ B’

(1) If A’ ≤ A and A satisfies P then A’ satisfies P.

4

( ) (2) If A’ ≤ A and B’ ≤ B, then A’ • B’ ≤ A • B.

slide-5
SLIDE 5

Synthesis of abstractions Synthesis of abstractions

  • Bottom‐up design

B A A’ B’ B’

If A and B are interfaces then we can compute an

5

p interface for their composition: A • B.

slide-6
SLIDE 6

Tons of related work … Tons of related work …

  • Floyd, Hoare, Dijkstra, Wirth, …, 1960s, 1970s, …: pre/post‐conditions, stepwise

y , , j , , , , , p /p , p refinement, …

  • Abrial, 1980s, 1990s: the Z notation, the B method
  • Back, 1980s, …: refinement calculus
  • Liskov 1980s: Modular program construction using abstractions

Liskov, 1980s: Modular program construction using abstractions

  • Meyer, 1980s: Eiffel, contracts (pre/post‐conditions), subcontracting

(inheritance)

  • Lynch, 1980s: I/O automata
  • Dill 1980s: Trace theory for automatic hierarchical verification of speed
  • Dill, 1980s: Trace theory for automatic hierarchical verification of speed‐

independent circuits

  • Misra/Chandy, Jones, Barringer/Kuiper/Pnueli, Stark, …, many others, 1980s,

1990s, 2000s, …: compositional verification, assume‐guarantee, … B 1990 FOCUS

  • Broy, 1990s, …: FOCUS
  • Software engineering: software reuse, modularization, Parnas, many others, …
  • Type theory: covariance/contravariance

6

slide-7
SLIDE 7

Non‐relational Interfaces

e.g., [Doyen et al., EMSOFT’08]

S t di t i t d t t

  • Separate predicates over inputs and outputs

Assumption about inputs Guarantee

  • ver outputs

Divide x1 ≥ 0 x2 > 0 y ≥ 0

  • Cannot express input‐output relations:

y = x1/x2

7

slide-8
SLIDE 8

Relational Interfaces

[this work]

P di t b th i t d t t

  • Predicates over both inputs and outputs

Di id x1 ≥ 0 y ≥ 0

  • Can express input‐output relations:

Divide x2 > 0 y ≥ 0

Can express input output relations:

deterministic (function)

1 2

x y x = ∧ ≠

(f )

2 2

x

non‐deterministic (relation)

1 2

x y x = → ≠

8

2

x

slide-9
SLIDE 9

Plan of talk Plan of talk

  • Relational interfaces

Relational interfaces

– Stateless, stateful

  • Environments and pluggability
  • Environments and pluggability
  • Refinement

– Refinement and pluggability

  • Composition

– Connection, feedback – Preservation of refinement by composition y p

9

slide-10
SLIDE 10

Plan of talk Plan of talk

  • Relational interfaces

Relational interfaces

– Stateless, stateful

  • Environments and pluggability
  • Environments and pluggability
  • Refinement

– Refinement and pluggability

  • Composition

– Connection, feedback – Preservation of refinement by composition y p

10

slide-11
SLIDE 11

Stateless Relational Interfaces Stateless Relational Interfaces

) ( φ Y X I

Set of input variables S t f t t i bl

) , , ( φ Y X I =

I

X Y

Set of input variables Set of output variables

M M

I

φ X Y

M M

φ

Contract

11

slide-12
SLIDE 12

Contracts Contracts

  • Semantically: relations between input and

y p

  • utput assignments:

) ( ) ( ) ( Y X A Y A X A ∪ = × ⊆ φ

Set of all assignments

  • ver variables in X

φ

Set of all assignments

  • ver variables in Y

A(X) A(Y)

  • Syntactically: predicates or something similar

1

x ≠

12

2 1 2

x y x = ∧ ≠

slide-13
SLIDE 13

Assumptions and Guarantees Assumptions and Guarantees

  • Input assumptions: set of legal input

Input assumptions: set of legal input assignments

) ( : ) ( X A Y in ⊆ ∃ ≡ φ φ

  • Output guarantees: set of possible output

) ( : ) ( X A Y in ⊆ ∃ ≡ φ φ

  • Output guarantees: set of possible output

assignments

) ( ) ( Y A X ∃ φ φ ) ( : ) ( Y A X

  • ut

⊆ ∃ ≡ φ φ

13

slide-14
SLIDE 14

Assumptions and Guarantees Assumptions and Guarantees

  • Input assumptions: set of legal input

Input assumptions: set of legal input assignments

φ φ : ) ( Y in ∃ ≡ φ φ ) (

1

x ) (

2 2 1 2

≠ ≡ = ∧ ≠ x x x y x in true x x y x in ≡ = → ≠ ) (

2 1 2

14

slide-15
SLIDE 15

Stateful Relational Interfaces Stateful Relational Interfaces

) ( ξ Y X I ) , , ( ξ Y X I =

*

) ( ) ( :

*

Y X C Y X A ∪ → ∪ ξ

Set of all possible states over X U Y Set of all possible contracts over X U Y Stateless = special case of stateful state = history = a1 a2 … ak

15

p = same contract at all states

slide-16
SLIDE 16

Example of stateful interface: d l unit delay

1 2 3 4 5 x y 0 1 2 3 4 5 ... v0 0 1 2 3 4 ... x: y:

unit‐delay

x y

) }, { }, ({

ud ud

y x I ξ = )) ( ( ) ( ) ( ) ( x a y a s v y

d ud

= ≡ ⋅ = ≡ ξ ε ξ )) ( ( ) ( x a y a s

ud

ξ

i iti l t t last step

Infinite‐state interface

16

initial state last step

slide-17
SLIDE 17

Example of finite‐state interface: l b ff 1‐place buffer

1 l

data in data out

1‐place buffer

data_in write full read data_out empty

Note: this says almost nothing about implementation

Global contract: (holds at all states)

) full empty ( ∧ ¬

State‐dependent contracts:

d Note: this says almost nothing about implementation Note: this says nothing about data

) read write ( ) p y ( ∧ ¬ ∧

write write read

¬ ¬

read empty ¬ → ∧

s1 s0 empty full read

17

write full ¬ → ∧

empty full

slide-18
SLIDE 18

Well‐formed and well‐formable f interfaces

  • Well‐formed:

Well formed:

– Every reachable state has a satisfiable contract

  • Well formable
  • Well‐formable:

– Can be made well‐formed by restricting the inputs – Amounts to finding a winning strategy in a game [Alfaro‐Henzinger ‘01, Dill ‘89, Back ‘90]

l f

  • For stateless interfaces,

well‐formed = well‐formable = satisfiable

18

slide-19
SLIDE 19

Plan of talk Plan of talk

  • Relational interfaces

Relational interfaces

– Stateless, stateful

  • Environments and pluggability
  • Environments and pluggability
  • Refinement

– Refinement and pluggability

  • Composition

– Connection, feedback – Preservation of refinement by composition y p

19

slide-20
SLIDE 20

Environments and Pluggability Environments and Pluggability

E i t Environment

Interface

20

slide-21
SLIDE 21

Environments Environments

) ( Y X E φ φ ) , , , (

Y X

Y X E φ φ =

predicate on X (possible inputs) predicate on Y (desirable outputs)

Environment

Interface

X Y

Think precondition/postcondition

21

X Y

slide-22
SLIDE 22

Pluggability Pluggability

) ( φ Y X I = ) , , , (

Y X

Y X E φ φ = ) , , ( φ Y X I =

  • Interface I is pluggable to environment E if:

) , , , (

Y X

φ φ

p gg

X

in X φ φ → ∀ ) ( :

Y X

Y X φ φ φ → ∧ ∀ : ,

22

slide-23
SLIDE 23

Plan of talk Plan of talk

  • Relational interfaces

Relational interfaces

– Stateless, stateful

  • Environments and pluggability
  • Environments and pluggability
  • Refinement

– Refinement and pluggability

  • Composition

– Connection, feedback – Preservation of refinement by composition y p

23

slide-24
SLIDE 24

Refinement Refinement

) ( ) ' ( ' φ φ Y X I Y X I ≤ ) , , ( ) ' , , ( ' φ φ Y X I Y X I = ≤ =

iff

φ φ → ∀ ) ' ( ) ( i i X

iff

φ φ φ φ φ → ∧ ∀ → ∀ ' ) ( : , ) ' ( ) ( : in Y X in in X φ φ φ → ∧ ∀ ) ( : , in Y X

24

slide-25
SLIDE 25

Refinement examples Refinement examples

φ φ φ φ φ → ∀ → ∀ ' ) ( : ) ' ( ) ( : i Y X in in X φ φ φ → ∧ ∀ ' ) ( : , in Y X

y x y x y x = + ∨ = ≤ = 1

more deterministic

  • utputs

2 1 2 2 1 2

x x y x x x y x = ∧ ≠ ≤ = → ≠

more legal inputs

) 1 ( y x y x x y x = + ∨ = ∧ > ≤ =

  • r both

25

slide-26
SLIDE 26

Refinement properties Refinement properties

  • Reflexive, transitive, antisymmetric: partial order
  • Top element: false

false false in false → ∧ → ' ) ' ( φ φ

  • No bottom element

φ φ φ → t i true in ) ( ) (

– true is not bottom: – constant outputs are minimal elements

b d d f d

φ φ → ∧ true in ) (

  • Least upper bound defined
  • Greatest lower bound: sometimes defined

– C.f. shared refinement

26

slide-27
SLIDE 27

Main results (1) Main results (1)

  • Refinement characterizes pluggability:
  • Refinement characterizes pluggability:

– I’ ≤ I iff for all environments E, pluggable(I,E) implies pluggable(I’,E) – Note that this is iff – If we used an alternative notion of refinement (c.f., Meyer’s subcontracting): y g) φ φ φ φ → ∀ → ∀ ' : , ) ' ( ) ( : Y X in in X – then if direction would not hold – neither would the last two examples φ φ , p

27

slide-28
SLIDE 28

Plan of talk Plan of talk

  • Relational interfaces

Relational interfaces

– Stateless, stateful

  • Environments and pluggability
  • Environments and pluggability
  • Refinement

– Refinement and pluggability

  • Composition

– Connection, feedback – Preservation of refinement by composition y p

28

slide-29
SLIDE 29

Composition: in a nutshell Composition: in a nutshell

  • Composition by connection

Co pos t o by co ect o

  • Composition by feedback

Composition by feedback

– Arbitrary feedback not allowed:

  • It “breaks” the theory (refinement not preserved by

f db k) feedback)

– Restricted to Moore interfaces

  • Current outputs independent from some current inputs

Current outputs independent from some current inputs

– Reasonable in most cases in practice

  • C.f., synchronous models like Simulink, Lustre, …

29

slide-30
SLIDE 30

Composition by connection Composition by connection

φ1 φ2 x y z w

Φ ∧ = ∧ ∧ = ) ( :

2 1

z y φ φ φ Φ ∧ ∧ ∧ ) ( :

2 1

z y φ φ φ

) ( ) ( : : φ φ in z y z y → ∧ ∀ Φ ) ( ) ( : , :

2 1

φ φ in z y z y → = ∧ ∀ = Φ

This is not composition of relations

30

p (c.f., “demonic” vs. “angelic” non‐determinism)

slide-31
SLIDE 31

Composition by connection Composition by connection

x y1 x y2

1

φ

2

φ

This is not composition of relations

31

p (c.f., “demonic” vs. “angelic” non‐determinism)

slide-32
SLIDE 32

Example of connection Example of connection

x ≤ y ≤ x+1 x y z z ≥ 0 composite interface x y z

1 ≥ ∧ = ∧ ≥ ∧ + ≤ ≤ x z y z x y x

32

slide-33
SLIDE 33

Composition by connection Composition by connection

  • Associative:

φ1 φ2 φ3 φ1 φ2 φ3

=

  • Parallel composition

– Special case = empty connection

φ1

x1 y1

φ2

x2 y2

– Commutative

φ2

x2 y2 2 1

φ φ ∧

33

2 1

φ φ ∧

slide-34
SLIDE 34

Composition by feedback Composition by feedback

t ti

φ1 x y

commutative

Interface must be Moore with respect to input x: i e contract do not depend on x i.e., contract do not depend on x (the Unit Delay is Moore)

) ( φ φ ) ( :

1

y x = ∧ = φ φ

34

slide-35
SLIDE 35

Main results (2) Main results (2)

  • Refinement preserved by composition:

– If A’ ≤ A and B’ ≤ B then θ(A’,B’) ≤ θ(A,B)

  • θ is a composition by connection

– If A’ ≤ A then κ(A’) ≤ κ(A)

  • κ is a composition by feedback
  • Both A and A’ must be Moore
  • Refinement does not necessarily preserve Mooreness

E ( 2 ) fi ( d 2 0) – E.g., (y = 2x) refines (y mod 2 = 0)

35

slide-36
SLIDE 36

Difficulties with arbitrary feedback Difficulties with arbitrary feedback

true

x y

x = y

x y

= ≤ ≤

x ≠ y

x y

false

x y

=

  • Refinement would not be preserved by

x y x y

feedback …

36

slide-37
SLIDE 37

Additional topics

see [EMSOFT’09] for details

  • Hiding: removes output variables

g p

– Existential quantification for stateless interfaces – A bit trickier for stateful interfaces

  • Shared refinement [Doyen et al 2008, Benveniste

et al] et al]

– An interface that refines multiple others – Not always possible

  • Input‐complete interfaces

37

slide-38
SLIDE 38

Input‐complete interfaces Input complete interfaces

  • All inputs are legal at all states:

true in ≡ ) (φ

x z y = ∧ ≠ 0 x z y = → ≠ 0

vs.

y y

Input‐complete Non‐input‐complete

  • Input‐complete = receptive

Input complete receptive

38

slide-39
SLIDE 39

Input‐complete interfaces:

  • Input‐complete => well‐formed

theory becomes much simpler!

Input complete > well formed

  • Input‐completion:

– Input‐complete version refines original

) ( : ' φ φ φ in ¬ ∨ =

Input complete version refines original

  • Connection, feedback, hiding preserve input‐

completeness

Φ ∧ ∧ ∧ ) ( : z y φ φ φ

p

– Connection is simplified:

  • Refinement = implication

Φ ∧ = ∧ ∧ = ) ( :

2 1

z y φ φ φ

true in z y z y ≡ → = ∧ ∀ = Φ ) ( ) ( : , :

2 1

φ φ

  • Shared refinement = conjunction

so why do we need non input complete interfaces?

39

so why do we need non‐input‐complete interfaces?

slide-40
SLIDE 40

Why non‐input‐complete interfaces? Why non input complete interfaces?

  • Expressiveness:

p

– Termination: some algorithms guarantee termination only if inputs satisfy some constraints => non‐input‐complete

  • Could model as input complete with extra output in {T?} but need
  • Could model as input‐complete with extra output in {T,?}, but need

to handle this output during composition => comes to the same thing

  • Flexibility in design:

– Check local compatibility of interfaces: is their composition ll f d? well‐formed?

  • Catch errors earlier

– Composition of input‐complete is input‐complete, which is always well‐formed

40

slide-41
SLIDE 41

Conclusions Conclusions

  • Novel theory of relational interfaces

Novel theory of relational interfaces

– Generalizes previous attempts Semantical declarative denotational symbolic – Semantical, declarative, denotational, symbolic – Reasonable restrictions on feedback loops

  • Main results:

– Characterization of refinement by pluggability – Preservation of refinement by composition

41

slide-42
SLIDE 42

On‐going work On going work

  • Extend the theory

te d t e t eo y

– More flexibility in feedback:

  • Capture I/O dependencies in interfaces
  • A theory of fixed points for relations?
  • Applications:

Applications:

– Case studies from the HW domain (circuits)

  • Implementation in Ptolemy II

– Only stateless interfaces for now

42

slide-43
SLIDE 43

Director checks Interfaces Director checks Interfaces

slide-44
SLIDE 44

Can infer composite interfaces Can infer composite interfaces

(and (= x in) (and (= z y) (and (>= z 0) (== (* w w) z)) (or (/= x 1 ) (= y 1 ) ) (forall ( ( ) )) ( (/ ) ( y ) ) ( ( y::int z::int) (=> (and (or (/= x 1 ) (= y 1 )) (= z y)) (exists (w::int ) (and (>= z 0) (== (* w w) z)))))) (= y out1) (= w out2) (= z

  • ut1))
slide-45
SLIDE 45

Throws exception when composition bl impossible

slide-46
SLIDE 46

On‐going work On going work

  • Extend the theory

te d t e t eo y

– More flexibility in feedback:

  • Capture I/O dependencies in interfaces
  • A theory of fixed points for relations?
  • Applications:

Applications:

– Case studies from the HW domain (circuits)

  • Implementation in Ptolemy II

– Only stateless interfaces for now

46

slide-47
SLIDE 47

Limitations on feedback Limitations on feedback

  • Consider the parallel composition of two interfaces:

p p

φ1

x1 y1

φ2

x2 y2

φ φ

  • Need a way to capture I/O dependency information

2 1

φ φ ∧

  • Need a way to capture I/O dependency information

47

slide-48
SLIDE 48

Limitations on feedback Limitations on feedback

φ1

x1 y1

φ2

x2 y2

=

φ1

x1 y1

φ2

x2 y2

48

slide-49
SLIDE 49

Thank you Thank you

  • Questions?

Questions?

49