kleene algebra with tests (part 3: theoretical results)

59
Kleene Algebra with Tests (Part 3: Theoretical Results) Dexter Kozen Cornell University Workshop on Logic & Computation Nelson, NZ, January 2004

Upload: desma

Post on 30-Jan-2016

45 views

Category:

Documents


1 download

DESCRIPTION

Kleene Algebra with Tests (Part 3: Theoretical Results). Dexter Kozen Cornell University Workshop on Logic & Computation Nelson, NZ, January 2004. These Lectures. Tutorial on KA and KAT model theory complexity, deductive completeness relation to Hoare logic Practical applications - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Kleene Algebra with Tests (Part 3: Theoretical Results)

Kleene Algebra with Tests(Part 3: Theoretical Results)

Dexter KozenCornell University

Workshop on Logic & ComputationNelson, NZ, January 2004

Page 2: Kleene Algebra with Tests (Part 3: Theoretical Results)

These Lectures

1. Tutorial on KA and KAT

• model theory

• complexity, deductive completeness

• relation to Hoare logic

2. Practical applications

• compiler optimization

• scheme equivalence

• static analysis

3. Theoretical applications

• automata on guarded strings & BDDs

• algebraic version of Parikh’s theorem

• representation

• dynamic model theory

Page 3: Kleene Algebra with Tests (Part 3: Theoretical Results)

Kripke Frames over P,B

K = (K, mK)

mK : P 2K K P = atomic programs

mK : B 2K B = atomic tests

mK specifies a canonical interpretation for P,B

TP,B = {KAT terms over P,B}

Page 4: Kleene Algebra with Tests (Part 3: Theoretical Results)

Traces

K = (K, mK)

mK : P 2K K P = atomic programs

mK : B 2K B = atomic tests

A trace in K is a sequence

x = u0p0u1p1u2 … un-1pn-1un, n 0, (ui,ui+1) mK(pi)

u0p0u1 … un-1pn-1un · unpnun+1 … um-1pm-1um

= u0p0u1 … pn-1unpn … um-1pm-1um

TracesK = {traces in K} ,,... denote traces

Page 5: Kleene Algebra with Tests (Part 3: Theoretical Results)

Trace Algebras

A,B TracesK C K

A+B = A BAB = { | A, B}

A* = Un0 An 1 = K 0 = C = K − C

[[p]]K = {upv | (u,v) mK(p) }, p P

[[b]]K = mK(b), b B

extends to KAT homomorphism [[ ]]K : TP,B 2Traces(K)

TrK = { [[p]]K | p TP,B} regular trace algebra of K

Page 6: Kleene Algebra with Tests (Part 3: Theoretical Results)

Guarded Strings over P,B [Kaplan 69]

AtomsB = {atoms of free BA on B}

, , denote atoms

guarded strings 0p01p12p23 n-1pn-1n

join-irreducible elements of the free KAT on P,B

traces in Kripke frame G = (AtomsB,mG)

mG(p) = AtomsB x AtomsB

mG(b) = { | b}

TrG = {regular sets of guarded strings}

Page 7: Kleene Algebra with Tests (Part 3: Theoretical Results)

Relation Algebras

A,B K x K C idK = {(u,u) | u K}

A+B = A BAB = A B

A* = Un0 An 1 = idK 0 = C = idK − C

[p]K = mK(p) , p P

[b]K = {(u,u) | u mK(b)}, b B

extends to KAT homomorphism [ ]K : TP,B 2K x K

RelK = { [p]K | p TP,B} regular relation algebra of K

Page 8: Kleene Algebra with Tests (Part 3: Theoretical Results)

Traces and Relations

RelK is a homomorphic image of TrK

