Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Some Applications of Kleene Algebra

Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

Ubiquitous

Computing
REPRINTED
FROM:

and Communication Journal

Some Applications of Kleene Algebra


M. Al-Mousa, F. Tchier and F. Toufic
Mathematics department,
King Saud University
malmousa@ksu.edu.sa, ftchier@ksu.edu.sa,
ftoufic@ksu.edu.sa
(Invited Paper)
AbstractWe will treat some application by using Kleene
algebra and its properties. First, We will find the shortest
path which links two given vertices in a directed (finite)
graph. Also, we will give an algorithm to solve this problem
by using the typed Kleene algebra. Finally, we use Kleene
algebra to put any program in while free form.
Index TermsKleene algebra,
While program.

shortest path,

graph,

I. Introduction

LEENE algebra is an algebraic structure that captures axiomatically the properties of a natural class
of structures arising in logic and computer science. It
is named after Stephen Cole Kleene (1909 1994), who
among his many other achievements invented finite automate and regular expressions, structures of fundamental
importance in computer science. Kleene algebra is the algebraic theory of these objects, although it has many other
natural and useful interpretations.
Kleene algebras arise in various guises in many contexts;
relational algebra [20], [10], [9], semantics, logic of programs
[11], [21], automata, formal language theory [15], [14], the
design and analysis of algorithms [1], [8], [12], [17]. In this
paper, we will use Kleene algebra to solve some fields of
applications.
Some Fields of Applications
Within the field of efficient algorithms it has been
applied to path problems on graphs. The shortest
path problem consists of finding a path between two
vertices such that the sum of the weights of its constituent edges is minimized. Many important algorithms have been used to solve this problem; Dijkstras algorithm solves the single-pair, single-source,
and single-destination shortest path problems [18].
Bellman-Ford algorithm solves the single source problem if edge weights may be negative [17]. FloydWarshall algorithm solves all pairs shortest paths [18],
[17]. Johnsons algorithm solves all pairs shortest
paths, and may be faster than Floyd-Warshall on
sparse graphs [18], [17], [3]. Perturbation theory finds
(at worst) the locally shortest path.
More recently, Kleene algebra has been successfully
applied to the semantic description of imperative programs. Kleene algebras with tests will give us a mathematical framework for studying and manipulating

Volume 7 Number 1

programs. It provides an effective procedure to decide


wether two programs are equal or not and permits us
to simulate any while program with a program which
has at most one while loop.
In the following we will present some notions needed for
the rest of the paper.
(1) Definition.
1. A partial order is a binary relation over a set
S which is reflexive, antisymmetric, and transitive,
that is, for all a, b, and c S, we have
a a (reflexivity);
if a b and b a then a = b (antisymmetric);
if a b and b c then a c (transitivity).
2. A set with a partial order is called a partially ordered set (also called a poset).
3. Let (A, ) and (B, ) be two partially ordered
sets. A Galois connection between these posets consists of two functions: F : A B and G : B A, such
that for all a in A and b in B, we have F (a) b if and
only if a G(b).
Now we will give the definition of directed graph [18].
(2) Definition. A directed graph G = (V, B) consists of
a set V of vertices and a set B of ordered pairs of vertices,
called edges. And the adjacency matrix of G is a means
of representing which vertices of a graph are adjacent to
which other vertices.
II. Kleene algebra
We start by define Kleene algebra.
(3) Definition. A Kleene algebra is a structure
K = (K, +, , , 0, 1) where the following axioms satisfied
(a + b) + c = a + (b + c)
a+a = a
a+b = b+a
a+0 = a
a.0 = 0.a = 0
(a b) c = a (b c)
a1 = 1a = a
a (b + c) = a b + a c
(a + b) c = a c + b c.

Page 201210

www.ubicc.org

Ubiquitous Computing and Communication Journal

(K1)
(K2)
(K3)
(K4)

REPRINTED FROM:

