Original citation:
Lehmann, D. J. (1976) Algebraic structures for transitive closure. Coventry, UK: Department of Computer Science. (Theory of Computation Report). CS-RR-010 Permanent WRAP url:
http://wrap.warwick.ac.uk/46308 Copyright and reuse:
The Warwick Research Archive Portal (WRAP) makes this work by researchers of the University of Warwick available open access under the following conditions. Copyright © and all moral rights to the version of the paper presented here belong to the individual author(s) and/or other copyright owners. To the extent reasonable and practicable the material made available in WRAP has been checked for eligibility before being made available.
Copies of full items can be used for personal research or study, educational, or not-for-profit purposes without prior permission or charge. Provided that the authors, title and full bibliographic details are credited, a hyperlink and/or URL is given for the original metadata page and the content is not changed in any way.
A note on versions:
The version presented in WRAP is the published version or, version of record, and may be cited as it appears here.
The
Univensity
of
Warwick
THEORY
OF
COMPUIATION
REPORT
N0. t0
ALGEBRAIC STRUCTURES FOR TRANSITIVE CLOSURE
by
DANIEL
J.
LEHMANNDepartment
of
Computer ScienceUni versi
ty of
l^larwi ckCOVENTRY
CV4 7AL
ENGLAND
Algebraic
str:uctur"esfon tr"ansitive
closureAbstnact
Closed semi-:rings and
the
closuneof
matnices oven closed semi-r"ingsane defined and studied.
Closed semi-::ings ane stnuctunes weaker than
the
str^uctunes studied by Conway[3]
and Aho, Hopcnoft and Ullman[1].
Examples
of
closed semi-rings and cl-osune 'ppenationsare
given,
incJ.udingthe
caseof
semi-nings on whichthe
cfosuneof
an el-ement isnot
alwaysdefined.
Two algor.ithms
are
pnovedto
computethe
cl-osune of a matr"ix oven anyclosed semi-ning;
the
finst
one based on Gauss-,Jordan el-irirfinationis
agenenalization
of
algor:ithmsby
Wa:rshallo Floyd and l(feene;the
second onebased on Gauss
elimination
has been studied by Tar.jan [11]
and I 12],
fnomthe
complexitypoint
of
viewin
a
slightly
diffenent
framewonk.Sinrple semi-nings, whene
the
cfosure openationfor
elementsiist$iitia],
ane defined and
it is
shownthat
the
closuneof
an nln-matnix over asimple
semi-ring
is
the
sumof its
powens od degr"eeless
than n.Dijkstna
serni-rings ane defined andit is
shownthat
the
rowsof
the closur:eof
a
matnix ouena Dijkstra
semi-r"ing, can he computedby
af.
Introduction
WanshalLrs algonithm
for
computingthe tnansitive
closureof
aBoolean
matnix, Floydts
al-gorithmfo::
minimum-costpaths,
Kleenets pnoofthat
every regulan language can be definedby
a r"egulan expnession andGauss-Jordanrs method
fon
inver.ting
::ealmatric€srmer.d{ffuAtt
intenpnetations
of
the
same pnog:ram scheme(
with
one counte:: and an'l anray).
-By prrcgnam scheme
is
meanta
te::minating pnognanwith
fixed
control- butwhene
the
sets
oven whichthe
var:iables(or
some6f
them)take thein
val-ues and
the
meaningof
the
a1$ebnaic ope::ationsisLlb|ft
uninterprreted.The pu::pose
of this
papenis to
investigate the
conditions
of
cor"rectnessfon
thnee such schemesfor:
closureof
matnices and to showa
number"of
diffenent
structunesin
whichthey
carr beusefully
applied.The
proof
of
connectnesswilt
beof
algebnaic t54pe and unden assumptions weaken than those madein
pnevious works([1], l2), nf),
and withoutintnoducing
infinite
sums.The
feeling
that
the
numenical pnoblemof
inventing
real- rnatrices wasclosely
rel-atedto
some paths pr.oblemsin
graphs, has been pantof
thefolkone
of
the
subject
for
sometime
and has beenrecently
expr.essed byGqndnan [
0J,
Backhcueand car,rd I zf and rar"janI
lr] ; this
wonk showsthat,
in
a
pnecise sense, both pnoblemsare
special
casesof
the
same genena] pnoblem and pnoposes generar argonithms which,when
speciarized,
neduceto
the
methods mentioned above.J_irf${D
* rt
waspointed
out
to
the
authon by an anonymous nefeneethat
thealgorithm
fon
computingthe
transitive
closu::eof
a
boo]eanmatnix,
generallyattributed
to
warshalI,
had beenpreviously
describedby
B.
Roy [1e.The main
novelty
of this
wonk isthe
definition of
the
closuneof
matrixby induction
onthe size
of
the rnatrix
usinga
Cecompositioninto
sub-matrices. ft is
shownthat
sucha
definition
implies
the
cl-assicalequation A:':
=
f
+ A.A:'r(f).
In
structures
where(l)
has more tharr onesol-ution
it is
the
authorts
experiencethat it is
alwaysa
simpletask
to
show equival-ence
of
the inductive
definition
usecl andof
any othen reasonab-l.e dcf.'-i+'i^-€^-ss.trr:rLrurl, rL,r,exampl_e
bI
meansof
l-east sol-utionsto (t),
whena
suitableor"der- can be
defined.
,,
2.
Closed semi-ringsWe shal-] consider. algebnas
of
the type {S,
*, .,
,l,
O,
I}
whereS
is
a
set, *:
SxS+
S and.:
SxS -) S+ar"ebinary
openations,*:
S -+ Sis
a
unaryoperation,
and OeSleS
a::e constants.+
wil-I
be
called additiono
.
multiplication
and*
closune.In writing
expnessions we shall choosethe
infix
notation
a*bfon
+(arb),a.b
fon .(arb)
and a:tfor "t(a)),
assumethat
closur.e has pneced.ence oventhe other
operations andmultiplication
over additiOn.Sornetimes we
sha1l
also
abbrreviatea.b
to
a.b.Definitioq:
An algebr:ais
cal1eda
closedseni-ring
iff
the
following
equalities
aneidentical_ly
tnue:a)
a+(b+c)= (a+b)+c
addition
is
associativeb)
a+b =b+a
addition
is
commutativec)
a+O=
a
Ois
a
unit for
additiond) a.(b.c) = (a.b).c
rmltiplication is
associativee) a.I
=
l.a
=a
I is
a
unit
for. mul_tiplicationf
)
6. (b+c)=
a.b+a. cNote:
We donot
askfon
cornmutativityof
multip.l-ication,
foni
. -;:pidenpgtercyddftaddit:i.oa (aod,=";,
for:
(s1f):!
=
(a*b )*brt,
(".b):l
=
l+a. (b. a)t .bon even
for
a.0
=
O.a:
0It
seemsthat
axiomsc)
ande)
assentingthe
existenceof
units
for
addition
andrnultiplication
anenot
essential- and could have beenleft
out
had we chosento
axiomatizetransitive
c.l-osut?epnoper
(as opposedto
reflexive tnansitive
cl-osu:re)
nut the
formulae woul-d have been muchlongen. It
seems thoughthat in
certain
inter:esting applications
theneis
no zero element (seeIZJ
p.160 whene ze::ois
cal]ed
one)Matrix
Openationsopenations
similar:
to
addition, multiplication
and closune canbe
defined on nxn matnices
over
a
closed semi-ning,that
makethis
set
nearlv
a
cl-osed semi-ning.Let
A and B be nxn matnices ovena
closed semi_ning S.^-f--l
A
= Ia..l
D- la
-1t_
ijJ
i,je
[r:nJ
u
-
l]r:j
i,
je [1:nJLet
us define-3-A+B=
Fr,
*ortri,ie[l:nJ
A.B = |
xThe closune oper.atior: on
matrices
is
definedinductively
onthe size
of
the
matnixby
decomposingthe
matr.ixinto
four
sub-matnices.
Thedefinition is
conrect because, aswill
be shovrnin
the
next
panag::aph,the size
of
the
sub-matnices usedin this
decomposition doesnot
bearany relevance on
the definition.
Definition
of
the
closuneof
atxn
matrix:A:t=
F,-g:'sg6rrpg:'c
B,tcd;l
fon
A=E+DB*c
tl
Lt*on,.
A:!
J
$g3, It is
not
true in
gene::althat
thithflsfdaftrirition
gJs .r g:tg6fcpgr'.-
.6n
be neplacedby
ig
1gg:'cp):t;
howeven Conwaylll
has shown
that if
thnee moneidentities
ane tnuein
the
cl-osedsemi-ning
a.O =
O.a - 0 ,
(a.b)",
=1+ a.(b.a)*.b
(which implies our:g)) and
1a*
6)tl
=
(a?tb)?'s.a*, thenthe
aboveneplacement
is
possible
andthe
conrespondingidentities
for"matrices
hoId.
This
is
probably so evenif
only the
last
tw@identitie"
"T
assumed.Conversel-y
it is
easyto
seethat
the val-idity
of
the
aboveneplacement
implies the
last
twoidentities in
the
pnesenceof
the
finst
one.Let
us nowdefine
two matricesof
constants:If n=1 [a]'t:[a:t]
rf n
>1 and
A =[B
tl
whene,for:
some O <k
e n
:L'
EJB: kxk, C: kx(n-k)r D:
(n-ft)xkn
E:
(n-k)x(n-k),
then
0r,
=
[tij]ir1.[t,rr]
with
It is
easyto
venify
that
the
analogof identities a), b), c), d)
andf)
hold fon
matnices.Note: tfie:aaalogue:r5fe)):
A.Ir,
= Irr.A
=A
doesnot
ho]-d.Connectn_ess
of
the inductive definiti-on
of
closuneCompl-etion
of
a
pantials
clo?ed semi-ninq,Define
a
pantial
closed semi-r:ingto
be an algebnaof
ths 1l?.
described above, whene closune
is
only a
pantial
function
andsatisfying
a) ... f)
abdg)
wbebeventle
c&drsyneof
a
is defined. rf
s
is
a
partial
closed semi-::ing
then
sU{u} (wheneuls is
a
new element and standa fonundefined) canlrbe made
a
closed semi-ring by adding thesedefinitions:
u+a:a+u=ur
€t.u=u.€r=ur
u:l=u
add a?t=u if a*
wasnotpneviously defined.
SU{u}
is
ca]1edthe
conpletion
of
S.that
the size
of
the
sub-matnicesinvolved
in
the definition
ant
boils
downto
computingthe
cl_osuneof
a matr"ixwith
n6nees
in
twodifferent
wavs:r-r-ll-l
leln
c I
la Blc
Il-i
lli
I nlr
F
I
ana
ln
EIF
Ir r I T--'l
le lu r I
lc Hlr
IL):LIJ
ing nine
identities.
Thevenification
is tnivial
usingity
andassociativity
of
matr"ixaddition, associativity of
tiplication
and distributivity ofmatnil multiplication
ovenLtion.
lxiom
g) is
not
usedin this
proof.:at:'-on
is
canniedout
in
Appendix 1of
tgJ.The pnoof
tl
is
inrelevalsub-matnicer
and
ver"ifyir
commutativit
matnix
multi
matr"ix addit
Note
that
axThe
venifica
-5-The
careful
neader now undenstands whythe
troubre
was takennot
to
include
the
identity
a.0
=o.a
=
o
in
the
rist of
axioms andto
dealwith
identity
matnicesI'
which ar"enot
neal
identities.
we shall now prove
that
the
anarogueof
axiorn g) hordsfon
matnices.But
first
a
lemma:Lemma
1: If
A and B ane nxn matrices over.ta
closed semi-ning then:1) (r +B).A=A+B.A
n2) A(I +B)=A+A.8.
nPnoof:
r-ILI in
l"
+ B).Al
..
. - x
(6-.,. + b.,-)u,-* =I.a-..
r
b,-..8.,r
+ [
(o
+ b_.,-)q-.-_l lrl
k=lrn
ik kj
ij
-ii- i1
k=lrr'-
-ik'-kj
k+i
=
a.. + X b..
1l
a..
k=Irn
fK
lclAnd symmetnically
for
2).Iheo_rem
1:
If
Ais
a
nxn matnix then:A:k=f +A.Afs=J
+A:'r.ABloof:
The twoequalities
being symnetnic J-etus
just
prrcvethe
finst
one.By
induction
on n..If n=1A*:1+a.a*byg)
rf n>l
supposeA = [U'l
c:kxk
[_e
FJ
with
A=
F+
EC?ID,by
definition:
Fo
*. gfip6etggzt Cr"DAxlA*
=
l_r*pg*,
a?r
J
A.A*
=
Fa'.
1
ggJsp6:l5grl1
ptr:lgg:t
cc'*DA*+
oal
But by
the
induction
hypothesis:C*
=
fk
+ C.C:t arrd
Ar" = In-J<f
AA*By lenrna 1:
p6:lggfs
1
3g*p6alggJs= (Iu
+
gg*)p6:rgg?t= CrsDArtEc*
DA*
+
gg:"'p4:!=
(rk
+
cc*)D^rr= g*p4:t
ECrt + 5g'.tp4:!gg:t + FA:!EC,!
:
EC* 166:tggfs=
(In_k
n: A?IEC*
gg:lp6:t+FA*=66:r
Then
rr.
+ A.A:t=
|
tu
+
cc:k1
g*p6rcgg:t
g:tp6:t -1
I
I
n'*ec
r,r-k +
AA't II
n-K
_l
:
6r'sby
the
induction
hypothesis.46:t )59:l
Q.8.0.
Corollanv
l:
By
Corol]anv 2:
By
Corollanv 3:
By
A.Aai'=A+A.A:}A=A{rA
Lemma
1
and theonemI
A:!=I_+A+AA,'sA
n
Theorem
I
and eorollar"yI.
B + /iA'*g = A,:tg
and B
+
BAtrA=
BA?,..Lemma
l-
and Theoneml.
3.
Exarplesof
closedBool-ean semi-ring:
semi-nings
{ {0rf}, u,
n,
T,
OoI ]
wheneT(O)
= T(t)
=
r
tr"ansitive
andreflexive
The closune
of
a
Bo6lean matnixis its
closune.
A pnoof
of that fact
can be obtainedeithen dir:ectly
induction
on using par:agraph 5 on simple serni_nings.{R U{+-} . + J r 'arr, t, Z, *-, O] whene R, is the set of
Mi-+
nol-negative neal
numbersis
a
c.l-osed semi-ning wheeeZ(a)
=
O aeRU{}-
The closune
of
a
matnix overthis
semi-ningis
the
minimum-costmatnix
for
the labelled
gnaphyielded
bythe
matnix.{&
J{+-, *J., l,tin-r.l,.jap,
o-} wheneft is
the
6et
of
/'^
neal
numbersand.
arr=f
c if
a)
o(--itaco
is
a
closed semi-ni:rg,if
(+-)
+ (-o) -
+o.The closune
of
a matr.ixgives the
minimum-costmatrix
for.
the conrespondingIabelled
graph, on--
whenthere
ane pathsof
costas
sma.l-1 as desined.Similanly
{Qt{+-, --},
Min,
r, ,t, r-,
O}and
{ZU{F, --},
Min,
*, rt, f-,
O} aneclosed semi-nings,
and so
is
{BnU{+-,
-*},
Max,*, Ot'*,
O}with
.t= (n- if
a
> o(otta=o
0n
this last
closedsemi-ring
the
closur:eof
a matnixgives
themaximum
cost
pathsin
the
conresponding gnaphsor
+- if
ther"ear.e
paths
of
unbounded cost.{finU{+-},
Max,Minr--,,Or,_+-}
whe:re-(a)
=1- is
a
closed semi-ningand
the
cfosuneof
a matnix oventhis
i:ing
gives
the
maxirnum_capacitypaths.
Mone genenally
if
L
is
a
rattice
with
openationsv
and A and bottom (r0and
top (r) then {L, v, A, T, 1
T} with T(a)
=
r is
a
closed[P(X'isJ,
U, . , 't. d, e] is
a
closed semi-::ingif
X
is
analphabet, e
the
empty wond,.
concatenation andA.*= U
A1ieN
{RUtu}n
+. . , s.
O.l} is
a
closed semi-ning fon"(u)=T*
fona{t
and t-*=u
and a+U=U+a=U
U.a=aog=U
and U*=U.
The same
is
tnue
if
Ris
replaced by 0.In this
c]-osed semi-r"ing,if
a matrix
Ais
suchthat
A* doesnot
containu
thenA*
= (I-A)-1
(A doesnot
containu eithen),
by theonem l-.-'l
A
*
may be computedby
computingthe
crosuneof r-A, at
l-eastif
(1-6;*sdoes
not
contain u.unfontunately thene ane non-singulan matrices A such
that (t-R;*
uo""contain u.
Sti11
if
Pis
a
penmutation matnix suchthat
(I-pA)'t
doesnot
contain uthen
(r-pA)t =
(pA)-l
=6-1
,-1
and(r-re1*'p
=A-f,
andthe
computationof
A-1 may be neducedto
that
of
closure.Conver"selYr
if
Ais
non-singulanthere
is
a penmutation matnixp
suchthat
PA can be invented by Gaussianelimination
without
pivoting.
Asshall
be
seenlaten
Gaussian el-imination methodwithout
pivoting
applied on B computes(f-g)"r,
then (t-pA)rl =
(pA)-I
and doesnot
contain u.-9-{FrUro,*rlxt,lxx} is
a
closed. semi-ningif
L
is
a
complete1attice
withzeno efement .t- (rUa=a
)
and upper-oper:ation U,F
is
the
set of all
functions:
L
-rL
satisfying
:Q)
f(UA)
=U{r(a) |
aeA}
fo::
any AcL, ArdU
is
aefinedby
(f!g)(x)
=f(x)llg(x)
with
an obvious notational- arnbiguity,o
is
function
compositionrlxJ-the
constantfunction
bottorn and ),xxthe
identity,
and
't is
defined by:(3) f'(x) =U{rtC*) | i
=o,t,
}
.On
this
semi-ningthe
computationof
the
elosuneof
a
matnj-x amor-yrts toa global
data ft_ow pnoblenr [TJ.Ali- distr'ibutive
g1obaldata
flow
pnoblems can be tneated astnansitive
closurre problems
but non-distributive
pr"oblems, whe:re(Z)
is
neplaced bythe
weaker assumptionthat
the
ftrnctions
of
F ane monotone, donot
seemto
fit into
our
fnamewonk.-9b-4.
Wanshall-Floyd-Kleenets algonithrn. Gaussdondan method.An argonithm
will
now be pnesented,to
computethe
cl-osureof
a matr:ix.
liFLaleorithg
(trol,
IreJ,
Isl
,
IB]]
Input:
A=fe.l ..r
L tU
arlet-I:nJ
tij t s
closed semi-ningbegin
1.
for-each
i, je[l:nJ do
A^[i,
j]
<-Ati,
jJ;
o
2. fol k:=I :Ep t until
n
do3.
€g!
eachirje[l:nJ
ds4.
AkIi,j] *
Ax_rti,JJi+r,1*+rIi,kl.
(on_rrn,k)r*An_atk,j];
5.
fon
eachirjelI:nl
do6. R[iri] * 6r.
1lK
+
A,,f,iril;
end
IOutput:
R[irj]
fon
i,je[1:nl
Note: 6-. in line
1l6
is
1 for:
i
=
j
and0
otherwise.This
algonithmis
a
str"aightforwandtnanslation
of
Kleenets proofthat
evenyregulan
ranguage can be nepresentedby
a
negula:: exp::ession.Ftoydrs
algorithm fon
minimum-cost pathsin
dinected graphsis
aspecialization
of
the
abovealgorithm
to
the
case where at!=
I
gaes andWanshal-lts algonithm
fon the tnansitive
closuneof
Boolean matr"icesis
its
special-ization
to
the
closed semi-ning {O11}.The algonithm computes
the tttransitivefr
crosureof
Ain
A.
andits
rrtnansitive
andneflexiverr closure
in
B.
Its
specialization
to
the
closed. semi-ring &U{u}
is
Gauss_Jond.an methodfor
inver"ting matnices,without pivoting.
-10-The
repetgtive
statements used aneof
two t54pes,the
fo:r
statementof
ALGOL,ild
a fon
eachstatenent
indicating
that
the
onderin
whichthe
vafuesare given
is of
no importance.For each
irje[t:n] is
an ab$neviation fonFon each
(irj )
e
[1:n] x [l:n]
.The
algorithm
usesn+l diffenent
matrices\
(0< k <
n)for simplicity. It is
not
difficult to
wnite
anequivalent
algonithmusing
only
one suchmatrix, taking
carethat
entries
in
the
mat:rix arenot
changed befor"e theY ane used.We
shalf
now proceedto
pnovingthat WFK-algonithm computes
in
R the closuneof
the
inprrt
matrix
A.Notgtions: If
C isa nxn;matrix
let
usdefine
atirt
lt3rgl to
berits
submatnixconsisting
of
rowsi to k
and columnsj
to.Q,.(r
<
i
<k
<n,
1<
j
<.c,Gri).
To
simplify
this
notation the
fi:ll intenval [1:n]
will-
be abbreviatedto .
andthe
one el_ementintenval
[iri] to i.
.r-L
Examples, Ai. is
the
i"'
rowof
AA_. 1l
j is
the
element At i o jl
In matrix notation the
algonithm computesa
sequenceof
nxn matr:icesrk)
A""
fon
0< k
(
n
defined bv:/^\
At"' = A
A(k)
_
o(t-r,
-
ojX.tr.
olX-t),',.u(k-r)
fon
1(
k
(
nand
the
output
R by:R
=
rr.,nA(t)
we
shall
now pnoveth.t A(t)
= A*
A.Arr.A,the
pnoofnot
nelyingon assumption
g).
Theogem
2:
Fon anyke[o:n]
A(k)
-
A +A.ir(r(r(orr,krtr:nJ" otr:kr
.
\/
(witn the
conventionthat
A.tr:ol, A[r:olr[1:oJ
and
Atr,o].
shouldjust
be
ignored).This obviously implies
o(n) -
A+
A ArrA.Proof:
Byinduction
onk.
l/^ \
Fork=O
-L2-Fonk=t+1
(0<n(n-1)
A(k)
=
a(r)
*
affl)
Gr!*))n
At:)
(r)
by the- pneceding
natnix-fosn
of
WFK_algorithrn;and by
the
induction
h3pothesis:o(l)
-
o
*
A.[1:.e,](otr-,rr-r:gr)'t
A[t,.t,].
(2)Define
t
=o[r:r][l:n]' t
=Ak[t,l],
Q =A[r,g]k
Then: ltr \ l \- / V
t,o \
A'-r
/a \ ^ \1,/
J<k
Der.ine
o
=ofi)
The respective
- A.
+ PB:10koK
positions
o{
B,
P and Qin
A aneillustnated
byFig. I
(-
ro
ws
F5. I
: A.
+kk
=A'k*
=\.n
A R:!n
".[]-:ol"
*tt','o[r,u].
PB*Q
A
Rewniting (t_)
e(k)
= ausing (2)
we get:*
A-.Lt:.e,J-
".
^-B?t A--"[1:r].
-
[.*
n
o.rr,urt'I
ot'
F.
* ls"err,s]J
[image:17.595.79.503.58.783.2]But,
by
definition of t
(orr,r<t[]-:,.):
ll
\.--/L'
he closune operation:
=
F-
1
srsqd*PBr'u:tqaf
l.nrrn
^-l
--l fi
al
\d
/
'\rr
A.Ir,k]
(otr,rrtr:rr
)
A[r,k].
=\/
A.[r,l]
(Bal+
3*q4:lPBrs)utr:ll. *
A.k A".'lB:lA[t,t].
*
A.[r,g]B*QA'r\.
*
O.kO,*\.
Companing
with
(3)
gives
A(k)
-
An
A.tr:kl
(Atrtrtir:tr/
/
\
oA[1rk].
'
a.t.o.
and
Coryl-l-ary
(usingg) again):
R = Ar!B$,
R=
f-
nn
+
a(t)
=
I*
+ A+
AArtA and byconcllary
2to
Theonem 1:ft
= 6:!'5.
Gauss methodAnothen argor"ithm
shalr
now be introducedfon
computing theclosune
of
amatrix, the speeialization
of
whichto
the semi-ring
e
U{u}is
Gauss algonithmfon
inver"ting neal matnices(without
pivoting).
Gauss aleonithm:
fnput:
A=
[a.
.]i,
je[I:nJ
uij.t
c]-osed semi-ning begin1. for
eachirjelt:n]
doco[irj]
<-A[ioj];
2. fg
k:=1 ElSp 1until
n
do3.
fon
eachi, je[k:n] x [1:n]
do-14-4.
ck[i,
jJ
<-G*-r[i,
j]
+
.r-,_ii,-r.
6--rrn,u)'*
co-r[k,
j1;
5. for
eachirje[l:nj
@6.
B[irj] * G,[irj];
a -'J.
fon
i::n-l
step
-1 rgtif I
do8.
fon
eachjrke[l:n] x [i+t:n]
do9.
B[irj] * B[i,j]
+
c-.[irk] slkrj];
10.
fon
eachirje[1:h]
d-o-13.
RrlirjJ
<-6-.
+
B[i,j];
_LJ
Output: Rrtirjl
for:
irje[1:nl
&gel\g,
The algonithmis
a
str:aightforwardtranslation
of
Gaussinvension method.
In
the
vension pnesented abovethe
useof
memony spaceis
very
inefficient
butras
with
lfFK-algonithm,it
can be ned.ucedto
one nxnmatrix
bvobvious changes.
The
essential
differences
with
WFKare
that in
statement3
i
unns onlyfnorn
k to
n
insteadof
fnomI to
n
andthat
a
second pass, upwardso takesplace
after
statement 7.The advantage,
of
Gauss methodis
appar:ent when one may supposethat
o.d
=
a.0
=o
(fon al-I the
ars
which a::ise duningthe
executionof
thealgonithm) and when
the input
matr.ix A containsa
la:r'ge nurnbenof
zeros.rn
this
casethe
zerosptay
in
longenin
Gauss methodthan
in
I{FK.In tlll I
Tarjanrunden assumptions cJoseto
ounsbut
seemingl-y incomparablewith
them, has sbqwnthat,
with
suitabLe data nepnesentatiirn, Gatss nethod may be implemented. ina
number:of-basic
steps
(ona
paprdorn_aec6ss machine)which
is
almostlingar in
the
numbqr-of-:4on-zenoentries
in lhe
inp$t
matr"ixf,on
a
lar"ge cl-aFq of matriceswith rgstricted
zero-non-zenosrnucture.
Thewe shal-I now pnoceed
to
showingthat
the
above argo::ithm computesin
Rr
the
closu:reof
the input matrix
A.
Refenenceswill
be madeto
thenotations
usedin
the
pnoofof
correstnessof
I{FK.C1ear1y,
in
matnixnotation, the
finst
passof
the
algonithm (statements1-4)
computes of sequenceof n*f
m6frigss^(o) ^(t-)
- (n)G
" , G'-'.
..G""
suchthat:
e
(o)
= A(o)
=A,
c(1) _
a(1),
Then
in
statements5-6
it
computes anjo)=ajk) fon r<k(r,
-k.
"k.
1^)
or
monepictunesquely
B'"'
=ft \
fL)and
G"''
=Ait,r,: f""
nratnix
B(o)
suchthat
1<k(n.
[^l"l
t-.1tl
ldt'l
l:l
|
;(n)
1Li"'
-l
computes
a
sequence of nowThen
in
statements 7-9the
algonithnvectors
n(t)r...rB(1)
"rr"h
that:
r(")
=r,ll)
=o::)
",d
o(t)
_
o(o)-
-k.
JEt'"k[k+I:n]
^,n*rrl
rJl
B(k+2)
|brn)
J
r(u)
=4:)
Theorem
3:
Fon anyk
1(
k
(
n,Eg€,
By backwandsinduction
on kFonk=n r(n)-o(n)
n.Fon
k =
.t-l-R(k)-o(o)*o(o)
"
"k.
'"k[k+I:n]
-(t<+r).
IJ ^ (k+2 ) bir"
r^
(n)
^[k+1:n]
_
^(k)
.(r)
tet
us now consider" apartition of
Ainto sub-matr"ices
Fnl
A= f
- | suchthatBiskxk.
tl
E_iPnecisely:
B =A[r:k][k:k]'
c
=A[t,t][k+1:n]'
o
=
o[nnr:n][I:k]' t
=^[k*1:n][k+r:n]
By Theonem
2:
A(k)
-
A +A.[r:t] (orrrklrr:k)
n
orr,nr.
,andA(n)=A+AA*A.
\
/
or
using
the
partition into
sub-matnices:r-
-'l
r
-rA(k)_la
cl *
lnlB*
rBcl
f_o
eJ
Lol
f-l
= |
B+
BBr',B C+
BBtrCl
tt
wedefine
A = E+
DB*C "iJ+DB?IB
a
_JBy
Corollaries
l
and3
toTheoneml: B+
BB'}B=
B?tB A+
AA:IA = 6:1trc +
BB:IC=
l:'sg and
D+
DB*B:
plfs.Consequently:
f
_-1,i
\
IBlsB
BtrC IA(K/
= lrrn
^_l
r
and
A(t)
=tr,t6
= [i"
+
B*cA?tDBx 3'*g6,1'l[t
.l
[l'tps*,
^,r
J Lr
r_.]because
the
definition of
the
cl-osur"eof
amatrix
is
independentof
the size
of
the
sub-matrices chosen.Then
otX]
=
F.'
'*l
Iii-t
''
I
=
Bi:. clr- \
R(k)
_
a(k)-
"k.
r
=
lBrl lur BI K.
I
=
lsi', tv eL_:'"
But,\
A,lt'
=
lnt
s^
L*'
_(k)
Then:
Q.E.D.
6.
Simple semi-ringsA
class
of
closed semi-r:ingswill-
now bedefined
in
whichthe
star
openation
is
simpleto
perform: a*
= 1
fon
anyaeS.
A chanactenizationof
the
closure
of
a
nntnix
overa
simple semi-r:ingwirl-
be giventhat
relates the
closur"eof
amatrix
to
the
sumof
the
l-abe1sof
the
elementarypaths between couples
of nodes.
Simple ser,ri-rings
are
exactly the
Q-semi-ringsof
Yoel_i '[1]*]o and thefundamental propenty below shows
that
our
definition of
closure
is
a
connectversion
of his
not quite
cornectdefinition of
the
tnansrnissionmatrix
(notquite correct
becauseinfinite
sumsare
usedwithout
ever being properlydefined;
similar
canelessnessis
foundin [1]
andt2l.).
* o(k)
''^k[t+t:n]
"Ik+]-:nl.
o(n)+
B':'k.
CA*DB*
B3tK.
C+
BilK.
CA*A I_-l
+
B.:'rK.K.J
CA*DB*
Bis CA;l+ R:l n^:'.'np:!R r
,
-k.vd uu..!
, -*.cA*D
rlefl.c
+
B*.cAtrDB*a*
uii.c^r'E]l
From
that it
follows
that
the
output matnixRr
is:
l- orr
l-l
r- \Rt =
J + | :..1 - r
-n I i,(n)l
+
A\t'l
= 6:tn tDl J
-The r:egular algebr"as
of
Carrd and Backhouse ane cfoseto
or::: simple semi-rings(they
donot
assumea+l
= ]
but
assume a+a:
a
and arule of
infenence);
their
axiomatization makes an e>itensive use
of
the
onde::: a<biff
afb
=b
andthis
seemsto
take
us far" away fnom linear"algebra.
The author" doesnot
know howto
companethe
stnengthof
the
axiornsfor
regulan algebnas and simple semi-rings.!S!ili!!gl:
A cl-osedsemi-ring
is
cal-l-ed sinnpleiff, in
addjtion
to
assur,pticris ar ). . .g), the followjng is
tnueh)
a+-l= .l
.A nrlnben
of identities folIow,
fon
example:
1+ 1= l,
a+a:a,
a*= 1, a+a.b=a+b.a=ar
a.b.
+ a"c.b
=
Et.b,
C)oa = a.O:
O.The
l-ast
of
these
identities is
pnovedbyi
O.it = O+ Ooa:
O(f +
a)
=0.1
= 0.-r_8b-andB=
then
The
next
theoremwill
providea link
between closur"eof
matricesand
labelled paths in a
gnaph and be usedto
pnove asa
Coroll3prr rh:+oven simple
semi-rings,
closune behaves neasonablywith
respectto
interchanging
at the
sametime
nows and columns.This
l-ast
result
has already been pnovedin
[3J
by Conway(p.1I1)
under much weaker assumptions (thoughthe
wholeproof
hasnot
beenprinted)
andasit is
the
only
nesul-tof
impontancefor
the
next
section,
a:leaderfamiliar
with
Conwayfsnesults
and uninterestedin
gr:aphs mayskip
to
thenext
section.Fundamental EnoDentv of simple semi-rinss
If
A= F.J.
I rlllrl€Ll:nl
.:_rr -_-,is
a
nxn matr.ix overa
simple semi-ningA/t : b.. r_l rt
t-rJ€LI:nJ
I
a., a, r_ ... d.
,
a.m
t^r- n1o2
Km-fK*
K*Jrt
r\ft... r,.mcr.!.rrr
k_
k alf distinct
I1...1ID
and
Cirfepsnl
frnmi
andi
-A
full
pnoofis given in
Appendix2 of [9]
and abrief
summarywill
only
be given here.S-kgtch_gf.
thg
Eogf..o.f- _t:tre.Iund.aLeltgt pr:ogertv,o.f
-*nlglgse.mi-j:inqp_-There
is
an obvious wayto
l-ookat
a n>crmatrix
asa
labell-ed cornpletedirected
graph onn vertices,
andto attach a
l-abelto afl
directeci paths.The fr:ndamental prapenty
of
simple semi-rings saysthat the (i,j) -ttt
element
of the
closuneof
amatrix
Ais the
sumpof the
J_abel_sof all
elegrntarX
paths
fror,ri to j.
Theproperty
can be prov-edby
using theinducti-ve
defilrition of
A,i'or by
usingthe fact that
Ats may be computedL-t,
u.. - u.. t
1l
r-l-19-by
WFK-
algorithm.
We choosethe
latter. It is
enoughto
prove,
wi,ththe
nctationsused.
in
Section4
that
fon
ke[0,r,J,
"(k)
i=
the
surnof
the
1abelsof all
non-e];pty elementar5r paths f:romi to j
the
intermediate ve::tfcesof
which anein [1:k].
The
assertion
is
p::ovedby
induction
onk
by
simple algebnaic nanipulations.Theonern
4: rf
Ais
a
nxnmatrix
overa
simple semi-ningAfr=r.+A+e2+...+An-I
lnrof:
An el-ementar"y path haslength
l_ess on equalto n-I
arrd thelabels
of
al-l- elementany pathsof
length l,
are
tenmsin
some elementof
At.
Conver.sel-y
a
termin
an elementof A!
(S<n) whichis
the label
of
anon-elementary pa"Eh
is
absonbed bya
tenmof
Akfor:
k<.t, whichis
thelabe]
of
a
shorten el_ementarv path.-19b-Conol]arz:
If
Bis
the
matnix obtained fnom Aby
interchanging nowsi
and
j
and cofurnnsi
andj
then
B:lis
obtained from A*by
the
same exchanges.This
is
not
true for
a
general closed semi-ningbut
Conway has shownin [3] that it
holds
if
the
thneefollowing
identities
hold: a.O=
O.a=
Or (a+b)'t
=
a'!(ba)"', (S)*
= I+a(ba):'sb.
This implies
that if
n-
^
-
[-t
^l
|'
"l
then[_r
El
T;.,. rr.an.,. -lA*'=
'a^ut'^
|
rooA=B+CE:'sD.
|-!',ooT',
.r g:'rptr:tg6l7.
Dijkstra
semi-rings andDijkstrars
algonithm.Definitio_Tr:
ADijkstr-a semi-ring
is
a
simple serni-ningin which
f^
i)
a+b=
)*
on(b
\-[o!":
It is
easyto
seethat
a Dijkstra
semi-ningis totally
onder^edbyther:el-ation:
a)b
iff
a+b=a.
The
addition
is
thena
maximum oper"ationin
the
ordened set:a
+b :
the
maximumof
a
and b.The cl-osune of
a
matnixover a
Dijkstra
semi-ring
can be computed rowby
now bythe following
algorithm.D.ij k_strat
s
a.l-go:rlthm [4] :Input:
A=
[ar*]irje[1:n]
a...
efmentsof
a Dijkstra
semi-ring
,J-J TJ
or
e [:-: n]-20-beein
*
1.
1*{on} i
t2. b[or]<-f;
3. for each ie[t:n] -
{on}
g9 b[i] *
A[on,
i];
4.
fon
eachke[2lnJ
dg5. find
a
je[I:n] -
T
suchthat
b- =
X
b^;I
.1,.[f:n]-T
r-6.
r * ru{ji;
7.
fon
each
ie[]_;nl
-
T
do b[i]
<-b[i]
+btjl.Atjril;
endOutput: bIi] ,
ie[1:nJ
&ig:
the
output
B=
ibtill-.-..
---,
i"
the
o::th rowof
A:'r.]-€LI:NJ
Notice
that
statement 5 hasa
clear" rneaningin
a
Dijkst::a
semi-ningbecause
of
pnope::tyi).
Pnoof
of
connectness:By
the
corr:1laryto
Theorem 4 we may supoosethat or : r
andthat j
in
statement5
is
equalto k.
Thenthe
algo::ithm computesa
sequenceof
-
(1)
.
(n)n
rows: b'-'...b""o
the
l-ast
one beingthe
output,
suchthat:
*(r)_lT ^
u - tf n_- .-rl_l
L
IL2 :nll
o(k+r)=b(k)nljkJ
n
ok*r-
F
_-ll}*t
Ar+rtr*z,r,1l
fon
1< k < n
-
1where on
is
a
nowof k
zero€g ando,lll
t"
suchthat
bJkl
k+'
= ;
b(k)
.Q,=k+r I'
Theonem
5:
For anvk
l-(
k
(
nb(k)
-
(A,',)1[1:k]
F-
Atr,rltr.*r,"i
T -'o +lraj.la-+i.ty matf"iX Of SiZe k.
-k t"
alently,
u(k)
=
p,.,,_r,_,n, o[l]ororr:klrr+r:nf
Er; r'n/lrra+"i^-
^n k.
whene
/ equlv
t-I
Dnn^t. r rvuf .
For
k=f,
b(r)-rEo.,r^.-.,1
=
fio
I
L rtz:nlJ
l_
"lt2:nl
because
(at")r, =
I for
any A.For r<k(n:
b(k-l)=;-o(t-r)
.r,d.Q,=k L
b(k)
_
o(k-r)
n
o(t-r)
K
I
o.
A... -
_ll_
K
KLK+r:nt__lllco-r)
,(k-r)
.(k-r)^ I
=
[trtr.:
o[t*t,.,]n
bk
^k[k*tt"rj'
By
the
induction
hypothesis:*(k-t)
_*(t<-t
^
_*r"[k+]:nl - "[t:k-t] ^[t:k-t][k+1:n]
arru,(k) [(r-r)
*(k-1)
^
-l
D
=
lolrt:.r
D[r,r]
^[r,r.]ik+r:nl
Tt is left fo
u" .y-nrovethat:
f a i \
L(K-4., - ,,^
Dr- ,.^tt)--- r a
LJ-:KI I.LI:KI
Prr fha r'ndrr^+r'^-. hypOtheSiS: b
Dr
Lrrs'ruuu,,..,
hypothesist
oIfli]r,=
(e,',)rrr:k_rl
and
*0<-r)
_ |
.(k-1)
"k
'-
uo.Q.:k
=
o(t-r)
*
u=l*r
o(t<-r)
{'*'u)
fon
any corumn B=
;
b(k-r)
, *(k-r)
Dp.=t
"L
t
o[k+]:nl
b[k+]-:nl_.(t<-r) .(k-r)
s- uk
* o[k+l,r,]
wemaychoose
B
=
/
\'t
(
or*:nlrr:nl)
[2:n]r_./
A[
r,r-r]
[k : n]
(^r-:nt
[k,r't
\"
\
/
1
the
induction
hypothesis.then
_
b(k-l)
bv Kr(k-r)-*(k-r)I
\,',
bk *
=oii.-r"i
(ort:nlik:n1
)
becausein
a
simple\
/
'1semi-r"ing
the
diagonalof
a
closune matnix containsonlv
ones.By
the
conolla:ryto
Theonem4
it is
cleanthat:
(a,t
)rn
=
(6:t)rtr
,
t.rl
Q.E.D.
Notice
that
the
hypothesisi) is
not
usedat all in
the
proof of
connectness
it
only
guaranteesthat
statement5
of
the
algor.ithmis
Acknowledgements
This
workoriginated in
discussionswith
Peter Wegnen andduring
thefirst part of its elaboration I
hada fruitful
exchangewith C.
E1got;I
thank them
for thein
encouraqemenr.Finally I
am mostgrateful to
l'lichaeJ- Patensonfor pointing
meearlier
works on
the subject, his
suggestions and constantinterest; if
somemeasure
of cla:rity
has been achievedit is only
thanksto
him.Appendix
I
Let
us computethe
closuneof
the
squane rnatrixl-e
r
.-l
P =
In
E Fl
wheneArEandfanesquane
l.
H
'l
L_)
using two
diffenent
decompositions.Decomposition 1:
-
'1
f+
F. -
6;ts6fp6r,loioo,,
L__-for6r=f,1P6*3
o F IJ E[^fl
*
ll=
Ln
r-land
icHr
F
tl
+
+
A = T+
*I
= f
+A:tn,f :'cl
" '"'r
-l
I6'if
I-.1
G IA:t
GA"E
A:lBdtDAtslC
+
H6IDA*C +(r-r
+
cA,tB)61(F + DAr'e)cA*B6"jF+H6isp.
II
Prt =
F'
B'!
c'l
ln' E,
F,
Ik'
H'i
''-l
r,
=
Af[Gr
Hr ]=
^ite
[I p-l"
r
Hr
l; ; I =
l^'fG(A'i L +A':iB6?iDA:'s)A+GAfs86,;,
+
l'{,HO*;l J_ I a I_J+
AfH6fDA:tH
=
[:].[]
^r
=I I I
l
A'tB6irA'i [-r t-' Ilr
[o'
r-l
F
rl'*
l-oI
l=
|
l+l
Lo'r:j
LorJ
|-1lt-f
(a't
+ AtrB6lLDA:!)cl.i +t-L
6tDAtsc^'i+
efra'fsl
"
l-c -l|
| la'+
tcHl
p I
lr I r
lrAt = d:! 1
ht _ A'!B6-i
f
[(A'l
+
,qfs1tr:l
"I-" ''"1""
+fA:'.'nA*n"
^tt)
-A:tpA:!nl:! ) n A",B6iFt
af
tc(a,t+
H6tDA'rl
[ (A,l + A*B6:iDAtr )
A?'sB6iDA,!)C
f
Ar,B6iFlAt
tcA.*B6t+
H6.fl
+
6:lFl
r-
A'i.r
te(a,',+
A'lB6t'DA:!) 1g6i':pnf:ll-
--
-t-^'
-FI = Atr "1 A:k "1
tcA,tB6'i
+
Hofl
[H +
Ce,iB]61+
6'f
tF
+ re'rcl
AtDecomposition 2:
oz
tB
cl
DA*B
uA'" lJ GA:tB
62=r+GA'lc+(H+
cat3R)A?tfF-" "'"f"+
DA'!C)=
A,-l
I-l
I I r I JF + DArlCl
]
+
GA"CJr
+DA,rcl
lT,-r
+cAtc_l = l_r
*[-E
+=l-n*
BC
=ll
:l
.
[:]
A'r1
:'.'( H
f '-'
o'i(r
+
DAt c)+
eAf,B ) 61nJ:
(u
+_I
cAt,B )6t Afs(re-J. l .r.
I nn".c)A-i^:l
_l
TI Ht Fl,f f;
-1
AtrfH +
*r'"
6i'(
r
+
J-GA'!B
)6i
le,tc )Atl
-27-DA'tc)At (H + cA*B)6'g'
Dt
=
tiof
+
o'1(r+
DAetc)A'i
(H+
cA*B)6tl
D+
o,f(r
1p6rsg)1f6 4:'s=
6:lp6:'s+
of(r
+
DA*c)af
(ea,r+
(H+ eA,rs)ffDA*)cf
=
A't(r+
cA*B)6fDA:'.'1
4.f66r's4:t
1
6:l+
B6t(FEr =
61!+ 6,i(f
+ J- ,Ll-o'l
[nI
tttl
L.:i
=
oi
L.
I
A"'n cta!
+
of(r
+
DA?tc)l'f
tH+
ea-'nlof)
+ axcA:f(H+
ea,tB)6ff,on
+
A,iB6tDA,',)c+
a-*nofl(
,,
r
ear,B)61+
DA*c)af + er,cafrB
cr
^,:
'
[t l
L.J
A:,:lt/rt
+ d,l(r
n 01,,.)
^t
(H+
cAr,B)61.) D+ c^t(H +
cA,rB)6.iDL\' ' _l
/
+
DAtsclale +cllJ
4*t] :6:t1
A,kB{61
A",86-i +
A.*86,i(F
6fs 1 grk
TR' N
pl
=
nt
-At =
:
{:'.'.r
A?tB6tDA:!-
o-[ruf(r
+
oon.l*.)
^t
(,r
+
cA,!B)6frAppendix 2
Befone we pr:oceed to
the
pnoofof
the
fundamentar propentyof
simple
semi-rings
some tenminoloryis
nequired.A nxn matnix can be viewed as
a labelled
complete directedgnaph on
n
vertices.
"ij
is
the tabel
of
edge(irj).
To any
path (ko,
kr,
k2r...rkm)
fnom koto k, in
the
graph can beassociated
a
uniquelabel-r
ukk_
-k_k-....at ,
4ool ^l^2
Km-2Km-r km-rktThe
label l-
is
associatedwith
the
emptypath
fnom koto
ko,
fo:r
all
ko.The fundamental-
property
of
simpre semi-nings saysthat
the
(iri)-th
erement
of
the
cl-osuneof
a
matrix
Ais
the
sumof
the
rabel_sof
al-lel-eme.ntary paths from
i to j.
Prpqf
:
we could usethe inductive
definition of
A:'cbut
we prefento
use WFK-a1go::ithm.
R = 6:t
=
l-
n+
A(n)
andit is left to
showf n'l +L-+ LrrdL -\"/
-<1 '
' -
L
-l--r-...-I'-
=
the
sumof
thb labels of
Ll
m
tk,--'-k_.
krr...rk,ne[l:nJ
r
m]
al-r
non-empty elementanyk.
;..
.k_
all distinct
paths fi:omi to
j-r-
mand different fi:om
i
andj.
We shall- prove
that
fon
any le[0:n]
-(s)
_.ij =
;
"rur_. .
..uri
u;,
"irr"(s,i,j
)r. k .f1.01 '
^1r...^meLI:&J
kIr.. .k, all distinct
and
diffe::ent
fnomi
andi.
=
the
sumof
the tabels
of
al-I
non-empty el-ementa:ry pathsfrom
i to j
the
intermediateventices
of
whichare
in tr:.t].
-zJ-Fon
t=o
.1?) = d:; =
11 ].tsigma(oriri)
For
.Q, =h
+1.
By wFK-argonithm:.11,
="fl,
-
.fil
,fl,
/-because
/ -rit)\
(";;l
-
1'By
the
induction
hypothesis:(l)
uii'
= signa
(hri,j)
+
sigma(h,i,.{,).sigma
(h,
.t,j)
Let
us
considersigna
(trirj):
its
termsare
labels
of
non-emptyelementany paths fr:om
i to j
the
intenmediateventices
of
which arein [t:h+]-l; of
thosethe labels
of
the
pathsof
whichg
=h+I
is
not an interrnediate ventex ar"e terrnsin
sigma(hrirj)
andthe labels
of
thepaths
of
whichn
is
an intermediate ve::texare
tenmsin
the
pnoductsigma
(hrirg).sigma
(h'noi)
because.Q,is visited
only
oncein
such anelementany path.
Convensely
all
the
tennsof
sigma(hrirj)
appean insigna
(h+trirj);
suppose.rnr_...a*0.
"nnr....h*rj is
a
termof
sigma(hrirg).sigma
(trrl,ri).
rf (irkl
,...rkmrgrhl
,...rhmrj) is
an erementar"ypath
it
appear:sin
sigma
(l,riri) if it is
not
elementapythere
is
a
ventexv
whichis
visited
twice
(andat
least
once as an intermediate node ):v
=k"
=ha , v
=
i
=h,
onv : k"
=j.
Let s
bethe
smal-l-est integen suchthat k" is visited
twice
andlet t
bethe
lar:gest
integer
suchthat
ha =nj.
Then(irk1r...rk"rht+l_n"..rj)
is
a
non-empty elementarypath
fnomi to j
which doesnot
go thnough .Q, andits
l-abel- appearsin
sigma (h oi
, j ) .-30-By
the
identities:
All-
th'e terms appearing i.n sigma(hrirg).
sigma(hrlrj)
which ar"e notin
signa
(Lrirj )
ane absorbed by ter"msof
sigma(h'ioi)
and:sigma