Ext(A) = {(first(),last() | A}

Ext : 2Traces(K) 2K x K

Ext : TrK RelK Ext([[p]]K) = [p]K

TrK is isomorphic to a relation algebra on TracesK

Rel(A) = {(,) | TracesK, A}

Thus Eq(REL) = Eq(TR)

Page 9: Kleene Algebra with Tests (Part 3: Theoretical Results)

Traces and Relations

g : K AtomsB

g(u) = unique such that u [[]]K

g : TracesK TracesG

g(u0p0u1 … un-1pn-1un) = g(u0)p0g(u1) … g(un-1)pn-1g(un)

g−1 : 2Traces(G) 2Traces(K)

g−1(A) = {x | g(x) A}

g−1 : TrG TrK g−1([[p]]G) = [[p]]K

Thus TrG is universal for relational and trace algebras

Page 10: Kleene Algebra with Tests (Part 3: Theoretical Results)

Automata on Guarded Strings

• ordinary finite automaton on alphabet P TB

• transitions labeled p P are action transitions

• transitions labeled b TB are test transitions

• inputs are guarded strings 0p01 n-1pn-1n

Page 11: Kleene Algebra with Tests (Part 3: Theoretical Results)

Automata on Guarded Strings

• read head always points to an atom, initially 0

• an action transition with label p is enabled if p is the next action symbol in x; advance the head past p

• a test transition with label b is enabled if b, where is the current atom in x; do not advance the head

• accept if occupying an accept state while scanning n

• ordinary NFA with -transitions is an AGS with B = {0,1}

Page 12: Kleene Algebra with Tests (Part 3: Theoretical Results)

Kleene’s Theorem for AGS

A set of guarded strings is accepted by some AGS over

P,B iff it is [[p]]G for some p TP,B

Page 13: Kleene Algebra with Tests (Part 3: Theoretical Results)

Determinization of AGS

An AGS is deterministic if

1. there is exactly one start state

2. each state is either an action state (has exiting action

transitions) or a test state (has exiting test transitions)

but not both

3. every action state has exactly one exiting action

transition for each p P (exactly one enabled)

4. the exiting test transitions of a test state are pairwise

exclusive and exhaustive (exactly one enabled)

5. every cycle contains at least one action transition

6. all accept states are action states

Page 14: Kleene Algebra with Tests (Part 3: Theoretical Results)

Determinization of AGS

Theorem Every nondeterministic AGS is equivalent to a

deterministic AGS

Proof Subset construction

Page 15: Kleene Algebra with Tests (Part 3: Theoretical Results)

State Minimization

Theorem If all possible tests are allowed, then minimal

unique deterministic AGSs exist

Page 16: Kleene Algebra with Tests (Part 3: Theoretical Results)

State Minimization

If only B and B = {b | b B} are allowed as tests, then

minimal deterministic AGSs are not unique

c c

d d d d

d d

c c c c

{cd,cd}

Page 17: Kleene Algebra with Tests (Part 3: Theoretical Results)

State Minimization

Theorem If only B and B = {b | b B} are allowed as

tests, and if the elements of B and B must be tested in

some fixed order, then unique minimal deterministic AGSs

exist

Special case unique minimal ordered BDDs

Page 18: Kleene Algebra with Tests (Part 3: Theoretical Results)

Myhill-Nerode Theorem for AGS

One can define an overlay operation ^ on prefixes of

guarded strings

Given a set A of guarded strings, define

x A y z (x^z A y^z A)

Theorem A is regular iff A has finitely many classes. The

A-classes give the minimal deterministic ordered AGS

Page 19: Kleene Algebra with Tests (Part 3: Theoretical Results)

Representation

Under what conditions is a given abstract KAT (K,B)

guaranteed to be isomorphic to a relational KAT?

Page 20: Kleene Algebra with Tests (Part 3: Theoretical Results)

Representation

Under what conditions is a given abstract KAT (K,B)

guaranteed to be isomorphic to a relational KAT?

1. (bc bqc = 0 bpc = 0) p q

2. pq = 0 b pb = 0 bq = 0

Theorem These conditions, together with *-continuity, are

sufficient for nonstandard representation

Proof states = ultrafilters of B

p’ = {(u,v) | b u c v bpc 0}

Page 21: Kleene Algebra with Tests (Part 3: Theoretical Results)

Dynamic Model Theory

Consider 1st-order KAT over a fixed signature

• atomic actions = assignments x := e

• atomic tests = atomic formulas R(e1,...,en)

A Kripke frame is Tarskian if it arises from a first-order

structure A

• states = valuations of variables over A

• mA(x := e) = { (u,u[x/u(e)]) | u : Var A}

• mA(R(e1,...,en)) = {u | u = R(e1,...,en)}|

Page 22: Kleene Algebra with Tests (Part 3: Theoretical Results)

Dynamic Model Theory

Obs The equational theories of relation and trace

algebras of Tarskian frames do not coincide

x := 1; y := 2 and y := 2; x := 1 are equivalent in the

relation algebra but not in the trace algebra

Question Can we find algebras that are universal for

the Tarskian trace and relation algebras? (i.e., that

play the same role as the regular sets of guarded

strings for KAT)

Page 23: Kleene Algebra with Tests (Part 3: Theoretical Results)

Dynamic Model Theory

Let T be a first-order theory

A quantifier-free type (qf-type) is a maximal consistent

set of quantifier-free formulas

A qf-type of T is a qf-type consistent with T

qf-types correspond to atoms in the guarded string

model

Page 24: Kleene Algebra with Tests (Part 3: Theoretical Results)

Dynamic Model Theory

Define the frame (U,mU)

• U = {qf-types of T}

• mU(x := e) = {(,{ | [x/e] }) | U}

• mU (P(e1,...,en)) = { U | P(e1,...,en) }

Theorem TrU is universal for the equational theory of

Tarskian trace algebras over models of T:

[[p]]U = [[q]]U iff [[p]]A = [[q]]A for all models A of T

Note that U itself is not Tarskian in general!

Page 25: Kleene Algebra with Tests (Part 3: Theoretical Results)

Dynamic Model Theory

Not true for RelU !

[P(c) P(d) ; x := c]U = [P(c) P(d) ; x := d]U

but these two programs are not equivalent in any

Tarskian frame in which c d

However they are observationally equivalent

(indistinguishable by any formulas in the language)

Page 26: Kleene Algebra with Tests (Part 3: Theoretical Results)

Dynamic Model Theory

Theorem RelU is universal for the equational theory of

relation algebras of Tarskian frames over models of T

modulo observational equivalence; i.e.,

[p]U = [q]U iff p and q are observationally equivalent

over all models of T

Page 27: Kleene Algebra with Tests (Part 3: Theoretical Results)

Complexity of Scheme Halting and Equivalence

Theorem Let T be a recursive qf-theory. The scheme

halting and scheme equivalence problem over models

of T are 1 and 1 complete, respectively

Corollary There is no relatively complete deductive

system for scheme equivalence (or inequivalence)

00

Page 28: Kleene Algebra with Tests (Part 3: Theoretical Results)

Parikh’s Theorem [Parikh 66]

Every context-free language is letter

equivalent to a regular set

Letter equivalence: just count occurrences of

letters in strings, ignore order

Page 29: Kleene Algebra with Tests (Part 3: Theoretical Results)

Examples{ababca} {aaabbc, cbbaaa}

{anbn | n 0} (ab)*

A is letter equivalent to B

every string in A has an anagram in B and vice

versa

Page 30: Kleene Algebra with Tests (Part 3: Theoretical Results)

Parikh Map #a(x) = number of occurrences of a in x(x) = (#a1(x),...,#an(x)) Parikh vector(A) = {(x) | x A} commutative image

Examples({ababca, cbbaaa}) = {(3,2,1)}({anbn | n 0}) = ((ab)*) = {(n,n) | n 0}

A is letter equivalent to B (A) = (B)def

Page 31: Kleene Algebra with Tests (Part 3: Theoretical Results)

Parikh’s Theorem (Parikh's version)

Every context-free language is letter equivalent to a regular set.

Page 32: Kleene Algebra with Tests (Part 3: Theoretical Results)

Parikh’s Theorem (Parikh's version)

Every context-free language is letter equivalent to a regular set.

Parikh’s Theorem (our version)

Every commutative Kleene algebra is uniformly algebraically closed.

Page 33: Kleene Algebra with Tests (Part 3: Theoretical Results)

Commutative Kleene Algebra (CKA)xy = yx

A theorem of CKA but not KA(p+q)* = p*q*

() 1 + (p+q)p*q* = 1 + pp*q*+qp*q*

= 1 + pp*q*+p*qq*

p*q*

(p+q)* p*q*

Page 34: Kleene Algebra with Tests (Part 3: Theoretical Results)

Using (p+q)* = p*q* can show

Normal Form [Pilling 73]Every expression is equivalent to

y1+ ... + yn, where yi is a product of am

and (a1...ak)*.

Example(((ab)*c)* + d)* = d* + (ab)*c*cd*

Page 35: Kleene Algebra with Tests (Part 3: Theoretical Results)

Standard Model

Reg(Nn) = regular sets of Parikh vectors in Nn

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

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

1 = {(0,...,0)}0 =

This is the free CKA on n generators

Page 36: Kleene Algebra with Tests (Part 3: Theoretical Results)

Algebraic Closure

Every system of polynomial inequalities

f1(x1,...,xn) x1...

fn(x1,...,xn) xn

over a CKA K has a unique least solution in Kn.

Page 37: Kleene Algebra with Tests (Part 3: Theoretical Results)

Uniform Algebraic Closure

Every system of polynomial inequalities

f1(x1,...,xn) x1...

fn(x1,...,xn) xn

over a CKA K has a unique least solution in Kn. The components of the solution are given by polynomials in

the coefficients of the fi.

Page 38: Kleene Algebra with Tests (Part 3: Theoretical Results)

• A context-free grammar is just a system of polynomial inequalities over the KA (*)

• The associated context-free language is its least solution in (*)

• Commutativity models letter equivalence

Examples

{anbn | n 0} S aSb | axb + 1 x

{balanced parens} S (S) | SS | (x) + xx + 1 x

{palindromes} S aSa | bSb | a | b | axa + bxb + a + b + 1 x

Page 39: Kleene Algebra with Tests (Part 3: Theoretical Results)

Previously known for

• Reg(Nn) [Pilling 73]• commutative -continuous semirings [Kuich 87]

Page 40: Kleene Algebra with Tests (Part 3: Theoretical Results)

Approach

• differential operators /x on polynomials

• Taylor’s theorem f(x+d) = f(x) + f(x+d)d

• closed form solution for n inequalities in n unknowns involving the Jacobian matrix

Page 41: Kleene Algebra with Tests (Part 3: Theoretical Results)

Polynomials K[x,y,...]

(ax + by)*1 + (ax*b*)* + bx + cya + xy(bxy)*

a,b,... Kx,y,... variables

K[x,y,...] is a CKA

Page 42: Kleene Algebra with Tests (Part 3: Theoretical Results)

Polynomials K[x,y,...]

(ax + by)*1 + (ax*b*)* + bx + cya + xy(bxy)*

a,b,... Kx,y,... variables

K[x,y,...] is a CKA

K

K[x,y,...]

{x,y,...}

L

eval

K[x,y,...] is the direct sum (coproduct) of K and

the free CKA on {x,y,...}

Page 43: Kleene Algebra with Tests (Part 3: Theoretical Results)

Differential Operators

A map D:K K is called a differential operator if for all x,y K,

• D(x+y) = Dx + Dy• D(xy) = xDy + yDx• D(x*) = x*Dx• D0 = D1 = 0

Page 44: Kleene Algebra with Tests (Part 3: Theoretical Results)

Differential Operators

A map D:K K is called a differential operator if for all x,y K,

• D(x+y) = Dx + Dy• D(xy) = xDy + yDx• D(x*) = x*Dx• D0 = D1 = 0

K

K[x,y,...]

{x,y,...}

K[x,y,...]

Page 45: Kleene Algebra with Tests (Part 3: Theoretical Results)

Differential Operators

:K[x,...] K[x,...], where

Examples

x

x(y) = 0, y x

x (a) = 0, a K

x (x) = 1

x (ax2y + bxy2 + (ax)* + 1) = axy + by2 + a(ax)*

y (ax2y + bxy2 + (ax)* + 1) = ax2 + bxy

x

Page 46: Kleene Algebra with Tests (Part 3: Theoretical Results)

Chain Rule

For f, e K[x],

or in more conventional notation,

f(e(x)) = f(e(x)) e(x)

f x

e x

x

(f(e)) = (e) ·

Page 47: Kleene Algebra with Tests (Part 3: Theoretical Results)

Taylor’s Theorem

For f, d K[x],

f(x+d) = f(x) + f(x+d) d

In particular, evaluating at x = 0,

f(d) = f(0) + f(d) d

Page 48: Kleene Algebra with Tests (Part 3: Theoretical Results)

Theorem

Let K be a CKA and let f(x) K[x]. The least solution of f(x) x is f(f(0))* f(0).

Page 49: Kleene Algebra with Tests (Part 3: Theoretical Results)

Theorem

Let K be a CKA and let f(x) K[x]. The least solution of f(x) x is f(f(0))* f(0).

Example {anbn | n 0}

f(x) x axb + 1 xf(x) axb + 1

f(x) abf(0) 1

f(f(0))* f(0) (ab)*

Page 50: Kleene Algebra with Tests (Part 3: Theoretical Results)

Theorem

Let K be a CKA and let f(x) K[x]. The least solution of f(x) x is f(f(0))* f(0).

Example {balanced parentheses}

f(x) x axb + x2 + 1 xf(x) axb + x2 + 1

f(x) ab + xf(0) 1

f(f(0))* f(0) (ab + 1)* = (ab)*

Page 51: Kleene Algebra with Tests (Part 3: Theoretical Results)

Theorem

Let K be a CKA and let f(x) K[x]. The least solution of f(x) x is f(f(0))* f(0).

Example {palindromes}

f(x) x axa + bxb + a + b + 1 xf(x) axa + bxb + a + b + 1

f(x) a2 + b2

f(0) a + b + 1

f(f(0))* f(0) (a2 + b2)* (a + b + 1)= (a2 )* (b2)* (a + b + 1)

Page 52: Kleene Algebra with Tests (Part 3: Theoretical Results)

The 2 x 2 Case

f(x,y) xg(x,y) y

Viewing K[x,y] as K[x][y], solve g(x,y) y over K[x]. Say the solution is h(x). Then solve f(x,h(x)) x over K. Say the solution is a.

Then (a,h(a)) is the least solution of (*).

(*)

Page 53: Kleene Algebra with Tests (Part 3: Theoretical Results)

The 2 x 2 Case

f(x,y) xg(x,y) y

Viewing K[x,y] as K[x][y], solve g(x,y) y over K[x]. Say the solution is h(x). Then solve f(x,h(x)) x over K. Say the solution is a.

Then (a,h(a)) is the least solution of (*).

Need uniformity: the expression f(f(0))* f(0) gives the least solution uniformly in all homomorphic images

(*)

Page 54: Kleene Algebra with Tests (Part 3: Theoretical Results)

Multivariate Taylor Theorem

For x = x1,...,xn, f = f1,...,fm K[x], ande = e1,...,en,

f(e) = f(0) + (e) ·e f x

Page 55: Kleene Algebra with Tests (Part 3: Theoretical Results)

Multivariate Taylor Theorem

For x = x1,...,xn, f = f1,...,fm K[x], ande = e1,...,en,

f(e) = f(0) + (e) ·e f x

f x

fi

xj

(e)ij = (e)

Jacobian matrix

Page 56: Kleene Algebra with Tests (Part 3: Theoretical Results)

Multivariate Chain Rule

For x = x1,...,xn, f = f1,...,fm K[x], ande = e1,...,en,

(f(e)) = (e) · f x

z

e z

Page 57: Kleene Algebra with Tests (Part 3: Theoretical Results)

TheoremLet x = x1,...,xn and f = f1,...,fn K[x]. Consider the n x n system

f(x) x (**)

Define

For sufficiently large finite N, aN is the least solution to (**).

a0 = f(0)

ak+1 = (ak)* ·ak

f x

Page 58: Kleene Algebra with Tests (Part 3: Theoretical Results)

How bad can N be?

Page 59: Kleene Algebra with Tests (Part 3: Theoretical Results)

How bad can N be?

N(n) (7 ·3n - 5) / 2