1 + x x x
1 + x x x
b + a x x = a b x
b + x a x = b a x.

Now, we take unusual model that turns out to be useful


in the shortest path algorithms in graphs. This algebra
is called the tropical algebra, also known as the min, +
algebra. For more details see [3].

where a b iff a + b = b is called the natural partial order


of Kleene algebra. The product a b will be written as ab.
(4) Definition. A Kleene algebra K is called starcontinuous [16] if it satisfies the axiom
xy z = supn0 xy n z,
for any x, y, z K ; where y 0 = 1, y n+1 = yy n and the
supremum is with respect to the natural order.
(5) Theorem. Let K be a Kleene algebra and c, d K,
then
a) (cd) c = c(dc) ,
b) If c is invertible,
that is cc1 = 1 for some c1 K

, then cdc1 = cd c1 .
(6) Example. (Language-Theoretic Model). Let denote the set of finite-length strings over a finite alphabet
, including the null string . The set forms a Kleene
algebra under the following constants and operations on
subsets of
1. A + B=A B,
2. A.B= {x z y | x z A, z y B} ,
(where is concatenation)
3. 0=,
4. 1= {}
S,
5. A = n0 An =
{x1 ...xn | n 0 and xi A, 1 i n} .
Thus the operation (), applied to two sets of strings A
and B, products the set of all strings obtained by concatenating a string from A with a string from B, in the order.
Thus A is the union of all powers of A, equivalently, A
consists of all strings obtained by concatenating together
any finite collection of string from A in any order. Any
subset of the full power set of containing and {}
and closed under the operations of (), (), and ( ) is a
Kleene algebra.
A subidentity of a Kleene algebra (S, , , , 0, 1) is an
element x with x 1. We call a Kleene algebra pre-typed
if all its subidentities are idempotent, i.e., x 1 = xx =
x. We call a pretyped Kleene algebra (S, , , , 0, 1) typed
if its a boolean algebra (S, , , 0, 1) and the restriction
operations distribute through arbitrary meets of subtypes,
i.e., if we have for all families (xj )jJ of subidentites and
all a S that
(

jJ

xj ) a =

xj a and a (

jJ

jJ

xj ) =

a xj .

jJ

In a typed Kleene algebra we can define, for a S, the


domain ha and co-domain ai via the Galois connections (y
ranges over subidentities only)
ha ya y 1,
ai ya 1 y.

Volume 7 Number 1

(7) Example. (The tropical algebra). Let R = R+ {}


is the set of nonnegative reals with an additional infinite element . This model forms a Kleene algebra under the following constants and operations on subsets of R+ {} :
1. a + b= min {a, b} ,
2. a b=a +R b,
(where +R means the addition in reals)
3. a =1 = 0R ,
4. 0=,
5. 1=0R .
The elements 1 and 0 of a Kleene algebra can play the
roles of the truth values true and false. Expressions
that yield one of these values are therefore also called assertions. The assertion 0 means not only false, but also
undefined. Negation is defined by 0 = 1, and 1 = 0.
Then for an assertion b and an element c we have

c if b = 1,
bc=cb=
0 if b = 0.
The conjunction of assertions a, b is their infimum a b or,
equivalently, their product a b; their disjunction is their
sum a + b. We write a b for a b and a b for a + b.
Using this, we can construct a conditional:
if b then c else d fi= b c b d
for assertions b and elements c, d. Note that the conditional is monotonic only in d and e. So, recursions over
the condition b need not be well-defined. A property we
are going to use in the sequel is
if b then d else if c then d else e fi fi =if b c then d else e fi
For assertions b, c and elements d, e.
A. Matrices Over a Kleene Algebra
Under the natural definitions of the Kleene algebra operators +, , , 0 and 1, the family M (n, K) of n n matrices
over a Kleene algebra K again forms a Kleene algebra. This
is a standard result proved for various classes of algebras
in [5], [2].
Define (+) and () on M (n, K) to be the usual operations
of matrix addition and multiplication, respectively, Zn the
n n zero matrix, and In the n n identity matrix. The
partial order () is defined on M (n, K) by A B A +
B = B.
(8) Lemma. The structure
(M (n, K) , +, , Zn , In ) is an idempotent semiring.
The definition of E for E M (n, K) comes from [14],
[5], [7]. We first consider the case n = 2. This construction
will later be applied inductively.
Let


