Initial commit of OpenSPARC T2 design and verification files.
[OpenSPARC-T2-DV] / tools / perl-5.8.0 / lib / site_perl / 5.8.0 / Math / Kleene.pod
CommitLineData
86530b38
AT
1
2=head1 NAME
3
4Kleene's Algorithm - the theory behind it
5
6brief introduction
7
8=head1 DESCRIPTION
9
10=head2 B<Semi-Rings>
11
12A Semi-Ring (S, +, ., 0, 1) is characterized by the following properties:
13
14=over 4
15
16=item 1)
17
18a) C<(S, +, 0) is a Semi-Group with neutral element 0>
19
20b) C<(S, ., 1) is a Semi-Group with neutral element 1>
21
22c) C<0 . a = a . 0 = 0 for all a in S>
23
24=item 2)
25
26C<"+"> is commutative and B<idempotent>, i.e., C<a + a = a>
27
28=item 3)
29
30Distributivity holds, i.e.,
31
32a) C<a . ( b + c ) = a . b + a . c for all a,b,c in S>
33
34b) C<( a + b ) . c = a . c + b . c for all a,b,c in S>
35
36=item 4)
37
38C<SUM_{i=0}^{+infinity} ( a[i] )>
39
40exists, is well-defined and unique
41
42C<for all a[i] in S>
43
44and associativity, commutativity and idempotency hold
45
46=item 5)
47
48Distributivity for infinite series also holds, i.e.,
49
50 ( SUM_{i=0}^{+infty} a[i] ) . ( SUM_{j=0}^{+infty} b[j] )
51 = SUM_{i=0}^{+infty} ( SUM_{j=0}^{+infty} ( a[i] . b[j] ) )
52
53=back
54
55EXAMPLES:
56
57=over 4
58
59=item *
60
61C<S1 = ({0,1}, |, &, 0, 1)>
62
63Boolean Algebra
64
65See also L<Math::MatrixBool(3)>
66
67=item *
68
69C<S2 = (pos. reals with 0 and +infty, min, +, +infty, 0)>
70
71Positive real numbers including zero and plus infinity
72
73See also L<Math::MatrixReal(3)>
74
75=item *
76
77C<S3 = (Pot(Sigma*), union, concat, {}, {''})>
78
79Formal languages over Sigma (= alphabet)
80
81See also L<DFA::Kleene(3)>
82
83=back
84
85=head2 B<Operator '*'>
86
87(reflexive and transitive closure)
88
89Define an operator called "*" as follows:
90
91 a in S ==> a* := SUM_{i=0}^{+infty} a^i
92
93where
94
95 a^0 = 1, a^(i+1) = a . a^i
96
97Then, also
98
99 a* = 1 + a . a*, 0* = 1* = 1
100
101hold.
102
103=head2 B<Kleene's Algorithm>
104
105In its general form, Kleene's algorithm goes as follows:
106
107 for i := 1 to n do
108 for j := 1 to n do
109 begin
110 C^0[i,j] := m(v[i],v[j]);
111 if (i = j) then C^0[i,j] := C^0[i,j] + 1
112 end
113 for k := 1 to n do
114 for i := 1 to n do
115 for j := 1 to n do
116 C^k[i,j] := C^k-1[i,j] +
117 C^k-1[i,k] . ( C^k-1[k,k] )* . C^k-1[k,j]
118 for i := 1 to n do
119 for j := 1 to n do
120 c(v[i],v[j]) := C^n[i,j]
121
122=head2 B<Kleene's Algorithm and Semi-Rings>
123
124Kleene's algorithm can be applied to any Semi-Ring having the properties
125listed previously (above). (!)
126
127EXAMPLES:
128
129=over 4
130
131=item *
132
133C<S1 = ({0,1}, |, &, 0, 1)>
134
135C<G(V,E)> be a graph with set of vortices V and set of edges E:
136
137C<m(v[i],v[j]) := ( (v[i],v[j]) in E ) ? 1 : 0>
138
139Kleene's algorithm then calculates
140
141C<c^{n}_{i,j} = ( path from v[i] to v[j] exists ) ? 1 : 0>
142
143using
144
145C<C^k[i,j] = C^k-1[i,j] | C^k-1[i,k] & C^k-1[k,j]>
146
147(remember C< 0* = 1* = 1 >)
148
149=item *
150
151C<S2 = (pos. reals with 0 and +infty, min, +, +infty, 0)>
152
153C<G(V,E)> be a graph with set of vortices V and set of edges E, with
154costs C<m(v[i],v[j])> associated with each edge C<(v[i],v[j])> in E:
155
156C<m(v[i],v[j]) := costs of (v[i],v[j])>
157
158C<for all (v[i],v[j]) in E>
159
160Set C<m(v[i],v[j]) := +infinity> if an edge (v[i],v[j]) is not in E.
161
162C< ==E<gt> a* = 0 for all a in S2>
163
164C< ==E<gt> C^k[i,j] = min( C^k-1[i,j] ,>
165
166C< C^k-1[i,k] + C^k-1[k,j] )>
167
168Kleene's algorithm then calculates the costs of the "shortest" path
169from any C<v[i]> to any other C<v[j]>:
170
171C<C^n[i,j] = costs of "shortest" path from v[i] to v[j]>
172
173=item *
174
175C<S3 = (Pot(Sigma*), union, concat, {}, {''})>
176
177C<M in DFA(Sigma)> be a Deterministic Finite Automaton with a set of
178states C<Q>, a subset C<F> of C<Q> of accepting states and a transition
179function C<delta : Q x Sigma --E<gt> Q>.
180
181Define
182
183C<m(v[i],v[j]) :=>
184
185C< { a in Sigma | delta( q[i] , a ) = q[j] }>
186
187and
188
189C<C^0[i,j] := m(v[i],v[j]);>
190
191C<if (i = j) then C^0[i,j] := C^0[i,j] union {''}>
192
193(C<{''}> is the set containing the empty string, whereas C<{}> is the
194empty set!)
195
196Then Kleene's algorithm calculates the language accepted by Deterministic
197Finite Automaton M using
198
199C<C^k[i,j] = C^k-1[i,j] union>
200
201C< C^k-1[i,k] concat ( C^k-1[k,k] )* concat C^k-1[k,j]>
202
203and
204
205C<L(M) = UNION_{ q[j] in F } C^n[1,j]>
206
207(state C<q[1]> is assumed to be the "start" state)
208
209finally being the language recognized by Deterministic Finite Automaton M.
210
211=back
212
213Note that instead of using Kleene's algorithm, you can also use the "*"
214operator on the associated matrix:
215
216Define C<A[i,j] := m(v[i],v[j])>
217
218C< ==E<gt> A*[i,j] = c(v[i],v[j])>
219
220Proof:
221
222C<A* = SUM_{i=0}^{+infty} A^i>
223
224where C<A^0 = E_{n}>
225
226(matrix with one's in its main diagonal and zero's elsewhere)
227
228and C<A^(i+1) = A . A^i>
229
230Induction over k yields:
231
232C<A^k[i,j] = c_{k}(v[i],v[j])>
233
234=over 10
235
236=item C<k = 0:>
237
238C<c_{0}(v[i],v[j]) = d_{i,j}>
239
240with C<d_{i,j} := (i = j) ? 1 : 0>
241
242and C<A^0 = E_{n} = [d_{i,j}]>
243
244=item C<k-1 -E<gt> k:>
245
246C<c_{k}(v[i],v[j])>
247
248C<= SUM_{l=1}^{n} m(v[i],v[l]) . c_{k-1}(v[l],v[j])>
249
250C<= SUM_{l=1}^{n} ( a[i,l] . a[l,j] )>
251
252C<= [a^{k}_{i,j}] = A^1 . A^(k-1) = A^k>
253
254=back
255
256qed
257
258In other words, the complexity of calculating the closure and doing
259matrix multiplications is of the same order C<S<O( n^3 )>> in Semi-Rings!
260
261=head1 SEE ALSO
262
263Math::MatrixBool(3), Math::MatrixReal(3), DFA::Kleene(3).
264
265(All contained in the distribution of the "Set::IntegerFast" module)
266
267Dijkstra's algorithm for shortest paths.
268
269=head1 AUTHOR
270
271This document is based on lecture notes and has been put into
272POD format by Steffen Beyer <sb@engelschall.com>.
273
274=head1 COPYRIGHT
275
276Copyright (c) 1997 by Steffen Beyer. All rights reserved.
277