representation of kleene algebra with tests dexter kozen cornell university

60
Representation of Kleene Algebra with Tests Dexter Kozen Cornell University

Post on 19-Dec-2015

218 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Representation of Kleene Algebra with Tests Dexter Kozen Cornell University

Representation ofKleene Algebra with Tests

Dexter KozenCornell University

Page 2: Representation of Kleene Algebra with Tests Dexter Kozen Cornell University

pq + qp p*q

{pq,qp} {q,pq,p2q,p3q, …}

(p + q)* = (p*q)*p* (pq)*p = p(qp)*

{all strings over p,q} {p,pqp,pqpqp,}

(0 + 1(01*0)*1)*

{multiples of 3 in binary}

Kleene Algebra (KA)is the algebra of regular expressions

00

0

1

1

1

p

p

q

q

p,q

p

q

p

q

Page 3: Representation of Kleene Algebra with Tests Dexter Kozen Cornell University

Standard InterpretationRegular sets over

A+B = A BAB = {xy | x A, y B}

A* = Un0 An = A0 A1 A2 ...

1 = {}0 =

p interpreted as {p}

Page 4: Representation of Kleene Algebra with Tests Dexter Kozen Cornell University

Binary Relations

R, S binary relations on a set X

R+S = R S

RS = R ° S = {(u,v) | w (u,w) R, (w,v) S}

R* = reflexive transitive closure of R

= Un0 Rn = 1 R R2 R3

1 = identity relation = {(u,u) | u X}0 =

Page 5: Representation of Kleene Algebra with Tests Dexter Kozen Cornell University

Applications

• Automata and formal languagesregular expressions

• Relational algebra

• Program logic and verificationDynamic Logic

program analysis

optimization

• Design and analysis of algorithmsshortest paths

connectivity

Page 6: Representation of Kleene Algebra with Tests Dexter Kozen Cornell University

Conway’s Definition

A Kleene algebra is any structure

(K, +, ·, *, 0, 1)

satisfying the same equations as theregular sets

established the equational theory as the primary theory of interest—not necessarily the best choice

Page 7: Representation of Kleene Algebra with Tests Dexter Kozen Cornell University

Fundamental Questions

• Can we axiomatize the valid equations?

YES [Salomaa 66]

—but not equationally [Redko 64]

• Can we decide if expressions are equivalent?

YES, PSPACE complete [(Stock+1)Meyer 74]

Page 8: Representation of Kleene Algebra with Tests Dexter Kozen Cornell University

Axioms of KA

• K is an idempotent semiring under +, ·, 0, 1

(p + q) + r = p + (q + r) (pq)r = p(qr)p + q = q + p p1 = 1p = pp + p = p p0 = 0p = 0 p + 0 = p

p(q + r) = pq + pr(p + q)r = pr + qr

• p*q = least x such that q + px x• qp* = least x such that q + xp x

defx y x + y = y

Page 9: Representation of Kleene Algebra with Tests Dexter Kozen Cornell University

This is a universal Horn axiomatization

• p*q = least x such that q + px xq + p(p*q) p*qq + px x p*q x

• qp* = least x such that q + xp xq + p(qp*) qp*q + px x qp* x

Every system of linear inequalities

a11x1 + ... + an1xn + b1 x1 . . .an1x1 + ... + annxn + bn xn

has a unique least solution

Page 10: Representation of Kleene Algebra with Tests Dexter Kozen Cornell University

Alternative Characterizations of *

Complete semirings (quantales)

i I pi = supremum of {pi | i I}

with respect to

*-continuity

pq*r = sup pqnr

• infinitary

• same equational theory Eq(KA) = Eq(KA*)

n 0

Page 11: Representation of Kleene Algebra with Tests Dexter Kozen Cornell University

1 + pp* = 1 + p*p = p*

p*p* = p** = p*

(pq)*p = p(qp)* sliding

(p*q)*p* = (p + q)* denesting

px = xq p*x = xq* bisimulation

qp = 0 (p + q)* = p*q* loop distribution

Some Useful Properties

Page 12: Representation of Kleene Algebra with Tests Dexter Kozen Cornell University

Proof of the Sliding Rule

(ab)*a a(ba)*

a + aba(ba)* = a(1 + ba(ba)*) distributivity

= a(ba)* 1 + pp* = p*.

a + aba(ba)* a(ba)*

(ab)*a a(ba)* q + px x p*q x

The reverse inequality is symmetric.

Page 13: Representation of Kleene Algebra with Tests Dexter Kozen Cornell University

Equational Completeness [K91]

• Reg, the KA regular sets over , is the• free KA on generators

p q as regular sets

p = q is a consequence of the KA axioms

• KA is complete over relational models

Eq(REL) = Eq(KA) = Eq(Reg)