a b
E=
c d

Page 201211

www.ubicc.org

Computing
and Communication
SOMEUbiquitous
APPLICATIONS
OF KLEENE
ALGEBRA

Journal

let f = a + bd c and define




f
f bd

E =
d cf d + d cf bd


F
F B2 B4
B4 B3 F B4 + B4 B3 F B2 B4

0 3 2 4
3 0 5 7

=
4 1 0 2 .
4 7 6 0
So, we can read on this matrix that the shortest path
from the vertex b to the vertex d is of length (B )bd = 7,
it passes through a and after c.
B =

(9) Lemma. The matrix E defined above satisfies the


Kleene algebra axioms (Def. 3).
(10) Proposition. If K is star-continuous (Def. 4), then
so is M (n, K) for n 1.
This Proposition states that the star-continuity passes
from the Kleene algebra K to M (n, K) and this is exactly
the key fact that we use in the following application.

In the following, we give an algorithm to solve the shortest path problem by using the typed Kleene algebra.
C. Shortest Connecting Path

B. All Pair-Shortest Paths Problem


[12]
Given a directed graph G which has n vertices 1, ..., n and
each edge is labelled by a positive real number called the
weight of the edge. From G, we create a complete graph
[17] (still denoted by G) such that the vertex i is connected
with j (in this order) by an edge labelled with the same
number if i and j are adjacent in G (in this order again),
and by an edge labelled by the symbol otherwise. So,
the edges of the new graph G are labelled by an element
of R+ {}. In the set R = R+ {}, we define the
operations as in (Ex.7).
The adjacency matrix B of the previous graph G is an
element of the Kleene algebra M (n, K) and the ij th entry
of B k is exactly the number of paths of length k which
links i with j and composed by less than or equal to k
edges.This result can be used to determine the length of
the shortest path between i and j. By the (Prop.10),
B = supR {B k | k N } = inf{B k | k N }.
So the ij th entry of B is exactly the length of the shortest path which links i to j.
(11) Example. The adjacency matrix of the following
graph is

Assume that (S, , , 0, 1) is a typed Kleene algebra. We


define the general operation E by E(W )(f, g) = g(f (w))
where
w S is a fixed element of S.
f : S P(M ) is a disjunctive abstraction function
with some set M of valuations, where a function
f from a Kleene algebra into a lattice is disjunctive,
if it distributes through +, i.e., satisfies f (x + y) =
f (x) f (y),
g : P(M ) P(M ) is a selection satisfying the properties
(1)
g(K) K,
(2) g(K L) = g(g(K) g(L))
(weak distributivity), for K, L M.
Motivated by the graph theoretical applications, we now
postulate the following conditions about f and g :
1. hc ai
g(f (a c)) = g(f (a c) + f (a u c)),
2. (a u)i ai
g(f (a c)) = g(f (a c) + f (a u c)),
with a, c, u S. These two conditions are used to obtain
two termination cases of the algorithm. For more details
see [3].
We have the following basic algorithm:
F (f, g)(a, b, c) = if hc ai (a b)i ai
then g(f (a c))
else g(f (a c)) + F (f, g)(a + a b, b, c))f i
We define
shortestpaths(a, c)=F (id, min paths)(a, c),

2 2

3
B1

B=
=
1 2
B3
4 3


with
B2
B4

Therefore, with a bit of calculation we find

Volume 7 Number 1

min paths(a)=let ml = min(

kxk)

xa

in

0 2
We have
=
,
0



2 3
0
F = B1 + B2 B4 B3 =
and F =
3
3
B4

