Some Applications of Kleene Algebra
Some Applications of Kleene Algebra
Some Applications of Kleene Algebra
Computing
REPRINTED
FROM:
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
Page 201210
www.ubicc.org
(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.
jJ
xj ) a =
xj a and a (
jJ
jJ
xj ) =
a xj .
jJ
Volume 7 Number 1
Page 201211
www.ubicc.org
Computing
and Communication
SOMEUbiquitous
APPLICATIONS
OF KLEENE
ALGEBRA
Journal
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 =
In the following, we give an algorithm to solve the shortest path problem by using the typed Kleene algebra.
C. Shortest Connecting Path
2 2
3
B1
B=
=
1 2
B3
4 3
with
B2
B4
Volume 7 Number 1
kxk)
xa
in
0 2
We have
=
,
0
2 3
0
F = B1 + B2 B4 B3 =
and F =
3
3
B4
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
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
(2)
(3)
(4)
Page 201213
www.ubicc.org
Computing
and Communication
SOMEUbiquitous
APPLICATIONS
OF KLEENE
ALGEBRA
Journal
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
REPRINTED FROM:
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
B. Nested loops
(bc + b
c)(bps(bc + b
c))b = ((bc + b
c)bps) (bc + b
c)b = (bcps)b
c
and,
(bp(cq) c) b
is equal to
[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
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
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