Page 14: Representation of Kleene Algebra with Tests Dexter Kozen Cornell University

Matrices over a KA

a bc d

a+e b+fc+g d+h

e fg h+ =

def

a bc d

ae+bg af+bhce+dg cf+dh

e fg h

· =def

1 00 1

0 00 0

0 1 =def

=def

a bc d

(a+bd*c)* (a+bd*c)*bd*(d+ca*b)*ca* (d+ca*b)*

*=def

Page 15: Representation of Kleene Algebra with Tests Dexter Kozen Cornell University

Matrices over a KA

a bc d

(a+bd*c)* (a+bd*c)*bd*(d+ca*b)*ca* (d+ca*b)*

*=def

a dc

b

Page 16: Representation of Kleene Algebra with Tests Dexter Kozen Cornell University

• Representation of finite automata

• Construction of regular expressions

• Solution of linear equations over a KA

• Connectivity and shortest path algorithms

Matrices over a KA

Page 17: Representation of Kleene Algebra with Tests Dexter Kozen Cornell University

Solution of Linear Inequalities

a11x1 + ... + an1xn + b1 x1 . . .an1x1 + ... + annxn + bn xn

a11 ... an1 . . + .an1 ... ann

b1...

bn

x1...

xn

x1...

xn

Page 18: Representation of Kleene Algebra with Tests Dexter Kozen Cornell University

Shortest PathsThe min,+ algebra

R+ {}

r + s = min r,srs = r + sr* = 00 = 1 = 0 =

1.4 .9

3.2

0 1.4 3.2

0 .9 0

0 1.4 2.3

0 .9 0

*=

Page 19: Representation of Kleene Algebra with Tests Dexter Kozen Cornell University

Other Models

Convex polyhedra [Iwano & Steiglitz 90]

AB = {ax + by | x A, y B}

A* = convex hull of A

A B

Page 20: Representation of Kleene Algebra with Tests Dexter Kozen Cornell University

(K, B, +, ·, *, ¯, 0, 1)

• (K, +, ·, *, 0, 1) is a Kleene algebra

• (B, +, ·, ¯, 0, 1) is a Boolean algebra

• B K

• p,q,r, range over K

• a,b,c, range over B

Kleene Algebra with Tests (KAT)

Page 21: Representation of Kleene Algebra with Tests Dexter Kozen Cornell University

+, ·, 0, 1 serve double duty

• applied to programs, denote choice,

composition, fail, and skip, resp.

• applied to tests, denote disjunction,

conjunction, falsity, and truth, resp.

• these usages do not conflict!

bc = b c b + c = b c

Kleene Algebra with Tests (KAT)

Page 22: Representation of Kleene Algebra with Tests Dexter Kozen Cornell University

Models

• Relational modelsK = binary relations on a set X

B = subsets of the identity relation

• Trace modelsK = sets of traces u0p0u1p1u2 … un-1pn-1un

B = sets of traces of length 0

• Language-theoretic modelsK = regular sets of guarded strings over

B = atoms of a finite free Boolean algebra

Page 23: Representation of Kleene Algebra with Tests Dexter Kozen Cornell University

Guarded Strings [Kaplan 69]

P atomic programs B atomic tests

, , atoms (minimal nonzero elements) of the free Boolean

algebra on generators B

e.g. if B = {b1,...,b6}, then b1b2b3b4b5b6 is an atom

guarded strings 0p01p12p23 n-1pn-1n

A+B = A B

AB = {xy | x A, y B}

A* = Un0 An

1 = {atoms}0 =

Page 24: Representation of Kleene Algebra with Tests Dexter Kozen Cornell University

Theorem [Kozen & Smith 96]

The family of regular sets of guarded strings

over P,B is the free KAT on generators P,B.

Corollary

KAT is complete over relational models.

Eq(GS) = Eq(KAT) = Eq(KAT*) = Eq(REL)

Page 25: Representation of Kleene Algebra with Tests Dexter Kozen Cornell University

Matrices over a KAT

The n x n matrices over a KAT (K,B) forms a KAT

(K’,B’)

B’ = diagonal matrices over B

Page 26: Representation of Kleene Algebra with Tests Dexter Kozen Cornell University

Modeling Programs[Fischer & Ladner 79]

p;q pq

if b then p else q bp + bq

while b do p (bp)*b

Page 27: Representation of Kleene Algebra with Tests Dexter Kozen Cornell University

Hoare Logic [C. A. R. Hoare 69]

{b}p{c} partial correctness assertion

‘‘If b holds in the current state, and if p is

executed starting in the current state, then if

p halts, c will be true of the halting state.’’

Page 28: Representation of Kleene Algebra with Tests Dexter Kozen Cornell University

{b}p{c}, {c}q{d}

{b}pq{d}composition rule

{bc}p{d}, {bc}q{d}