if kxk = ml then x else .

xa

3
0


.

Here path min length select from a set of words the ones
with the least number of letters. Therefore, we have the
following algorithm for computing the shortest path between a set S and the node y:

Page 201212

www.ubicc.org

Ubiquitous Computing and Communication Journal

REPRINTED FROM:

shortestpaths(S, y)
=
{definition in Equ. 1}
F (id, min paths)(S, y)
=
{Equ. 1}
if hy Si (S ./ R)i Si
then min paths(S ./ y)
else min paths(S ./ y shortestpaths(S S ./ R, y))fi
=
{Equ. 1}
if y Si
then min paths(S ./ y)
else if (S ./ R)i Si
then min paths(S ./ y)
else min paths(S ./ y shortestpaths(S S ./
R, y))fi fi
=
{y
/ Si S ./ y = }
if y Si
then min paths(S ./ y)
else if (S ./ R)i Si
then min paths()
else min paths(shortestpaths(S S ./ R, y))fi fi
=
{definition and idempotence of min paths}
if y Si
then min paths(S ./ y)
else if (S ./ R)i Si
then
else shortestpaths(S S ./ R, y))fi fi.
III. Kleene Algebra with Tests
Kleene algebras with tests [6], [19], [13] form a very important class of Kleene algebras. They provide an algebraic
framework for manipulating programs. In the context of
Kleene algebra with tests, we can show by the mean of
equations when two programs are equivalent, i.e. when
they perform the same tasks. The language of Kleene algebra with tests is the language of Kleene algebra together
with a finite set of new constant symbols called primitive
tests and one unary function () which will be applied only
on Boolean terms.
(12) Definition. A Kleene algebra with tests is a two
sorted algebra
(K, B, +, , , 0, 1,)
(1)
where is a unary operator defined only on B, such that
B K.
(K, +, , , 0, 1) is a Kleene algebra.
(B, +, ,, 0, 1) is a Boolean algebra.
The elements of B are called tests. We reserve the letters
p, q, r, ... for arbitrary elements of K and a, b, c, ... for tests.
(13) Remarks.
1. The sequential composition operator () acts as
conjunction when applied to tests, and the choice operator (+) acts as disjunction. Intuitively, a test bc
succeeds iff both b and c succeed, and b + c succeeds
iff either b or c succeeds.
2. It is immediately from the definition that b 1 for
all b B. It is tempting to define tests in an arbitrary
Kleene algebra to be the set {b K | b 1}, and this
is the approach taken by [4].

Volume 7 Number 1

3. The last remark makes sense in algebras of binary


relation [20], [10], but in general the set {b K | b 1}
may not extend to a Boolean algebra. For example,
in the (min, +) Kleene algebra (Ex.7), b 1 for all b,
but the idempotence law bb = b fails.
4. Every Kleene algebra extends trivially to a Kleene
algebra with tests by taking the two-element Boolean
algebra {0, 1}.
5. A Kleene algebra with tests is a Kleene algebra
with an embedded Boolean algebra whose elements
are called tests. So, the properties of Boolean algebra,
like De Morgans law (b + b0 = b b0 and bb0 = b + b0 ),
double negation principle (b = b), ... will be used without proofs.
(14) Theorem. The axiom of Kleene algebra with tests
is the axiom of Kleene algebra added with:
ab = ba
b+b = 1
bb = 0.

(2)
(3)
(4)

(15) Theorem. -continuous Kleene algebra with tests is