{c}if b then p else q{d}conditional rule

{bc}p{c}

{c}while b do p{bc}while rule

{b[x/e]} x:=e {b} assignment rule

b’ b, {b}p{c}, c c’

{b’}p{c’}weakening rule

Rules of Hoare Logic

Page 29: Representation of Kleene Algebra with Tests Dexter Kozen Cornell University

KAT subsumes PHL

{b}p{c} modeled by bp = bpc or bpc = 0

Page 30: Representation of Kleene Algebra with Tests Dexter Kozen Cornell University

{b}p{c}, {c}q{d}

{b}pq{d}composition rule

{bc}p{d}, {bc}q{d}

{c}if b then p else q{d}conditional rule

{bc}p{c}

{c}while b do p{bc}while rule

Page 31: Representation of Kleene Algebra with Tests Dexter Kozen Cornell University

{b}p{c}, {c}q{d}

{b}pq{d}composition rule

{bc}p{d}, {bc}q{d}

{c}if b then p else q{d}conditional rule

{bc}p{c}

{c}while b do p{bc}while rule

bpc = 0 cqd = 0 bpqd = 0

bcpd = 0 bcqd = 0 c(bp+bq)d = 0

bcpc = 0 c(bp)*b bc = 0

Page 32: Representation of Kleene Algebra with Tests Dexter Kozen Cornell University

Theorem

These are all theorems of KAT

Completeness Theorem [K 99]

All relationally valid rules of the form

are derivable in KAT (not so for PHL)

{b1}p1{c1}, ..., {bn}pn{cn}

{b}p{c}

Page 33: Representation of Kleene Algebra with Tests Dexter Kozen Cornell University

Counterexample

{c}if b then p else p{c}

{c}p{c}

is trivially unprovable in Hoare Logic, but

c(bp + bp)c = 0 cpc = 0

is easily provable in KAT

Page 34: Representation of Kleene Algebra with Tests Dexter Kozen Cornell University

Hoare formulasp1 = 0 p2 = 0 ... pn = 0 q = r

Theorem

KAT is complete for the Hoare theory of

relational algebras

... not for the Horn theory!

Counterexample: p 1 p2 = p

Page 35: Representation of Kleene Algebra with Tests Dexter Kozen Cornell University

Complexity of KAT and PHL

Theorem [Cohen 94]

The Hoare theory of KA (Horn formulas with

premises p = 0) is PSPACE-complete

Theorem [Cohen, Kozen & Smith 96]

The Hoare theory of KAT is PSPACE-complete

Theorem

PHL is PSPACE-complete

Page 36: Representation of Kleene Algebra with Tests Dexter Kozen Cornell University
Page 37: Representation of Kleene Algebra with Tests Dexter Kozen Cornell University
Page 38: Representation of Kleene Algebra with Tests Dexter Kozen Cornell University
Page 39: Representation of Kleene Algebra with Tests Dexter Kozen Cornell University
Page 40: Representation of Kleene Algebra with Tests Dexter Kozen Cornell University
Page 41: Representation of Kleene Algebra with Tests Dexter Kozen Cornell University
Page 42: Representation of Kleene Algebra with Tests Dexter Kozen Cornell University
Page 43: Representation of Kleene Algebra with Tests Dexter Kozen Cornell University
Page 44: Representation of Kleene Algebra with Tests Dexter Kozen Cornell University
Page 45: Representation of Kleene Algebra with Tests Dexter Kozen Cornell University
Page 46: Representation of Kleene Algebra with Tests Dexter Kozen Cornell University
Page 47: Representation of Kleene Algebra with Tests Dexter Kozen Cornell University
Page 48: Representation of Kleene Algebra with Tests Dexter Kozen Cornell University
Page 49: Representation of Kleene Algebra with Tests Dexter Kozen Cornell University
Page 50: Representation of Kleene Algebra with Tests Dexter Kozen Cornell University
Page 51: Representation of Kleene Algebra with Tests Dexter Kozen Cornell University
Page 52: Representation of Kleene Algebra with Tests Dexter Kozen Cornell University
Page 53: Representation of Kleene Algebra with Tests Dexter Kozen Cornell University
Page 54: Representation of Kleene Algebra with Tests Dexter Kozen Cornell University
Page 55: Representation of Kleene Algebra with Tests Dexter Kozen Cornell University
Page 56: Representation of Kleene Algebra with Tests Dexter Kozen Cornell University
Page 57: Representation of Kleene Algebra with Tests Dexter Kozen Cornell University
Page 58: Representation of Kleene Algebra with Tests Dexter Kozen Cornell University
Page 59: Representation of Kleene Algebra with Tests Dexter Kozen Cornell University
Page 60: Representation of Kleene Algebra with Tests Dexter Kozen Cornell University