a -continuous Kleene algebra.
(16) Theorem. Let a, b be elements of Kleene algebra
with tests, then we have
a) 1 + b = 1
b) bb = b
c) a b ab = a.
Proof. The equations in a) and b) are follow from the
axiom of Kleene algebra with tests. To prove c) suppose
a b = a + b = b
= aa + ab = ab
= a = aa ab.
Since 1 + b = b = a + ab = a
= ab a.
Conversely, suppose ab = a = a + b = ab + b
= a + b = (a + 1)b
= a + b = 1b = b
= a b.
The following results will be used when we prove the
equivalence of programs under some conditions. These
works can be seen in [13].
Let K be a Kleene algebra with tests and B its embedded
Boolean algebra.
(17) Lemma. For p K, b B, the following conditions
are equivalent:
a) bp = pb.
b) bpb + bpb = 0.
c) bp = pb.
Proof. We start by show the equivalence of a) and b).
Assuming a),
bpb + bpb
=
{Assumtion}
pbb + bbp
=
{Equ.4}
p0 + 0p = 0.

Page 201213

www.ubicc.org

Computing
and Communication
SOMEUbiquitous
APPLICATIONS
OF KLEENE
ALGEBRA

Journal

Conversely, assuming b), we have bpb = bpb = 0, thus


pb
=
{Equ.3}
(b + b)pb
=
{Distributivity}
bpb + bpb
=
{bpb = 0}
bpb + 0
=
{bpb = 0}

bpb + bpb
=
{Boolean algebra}
bp(b + b)
=
{Equ.3}
bp.
Of course, any pair of tests commute, i.e., bc = cb, this
is an axiom of Boolean algebra.
Now, we give useful results that are fairly evident from
an intuitive point of view, but nevertheless require formal
justification.
(18) Lemma. Let p, b K, such that b2 = b and bp = pb,
then bp = p b = b(pb) = (bp) b.
Proof. The first and last equality follow from the (Th.5)
with the condition bp = pb. Since pb = pbb = b(pb), we have
p b = b(pb) (Th.5 again).
The terms p + q and pq [respectively p and p (provides
that it has a meaning)] are said to be generated by p and
q [respectively p].
(19) Proposition. If p K is generated by elements of
K which commute with q then p commutes with q, that is
pq = qp is true in K.
Proof. If p = p1 + p2 then pq = p1 q + p2 q = qp1 + qp2 =
qp. If p = p1 p2 then pq = (p1 p2 )q = (p1 q)p2 = q(p1 p2 ) = qp.
The case of ( ) comes from (Lem.17) and the case of
comes from (Th.5).
IV. While Programs
Kleene algebra with tests is a powerful framework to
model programs algebraically. It permits us to reason
about the equivalence between programs and algebraic
equations.
In this section, we are going to model the sequential
composition p; q, the conditional test if b then p else q
and the looping construct while b do q with terms and
operators. So, in the context of Kleene algebra with tests,
we use the following definition:
a) p; q := pq
b) if b then p else q := bp + bq
b) while b do q := (bp) b.
Notice that the clauses begin...end will be used for
parenthesising if necessary. For instance,
if b then p else q; r
should be
begin if b then p else q end r

Volume 7 Number 1

but not
if b then p else begin q; r end
Then any while program can be represented by an expression in the language of Kleene algebra with tests.
The independence of two programs p and q is expressed
by a commutativity condition pq = qp. Intuitively, the
value of the program p is not affected by the execution
of the program q and conversely. The results in the first
section used the particular case where p or q is a test.
(20) Definition. A program of the form p; while b do q,
where p and q are while free, is said to be in normal form.
Our goal is to simulate any while program with a program in normal form (so contains at most one while loop).
Often, we need to preserve the value of a test b across a program p. For, we introduce in a specific place the program
s; bc + b
c such that c is a new test, s an atomic program
symbol and the condition cp = pc holds. The atomic program s assigns the value of b to some new Boolean variable
which is tested in c and bc + b
c insures that the values of b
and c are the same just after the execution of s. To reach
our aim (Th.24), we need to consider four local transformations [13].
A. While within conditional
One considers the program P1
if b then begin p1 ; while b1 do q1 end
else begin p2 ; while b2 do q2 end
We try to find a program equivalent to P1 with at most
one while loop together with the programs p1 , p2 , q1 , q2 and
the tests b, b1 , b2 . We need to preserve the value of b across
p1 , p2 , q1 and q2 , then we introduce an atomic program s
and a test c which commutes with these programs. To do
this, we first give the following theorem.
(21) Theorem. In the language of Kleene algebra with
tests, the statement
(bc + b
c)(bp1 (b1 q1 ) b1 + bp2 (b2 q2 ) b2 )

(5)

is equal to
(bc + b
c)(cp1 + cp2 )[(cb1 + cb2 )(cq1 + cq2 )] cb1 + cb2 . (6)
Proof.
(bc + b
c)(cp1 + cp2 )[(cb1 + cb2 )(cq1 + cq2 )] cb1 + cb2
=
{De Morgans lows}
(bc+ b
c)(cp1 + cp2 )[(cb1 + cb2 )(cq1 + cq2 )] (
c + b1 )(c+ b2 )
=
{Equ.4}
(bc + b
c)(cp1 + cp2 )[(cb1 + cb2 )(cq1 + cq2 )] (cb1 + cb2 +
b1 b2 )
=
{r = (cb1 + cb2 )(cq1 + cq2 ) = cb1 q1 + cb2 q2 }
(bc + b
c)(cp1 + cp2 )r (cb1 + cb2 + b1 b2 )
=
{b1 b2 (cb1 + cb2 ) = cb1 b2 + cb1 b2 = b1 b2 =

b1 b2 cb1 + cb2 }
(bc + b
c)(cp1 + cp2 )r (cb1 + cb2 )
=
{Distributivity}

Page 201214

www.ubicc.org

Ubiquitous Computing and Communication Journal

REPRINTED FROM:

bcp1 r cb1 + bcp1 r cb2 + b


cp2 r cb1 + b
cp2 r cb2
Since r is generated by programs which commute with c
and c (Lem.17), r and r commute with c and c (Prop.19).
So, the middle terms vanish.
For the first term, we have
bcp1 (cb1 q1 + cb2 q2 ) cb1 = bp1 c(cb1 q1 c + cb2 q2 c) b1
= bp1 c(cb1 q1 ) b1
= bp1 c(b1 q1 ) b1
and the last term is
b
cp2 (cb1 q1 + cb2 q2 ) cb2 = bp2 c(cb1 q1 c + cb2 q2 c) b2
= bp2 c(
cb2 q2 ) b2
= bp2 c(b2 q2 ) b2
The development of the expression (5) is exactly the sum
of the first and last terms.
Then, by use the last theorem we get that the program
P10

b + bp(cq) c(bp(cq) c)b


=
{Lem.18}
b + bp(cq) (
cbp(cq) ) cb.
On the other hand
bp[(b + c)(cq + cp)] b + c + b
=
{Distributivity}
bp[bcq + b
cp + cq] b + c + b
=
{De Morgans lows}
bp[bcq + b
cp + cq]b
c + b
=
{Commutivity and Th.16}
b + bp(cq + b
cp)b
c
=
{Th.5}
b + bp(cq) (
cbp(cq) ) cb.
Then, by use the last theorem we get that the program
P3 is equivalent to the program P4
if b then begin
p; while b + c do
if c then q else p
end
After a transformation of P3 into P4 , we apply the transformation (A) with 1; while 0 do 1 as subprogram in the
missing else clause of P4 . Moreover, if p and q are while
free, the resulting program is in normal form.

s; bc + bc
if b then begin p1 ; while b1 do q1 end
else begin p2 ; while b2 do q2 end
is equivalent to the program P2
s; bc + b
c;
if c then begin p1 ; else p2 ;
while cb1 + cb2 do
if c then q1 else q2

C. Removing postcomputation
We consider the program P5
while b do p; q

P1 and P10 are equivalent since the subprogram s; bc + b


c
does not affect any values of the subprograms in the P1 -like
part of P10 . Without loss of generality, we can ignore the
precomputation s since if these two programs are equivalent without s, then they are equivalent with it.
Therefore, the programs P1 and P2 are equivalent in
the context of Kleene algebra with tests. Moreover, if the
subprograms in the then and else of P1 are in normal
form then P2 is in normal form.

Firstly, we need that the test b commutes with q so we


introduce the program s; bc + b
c with the condition cq = qc.
The program P5 can be written as
s; bc + b
c; while b do begin p; s; bc + b
c end q
and we claim that this is equivalent to
s; bc + b
c; while c do begin p; s; bc + b
c end q
One can ignore the first occurrence of s and q when proving
the equivalence. We have

B. Nested loops
(bc + b
c)(bps(bc + b
c))b = ((bc + b
c)bps) (bc + b
c)b = (bcps)b
c

One considers the program P3


while b do begin
p; while c do q end

and,

(22) Theorem. In the language of Kleene algebra with


tests, the statement

(bp(cq) c) b
is equal to

bp[(b + c)(cq + cp)] b + c + b.


Proof.
(bp(cq) c)b
=
{Use (k1 ) with x = bp(cq) c }

[1 + bp(cq) c(bp(cq) c) ]b
=
{Distributivity}

Volume 7 Number 1

(bc + b
c)(cps(bc + b
c)) c = ((bc + b
c)cps) (bc + b
c)
c = (bcps)b
c
Thus, P5 is equivalent to the following program P50
r; while c do p0 ; q
where r = s; bc + b
c, p0 = p; s; bc + b
c and with the
condition cq = qc.
(23) Theorem. In the language of Kleene algebra with
tests, the statement
(cp0 ) cq
(7)
is equal to
cq + c(cp0 (
cq + c)) c

Page 201215

www.ubicc.org

(8)

Computing
and Communication
SOMEUbiquitous
APPLICATIONS
OF KLEENE
ALGEBRA

Journal

Proof. By (k1 ), this last expression becomes

to an instance of the program P1 up to some precomputation. Then, we conclude with the transformation (A) that
P7 is equivalent to a program in normal form.
By a finite applications of the transformations (A, B, C
and D), we have proved the following theorem:

cq + c(1 + cp0 (
cq + c)(cp0 (
cq + c)) )
c
0
0
= cq + cp (
cq + c)(cp (
cq + c)) c
= cq + cp0 ((
cq + c)cp0 ) (
cq + c)
c
0
0
= cq + cp (cp ) cq
= (1 + cp0 (cp0 ) )
cq
= (cp0 ) cq.
By (k1 ), this last expression becomes.
Now, by use the last theorem we get that P50 is equivalent
to the program P6
r; if c then q
else while c do begin
p0 ; if c then q
end
Still with the same reason as before, one can ignore r.
Thus the programs P5 and P6 are equivalent. We apply
the transformation (A) to P6 and if p and q were while
free, the resulting program is in normal form.
D. Composition of whiles
We consider the program P7
p1 while b1 do q1 ;
p2 while b2 do q2
where p1 , p2 , q1 and q2 are while free.
The subprogram p2 can be considered as a post computation of the first while subprogram. So by the previous
transformation, P7 is equivalent to the program P70
p01 ; while b01 do q10 ;
while b2 do q2
Again, the subprogram while b2 do q2 is a postcomputation of the first while program. So, P70 is equivalent
to
p01 ; r1 ; if c then while b2 do q2
else while c do begin
q10 ; if c then while b2 do q2
end
for some while free program r1 and some test c.
Next, we use the transformation (A) on the program if
c then while b2 do q inside the while (with 1; while 0 do
1 in the missing else clause) and we should have a nested
while loop in the else clause. The program P7 will be
equivalent to
p01 ; r1 ; if c then while b2 do q2
else while c do begin
q10 ; r2 ; while d do q20
end
for some while free program r2 , q20 and some test d.
After, we apply the transformation (B) to unwind the
nested loops in the else clause. Thus P7 will be equivalent

Volume 7 Number 1

(24) Theorem. In the context of Kleene algebra with


tests, any while program is equivalent to a while program
in normal form augmented with finitely many subprograms
of the form s; bc + b
c and under some commutativity condition.

References
[1] Alfred V. Aho, John E. Hopcroft, and Jeffrey D. Ullman.: The
Design and Analysis of Computer Algorithms. Addison-Wesley,
Reading, Mass., 1990.
[2] Backhouse, R.: Closure Algorithms and the star-Height Problem
of Regular Languages. PhD thesis, Imperial College, London, U.
K., 1975.
[3] Brunn, T., Moller, B. and Russling, M.: Layered Graph Traversals and Hamiltonian Path Problems - An Algebraic Approach.
In: Jeuring, J. (ed.)MPC 1998. LNCS, vol.1422, pp.96-121.
Springer, Heidelberg (1998).
[4] Cohen, E.: Hypotheses in Kleene algebra. Technical Report TMARH-023814, Bellcore, 1993.
[5] Conway, J.: Regular Algebra and finite Machines. Chapman and
Hall, London, 1971.
[6] Desharnais, J., Mller, B. and Struth, G.: Kleene algebra with
domain. TechnicalReport 2003-07, Universit
at Augsburg, Institut f
ur Informatik, 2003.
[7] Eilenberg, S.: Automata, Languages, and Machines, volume A.
Academic Press, New York, 1974.
[8] Iwano, K. and Steiglitz, K.: A semiring on convex polygons and
zero-sum cycle problems. SIAM J. Comput., 19(5): 883-901,
1990.
[9] K. C. Ng. and Tarski, A.: Relation algebras with transitive closure, abstract 742-02-09. Notices Amer. Math. Soc., 24: A 29A 30, 1977.
[10] K. C. Ng.: Relations with Transitive Closure. PhD thesis, University of California, Berkeley, 1984.
[11] Kozen, D.: On induction vs. continuity. In Kozen, editor,
Proc. Workshop on Logic of Programs, volume 131 of Lecture Notes in Computer Science, Page 167-176, New York,1981.
Springer-Verlag.
[12] Kozen, D.: The Design and Analysis of Algorithms. SpringerVerlag, New York, 1991.
[13] Kozen, D.: Kleene algebra with tests. Transactions on Programming Languages and Systems 19 (1997), no. 3, 427443.
[14] Kuich, W. and Salomaa, A.: Semirings, Automata, and Languages. Springer-Verlag, Berlin, 1986.
[15] Kuich, W.: The Kleene and Parikn theorem in complete semirings. In T. Ottmann, editor, Proc. 14th Colloq: Automata, Language, and Programming, volume 267 of Lecture Notes in Computer Science, page 212-225, New York, 1987. EATCS, SpringerVerlag.
[16] Mclver, A.: Mathematical foundations of Kleene Algebra.
African Institute for Mathematical Sciences (AIMS). Stellenboch University, South Africa, (22 May 2008).
[17] Mehlhorn, K.: Data Structures and Algorithms 2: Graph Algorithms and NP-Completeness. EATCS Monographs on Theoretical Computer Science. Springer-Verlag, 1984.
[18] Schmidt, G. and Str
ohlein, T.: Relations and graphs EATCS
Monographs on Theoretical Computer Science. Springer - Verlag, Berlin, Heidelberg 1993.
[19] Struth, G.: Calculating Church-Rosser proofs in Kleene algebra.
In: H.C.M. deSwart (ed.). Relational Methods in Computer Science, 6th International Conference. Lecture Notes in Computer
Science 2561. Springer 2002, 276-290.
[20] Tarski, A.: On the calculus of relations. J. Symb. Log. 1941.
[21] V. R. Pratt.: Dynamic algebras as a well-behaved fragment of
relation algebras. In D. Pigozzi, editor, Proc. Conf. on Algebra
and Computer Science. Springer-Verlag, June 1988.

Page 201216

www.ubicc.org

You might also like