Reently, many type systems forreords have beenproposed. For mostof them, the types
annotbedesribedasthetermsofan algebra. Inthisase, type heking, ortype inferene
inthease ofrst order type systems,annot be derivedfrom existingalgorithms.
We dene reord terms as theterms of an equational algebra. We prove deidability of
theuniationproblemforreordsterms byshowingthatits equational theoryissyntati.
We derive a ompletealgorithm and prove its termination. We denea notionof anonial
termsandapproximationsofreordtermsbyanonialterms,andshowthatapproximations
ommute with uniation. We also study generi reord terms, whih extend reord terms
to model a form of sharing between terms. We prove that the equational theory of generi
reordtermsand that theorrespondinguniationalgorithm always terminates.
Theories syntaxiques et Algebres d'enregistrements
Denombreuxsystemes detypespourlesenregistrementsont ete proposes reemment.Pour
laplupartd'entreeux lestypes nepeuvent pas^etre derits ommeles termes d'unealgebre.
Laveriationdetypes,ou lasynthesedetypedansleasdessystemesdetypesd'ordreun,
ne peuventalors plus^etre deduitsd'algorithmesonnus.
Nous denissons les termes a enregistrements omme les termes d'une algebre
equationnelle. Nous prouvons la deidabilite du probleme d'uniation pour les termes
d'enregistrements en montrant que sa theorie est syntaxique. Nous en deduisons un algo-
rithme omplet et prouvons sa terminaison. Nous denissons une notion de termes ano-
niques et l'approximation d'un terme d'enregistrement par des formes anoniques, et nous
montrons que les approximations ommutent ave l'uniation. Nous etudions les termes
d'enregistrements generiques qui etendent les termes d'enregistrements pour modeliser une
forme de partage entre les termes. Nous montrons que la theorie equationnelle des termes
d'enregistrements generique est syntaxique ainsi que la terminaison de l'algorithme orres-
pondant.
Introdution
Typesystemsforreordshavebeenstudiedextensivelyinreentyears. Formostofthemthe
typesof reords areno longerterms of an algebra. Consequently, results about uniation,
whih yield, forexample, algorithms for type inferene in the ase of rst order languages,
annot be reused, and the problems have to be studied again from the beginning. Type
infereneforMLan bedeomposedinto twosteps. TherststepdeomposesMLprograms
into uniation onstraints; it needs to know very little about the struture of types, as
opposed to the seond step whihresolvesthe uniationonstrains. The author desribed
a type system for polymorphi extensible reords that uses terms of an algebra modulo
equations for its types [Rem93℄. Type inferene for ML with sorted equational theory on
typeshasbeenstudiedin[Rem92a℄. Theonstrutionofthereordalgebraanditsproperties
have beenstudied in [Rem90℄but had not beenpublishedin English yet. Here,the results
of[Rem90℄ arereviewed and theirpresentationisimproved | thestudyis also extendedto
generireordterms.
Here,reordtermsarestudiedforthemselves,independentlyanypartiularuse. However,
wemotivatesomeoftheonstrutionsbytheiruseasthetypesofafuntionallanguagewith
reord objets. In this ontext we temporarily all them \reord types". They enable a
naturalextensionof funtionallanguages withreords. One interest ofextendingfuntional
languageswithreordsistohavefuntionsthatan operate polymorphiallyonreordswith
dierent sets of elds. Reordsare produts of variable sizewith labeled omponents. The
keyideaisthattypesmustreetthestrutureofvaluesandthereforereordtypesmustbe
produts of dierent sizes with named omponents. Types of reords arry information on
alllabels,butonlya nitenumberof labelshave dierenttypes, sotype informationan be
nitely represented. More motivation an be found in [Rem93℄. Typesof reords are often
dened by onstruting all elds at one. This requires the introdution of a olletion of
symbols fa
1
: ;:::a
p
: g for all subsets of the set of labels (labels form a ountable set).
Reord types with dierent sets of labels are ompletely inompatible types, whih makes
theiruniationquite diÆult. Onthe ontrary, reordtypesare introduedwitha symbol
() and builteld by eld withsymbols ( a: ; ),endingwith onstant symbolabs when
there are no more elds to dene. Two reords types with some ommon set of elds, for
instane ( a: ;(b:;) ),and (a: ;abs) an share some struture, namely theskeleton
( a: ; ). The elds of reord types may be dened in any order, and ommutativity
equations are used to re-order elds. Some other kind of equations are also be needed to
expand rows, for instane abs into ( b:abs ;abs), so that the two reord types may be
unied.
Reordtypesarethustypesofan algebratakenmoduloequations. TypeinfereneinML
reduestouniationproblems. Uniationintheemptytheoryiswellknown,butthereisno
generalalgorithm foruniationin anarbitrary equational theory. Forsome theories,there
maynoteven exist suh algorithm,orthealgorithmmay be inherentlyineÆient. Setion1
realls denitions and a few results about equational theories. Sine the basi problem is
rewriting proofs of equality between terms to proofs of a ertain shape, we introdue a
notation of equality relation that allows the manipulation of sets of proofs that share the
same pattern.
Fortunately, there is a lass of equational theories, alled syntati theories, for whih
thereexistsauniationalgorithmquitesimilartothefreeuniationalgorithmofMartelli-
Montanari [MM82℄. There is no known algorithm to deide whether a theory is syntati.
Theusualmethodsforprovingsyntatinessdonotapplyeither. Setion2brieyintrodues
syntatiness, and develops a framework forstudyingsyntatiness properties of equational
syntatiness and isusedinsetion 3 to prove thatthetheory ofreord termsis syntati.
The theory of reord terms is desribed in setion 3. It is shown to be syntati; this
automatiallyprovidesa ompleteuniationsemi-algorithm,and we prove its termination.
Infatreordtermshavemorestruturethanrequiredbytheiruseastypesofreordobjets.
In setion 4 we introdueanonial formsand show thatreord termsan be approximated
by anonial forms. Approximations ommute with uniation. In setion 5 we study an
extension of reordterms withmore struture, thegeneri reordterms, whih are used as
the typesofprojetions inthelanguageProjetive ML [Rem92b ℄.
The mainresults of this artile are theorem 6 in setion 3 and theorem 11 insetion 5,
whihstatesthedeidabilityofuniationinthetheoriesofreordtermsand generireord
terms,respetively. Aseondaryresultistheexisteneofprinipalapproximationsforreord
terms and their ommutation with uniation, stated by theorem 9. The method used for
proving theorem 1 and lemma 35 is also interesting and an probably be reused in other
situations.
1 Equational theories
This setion introdues the main denitions and some known results about uniation in
equational theories.
1.1 Sorted Free Algebras
We are given a set K of atomi sorts, written . Signatures are non-empty tuples of sorts,
written for aone-element signatureor
1 :::
p )
0
for longerones. The integer p (zero
for a one element signature) is the arity of the signature. We are given a set of symbols C
and a mappingS from C to the set ofsignatures. The arityofa symbolf is thearityof its
signature, written%(f). Thesort of asymbolis theright-mostsort of its signature. Finally,
we are given a set of variables V with innitely many variables of every sort (V
)
2K . The
setof termsisthesortedfreealgebraT(V;S). ThemappingS isalso alledthesignatureof
thealgebra. Variablesarewrittenwith theletters,,,andÆ,and termswiththe letters
,,and .
Thesetofvariablesappearingina term iswrittenV(). Weimpliitlyoerea term
into thesetof its variables V() when aset of variables isrequired. Forinstane,two terms
aresaid tobedisjointiftheirsetsofvariablesaredisjoint. The topsymbolofa non-variable
term , written Top(), is the symbol at the empty ourrene in . For any symbol f of
arityp,wewritef(T p
) forthesetofterms whosetopsymbolisf. The sortof atermis the
sort of its topsymbol. Two termsof thesame sorts aresaid homogeneous.
Substitutionsare sort-respeting mappingsof nitedomainsfrom theset of variables to
the set of terms. They naturally extend to mappings from terms to terms by ompatibility
with the struture of algebra. Substitutions are written with the letters , , and . The
domain of a substitution , written dom(), is the set of variables that are not their own
images and the range of , written im(), is (dom()). We say that a set of variables
is disjoint from a substitution if it is disjoint from both the domain and the range of the
substitution. We write j
W forthe restrition of substitution to theset W, and nW
forthe restritionof to thesetV nW.
1.2 Equational theories
It is important to distinguish between the presentation of an equational theory and the
is a set E of homogeneous pairs of terms alled axioms. A ongruene is an equivalene
that is ompatible with the struture of algebra. The E-equality on T generated by the
presentation E, written =
E
,is the smallestongruene ontaining all possiblesubstitutions
oftheaxioms. TheequationaltheoryequationaltheoryT=EisthequotientofT byE. Several
presentationsmaydenethesameequationaltheory(forinstane,ifonepresentationextends
theother witha pairof terms thatan beprovedequal intheequational theorytherst).
We write q for an arbitrary axiom and q l
and q r
for its rst and seond projetion,
respetively. We often assume that presentations are losed under symmetry, and we write
q 1
fortheaxiom (q r
;q l
).
1.3 Equalityrelations
The basi notion in studying equational theories, and in partiular syntatiness, is the
transformationofproofs. Equalityrelationsareaformalwayofmanipulationproofsmathing
aertainpattern. Theorretnessofaprooftransformationanbeformalizedbytheassertion
thatone equality relationisa sub-relationofanother.
We write
=u
for the sub-term of at the ourrene u. We write [=u℄ for the term
obtainedfrom byreplaingthesubtermat theourreneu by. Twoterms and an
be proved equalinonestep ifthere existsanaxiom q,an ourrene u,and asubstitution
suhthat
=u is(q
l
)and
=u is(q
r
). Inthisase,wewrite !. Whenmoreinformation
is needed, we may write !
q=u
. The former relation is symmetri, but the latter is not.
We formalize andextendthisnotation below, sothatit an be rigorouslyusedinproofs.
An equality step equality step is any sub-relation of !. Arbitrary equality steps are
written !
X , !
Y
, and !
Z
. An Equality relation is any omposition of equality steps. They
aresub-relations of=
E
. Arbitraryequalityrelationsarewritten X,Y andZ.
We writefortheidentityrelation. WewriteX Æ
and Æ
!
X
forequalitysteps,theunionof
therelationX withthe identityrelation. The omposition ompositionequalityrelations
oftwoequalityrelationsX andY,writtenXY,relatesanytwoterms and suhthatthere
existsaterm satisfying X ^Y . The union of twoequalityrelations relates anytwo
termsthat an be proved equal byeither oftherelations.
If K is atotally orderedset and (X
k )
k2K
is asequene of equalityrelations equalto the
identityafter some rank N,we write
( X
k )
k2K
and
k 2K
!
X
k
forequalitysteps,
theompositionof all relations taken inthe inreasing order. When X doesnotdepend on
k wewriteX K
(or K
!
X
) forshort. We also write
X
for
[
q2IN X
q
and
!
X
forequalitysteps.
The E-equalityis just
! . For all terms and that are E-equal, there existsa sequene
ofrelations
i2[1;p℄
!
Xi
and asequene of terms(
i )
i2[1;p 1℄
suh that
!
X1
1
::: !
Xi
i
::: !
Xp
p 1
!
Xp
Exhibitingtheserelations andthese terms realizesaproofof =
E
. We saythattheproof
mathes therelation
i2[1;p℄
!
X
i .
Given two equality relations X and Y, we write XY whenever X is a sub-relation of
Y. Being a sub-relation an also be understood as set inlusion, viewing relations as their
graphs, aswe oftendo.
1.4 Paths
Ourrenes are not enough preise. They dene a subterm of a term, but are unable to
tell anything aboutthe symbols enountered on the way from the root to the subterm. A
diretion diretion is a pair (f;x), also written f
x
, of a symbolf and an integer x. A path
path is a nitesequene of diretions. We saythat a pathu equalto (f
i
;x
i )
i2[1;p℄
is a path
in,orthat ontains thepathu,if
1. theourrene (x
i )
i2[1;p℄
is anourrene in,and
2. forall k in[1;p℄, the symbolf p
isat theourrene (x
i )
i2[1;p 1℄
.
Wewrite
=u
forthesubtermof attheourrene(x
i )
i2[1;p℄
. Wewritefortheemptypath.
Two paths are disjoint disjoint ifneither isa prexof theother. Forinstane, thesequene
(f;1)(g;2) is a path, abbreviated as f
1 g
2
. The assoiated ourrene is the sequene 12 of
length2.
Ifq is theaxiom (q l
;q r
)and u isa path, we write !
q=u
fortheequalitystep thatproves
[(q l
)=u℄=
E [(q
r
)=u℄
for any term ontaining u and any substitution . If u is a path and !
q=u
a one step
proof,we geta proof
=u
!
q=
=u
,alledthesub-proofat pathu.
Paths are muh more preise than ourrenes; sometimes they are too preise. An
ourreneu anbeonsideredasthesetofallpathswhoseourrenesareu. Theunionof
two equalitysteps !
q=u
and !
q=v
isanequalitystep. Wewriteit !
q=u[v
. Moregenerally,we
write !
q=U for
[
u2U
!
q=u
when U is a setof paths. Bydefault, U is thesetof all pathsand an be omitted.
Proposition 1 For any disjoint sets of paths U and V, the two equality steps !
U
and !
V
ommute in T, that is
!
U
!
V
= !
V
!
U
The followingnotations helpinmanipulatingsets ofpaths:
- We identifya pathu withthesingletonfug.
- For anysymbol f of non-zero arityp, we writefor f for the set of paths f(f;x)jx2
[1;%(f)℄g.
- For any integer p,we writep fortheset of paths f(f;p)jf 2C^%(f)pg. For large
- We write pathforthepathof length1omposedof theset of alldiretions.
- IfU andV aresetsofpaths,we writeUV fortheonatenationofU and V,omposed
ofall theonatenations of anypathof U withanypathof V.
- We writeU Æ
Æ pathset fortheunion([U).
- If K is a totally ordered set and (U
k )
k2K
is a sequene of path sets equal to after
somerank N,we write(U
k )
k2K
fortheonatenationof allpathsets (distintfrom )
and taken in theinreasing order. When U doesnot dependon k and K is nite, we
writeU K
forshort. We writeU
fortheunion S
k2IN U
k
and1 for(
).
Forinstane,(1) denotestheset of allpaths of lengthstritlygreaterthan one.
The union of the equality steps !
q=u
and !
s=u
is an equality step; it is written !
q[s=u .
That is,axiomsare replaed bysets of axioms: If R is asubset of E,we write !
R=u
forthe
equalitystep
[
q2R
!
q=u
By default, R is E and an be omitted. For example, the expression
!
k
1 Æ
!
relates any
two terms that are provably equal with any number of steps at a path of length at least k
followed eventuallybyone stepat the emptypath.
The expression !
Æ
!
1
!
21
relates anytwo terms that are provablyequal withone step
at theemptypath followed byany numberof stepsat non-emptypaths and one step inthe
seond diretsubterm.
1.5 Restrition of equality relations
In the following, we will be interested in transforming proofs inside a subset of T. This is
formalizedbyrestritionof equalityrelations. Therestrition of the equality step restrition
equality step !
X
to a subset H of T, noted !
Xj
H
is the relation !
X
\H 2
in H. The
restrition of the equality relation restrition equality relation X to a subset H of T, noted
X j
H, is the equality relation X \
!
j
H
in H; it always relates terms that an be proved
equalinH. IfH isasubsetof T,if and areinT,and ifall auxiliarytermsareinH,we
saythatthe proof isa proof in Hproof inH.
TherestritiontoasetoftermsHthatisnotlosedunderE-equalitymightbedangerous,
in the sense that ertain obvious properties in T might nothold in H. The reason is that
restritionof anequalityrelationaswe deneditis nottherestritionof therelationinthe
usualmeaning. If theset H islosed underE-equality,thenthetwo notions oinide.
Denition 1 A subsetH ofT islosed losedifitontains allits subtermsand satises
8;2H; 8u2dom(); (
=u
!)=)[=u℄2H:
Intherest of theartile, we onlyallowtherestrition ofrelations by losedsubsetsof T.
ThisdoesnotimplythatH islosedbyE-equality(if isnotinH,then[
=u
℄maynot
be inH),but atleast ithastwo interesting properties:
Two stepsat disjointpaths ommute.
These properties arehighlydesirable beforeanyserioussurgeryonproofsan be done.
We writeX
H
Y forX j
HYj
H andwesay thatX is asub-relationof Y in H. The
relation
H
isreexiveand transitive.
1.6 Sorts and equational theories
Sorting terms is a ommon way of restriting the set of admissible terms. The addition of
sorts to anequational theoryan have two eets onuniation:
Sine fewertermsan meet, diÆultases maysometimes disappear.
There are fewer proofs, whih an be either helpful or harmful. In some partiular
ases, all proofsbetweenvalidterms arevalidproofs.
The rst situation is unavoidable, beause sorts are aimed at restriting the set of terms.
It an only make uniation easier. The seond situation may have no eet, if all proofs
betweenhomogeneous termsarestillpermitted.
LetT be aset of terms, S asort signature,and E an equational theory. We noteT jS
the restrition of T bythe signature S. In general, axioms of E may violate thesorts. We
say that an axiom has sort ifbothleft and right handsides of the axiom have sort . We
writeEjS theset ofwell-sortedaxiomsforS.
We are interestingin theomparison of equalityinthe two theories(T j
S)=(Ej
S) and
(T=E)j
S,thatis,theomparisonoftheequalityrelations
!\(T j
S)
2
and
! \(Tj
S)
2
.
In partiular, when these relations are equal, anyuniation algorithm for T=E also solves
uniationin(T jS)=(EjS).
Denition 2 We saythatasignature anda presentationE areompatible ompatibleif,
forall axiomsq andall sorts,
`q l
:: () `q r
:::
Proposition 2 If the presentation E is regular and ompatible with the signature , then
the algebras (T=E)jand (T j)=(Ej) are isomorphi.
Proof: We show that
!\(T j
)
2
and
! \(T j
)
2
areequal. That is, any proof in
T of equalitybetweentwo terms inT j
hasall intermediate subtermsinT j
, whih isa
straight-forwardonsequeneof theproperty
8 2T j
; 82T; !=) 2T j
For some axiom q and some ourrene u, =u mathes q l
, that is, there exists some sub-
stitution suh that
=u
is equal to (q l
). Sine is in T j
, both q l
and the restrition
of substitution to V(q l
) are well sorted. The restrition of to V(q r
) is idential to its
restrition to V(q l
) beause thetheory isregular. Beause ofompatibility,q r
hasthe same
sort asq l
. Thus[(q r
)=u℄, thatis, iswellsorted.
The propertyisoften usedinone of thefollowingtwo ases:
The presentationE iswell-sorted.
The signatureremovessymbols inaway thatisompatible withE.
2 Syntati theories
Syntati theorieswereintroduedbyC. Kirhner [Kir85℄.
Assumption In therest ofthisartile, we assumethat thetheoryis ollapse free, thatis,
there isno axiomomposed ofa variableon one side.
For anypresentation E and any symbols f and g of respetive arities p and q, we write
E(f;g) thesetE\f(T p
)g(T q
) ofaxiomswhose topsymbolsare f and g,respetively.
Denition 3 Apairofsymbols(f;g)issyntatiforthepresentationEif,forallequalpairs
of terms of f(T)g(T), there is a proof of their equality that uses at most one axiom at
theemptypath. A presentationissyntati ifall pairsofsymbols are. A theoryis syntati
syntati if there existsa syntati presentationof thistheorysuh that all sets E(f;g) are
niteforallpairs ofsymbols (f;g).
Fora presentationto besyntati isequivalent to
!
!
1 Æ
!
!
1 :
LetH bealosedsubsetofT. We saythatapresentationissyntati in HsyntatiinH if
!
H
!
1 Æ
!
!
1 :
We writeSynt(H) when thepresentation issyntatiinH.
The presentation ff =
E
g;g =
E
hg is not syntati, sine the pair (f;h) is not (but
the pair (f;g) is). However, thetheory generated bythe presentation is syntati sinethe
addition of the axiom f =
E
h does not modifythe theory and makes all pairs of symbols
syntati. Theemptytheoryandthetheoryff(g())=
E
g()g aresyntati,butthetheory
ff(g()) =
E
f()g is not. Manyexamples an be foundin[Kir85℄ and[KK89℄.
Someinterestingquestions are:
Is apresentationsyntati?
Is atheory syntati?
Howto ndasyntati presentationof asyntatitheory.
Minimalizingtheset of axiomsofa syntatipresentation.
Thedenitionofsyntatitheoriesispurely\syntati,"butasemantiharaterizationwas
laterfoundbyC.KirhnerandF.Klay[KK89 ℄. T.Nipkowshowedthatsomeprooftransfor-
mationsbyrewriting tehniqueswere loselyrelated to syntati presentations [Nip89℄. All
these studies help in understanding the seond problem. A ommon instane of the third
problemistheompletionofapresentationintoone thatissyntati; ithasbeenthoroughly
addressed byC. Kirhner. Our interest isonlytherst problem.
2.1 SuÆient onditions for ommutativity
Proving that a presentation is syntati usually requires some rearrangement of equality
relations. The most frequent one is the ommutation of two equality steps. The suÆient
onditionsveninsetion2.2requireommutativityofonseutiveequalitystepsofaertain
shape. In general, two equality steps at disjoint paths ommute. Here, we study the ase
Lemma 3 Let H be a losed subsetof T. Let q be an axiom suh that there isa variable
appearing exatly one in q r
at the ourrene u and appearing k times in q l
at ourrenes
(u
j )
j2[1;k℄
. Then for any axiom s andany ourrene v,
!
q=
!
s=uv
H
j2[1;k℄
!
s=u
j v
!
q=
:
Proof: A proof mathing !
q=
!
s=uv
isof theform
(q l
) !
q=
(q r
) !
s=uv (q
r
)[=uv℄:
Let be q r
=u
. From theproof
(q r
) !
s=uv (q
r
)[=uv℄;
wean extrat theproofat u,
() !
s=v
()[=v℄;
and applyitto all disjointourrenes(u
j )
j2[1;q℄
of inq l
. Abbreviating()[=v℄by,
(q l
)
j2[1;k℄
!
s=u
j v
(q l
)[=u
j
℄
j2[1;k℄
:
Therighthandsideoftheabove proofisequalto (nfg+(7!))(q l
). Applyingaxiomq
at ourrene gives(nfg+(7!))(q r
), whihis (nfg)(q r
)[=u℄ sineuis theonly
ourrene of inq r
(the linearityondition ofq r
in is needed here). By expansionof ,
thissimpliesinto(q r
)[=uv℄.
Corollary 4 Let H be a losed subset of T. If q is a ollapse-free axiom 1
suh that there
exists one variable appearing exatly onein q r
atthe ourrene u, then for any axiom s,
!
q=
!
s=u1
H
!
s=1
!
q=
Proof: It suÆes to notiethattheourrenes(u
j )
j2[1;q℄
annotbe empty.
Corollary 5 LetHbealosedsubsetofT. Ifthepresentationisollapse-freeandallaxioms
are linear (regular and suh that a variable ours at most one in eah side of axioms) of
depth less or equal ton, then
!
q=
!
s=
n
1
H
!
s=1
!
q=
:
2.2 SuÆient onditions for syntatiness
Lemma 6 Theproperty Synt(H) is equivalent to
!
!
1
!
H
!
1 Æ
!
!
1 :
1
This onditionis importanthere. Thoughit is assumedto be truethroughoutthis setion, it was not
Proof: Theaboveonditionisneeded,sineit isaninstane oftheonditionSynt. We now
assumethe onditionand prove Synt(H),that is,
!
!
1 Æ
!
!
1 :
Theequalityrelation
! an bedeomposed into
[
k2IN
!
1
!
!
1
k
:
Theinlusion
!
1
!
!
1
k
!
1 Æ
!
!
1
isshown forall k byan easy indutionon k.
Proposition 7 A suÆient ondition for syntatiness in H is
^ 8
>
>
<
>
>
:
!
!
H
!
1 Æ
!
!
1
;
!
!
1
H
!
1 Æ
!
:
Thisonditionwasnamed-onuenebyClaudeKirhnerand provedin[Kir85℄. Theproof
isvery simple.
Proof: Underthe givenassumptions, theinlusion
!
k
!
1
!
H
!
1 Æ
!
!
1
forall k is easilyshownbyindutiononk. By takingthe unionoverall integers, we get
[
k2IN
!
k
!
1
!
H
!
1 Æ
!
!
1
That is,
!
!
1
!
H
!
1 Æ
!
!
1
We onludebythelemma 6.
Thispropositionisomposedoftwoonditions. Therstisusuallyhekedforallpossible
overings of axioms. The seond is ommutativity, and might be dedued from lemma 3.
However, the lemma only applies if axioms are of depth at most one. For instane, if one
member ofan axiom is ofdepth two,ommutativity might notholdwhen one ourrene is
prex of the other. If axioms are ollapse-free, linear, and of depth at most two, then the
ommutation
!
!
1
!
1 Æ
!
holds. Theorem1 belowgeneralizesproposition7 to thisase.
Remark 1 For any inreasing sequene(H
n )
n2IN
of losed subsets of T,
(8n2IN; X
H
n
Y) implies X
H
Y where H=
[
n2IN H
n
In partiular this applies tothe property Synt.
Denition 4 LetH bea losedsubsetof T. An ordering<isompatiblewiththeequality
relationon H if,
foranyterm inH and anysubterm of we have <,
forall terms ,, 0
and 0
inH,we have
Æ
! 0
^ Æ
! 0
^ <
=) 0
<
0
:
AnequationaltheoryisstritifatermisneverE-equaltoone ofits subterms. Ifthere exists
aompatibleordering,thetheoryisneessarilystrit. Thelastonditionisinfatequivalent
to
( =
E
0
^=
E
0
)=)( < ,;<
0
)
In thefollowing,we willalways deneompatibleorderingsbythemeansof afuntionfrom
terms to an ordered set, namely IN; these funtions will always be onstant on E-equality
lasses.
Theorem 1 LetH bea losedsubsetofT withawellfounded ompatible ordering,andsuh
that
!
!
1
H
!
1 Æ
!
(h
1 )
!
Æ
!
k
k2D
!
H
!
1 Æ
!
!
1
(h
2 )
Then Synt(H).
Proof: Forany integer n,let H
n
be thesubsetofH omposed ofall termsthat do notstart
any dereasing sequene of length greater than n. All these sets are losed under !
j
H
. In
partiular, they are losed subsets of T, so properties (h
1
) and (h
2
) are validin any (H
n ).
Any termsmaller thana term inH
n+1
is inH
n
. The sequene is inreasing and its limitis
H,thusSynt(H)holdsifSynt(H
n
) holdsforanyn. We show Synt(H
n
) byindutionon n;
infat, bylemma 6,itis enoughto show that !
!
1
!
Hn
!
1 Æ
!
!
1
holds.
The set H
0
is omposed of variables and onstant symbols. Thus, the only instane of
thepremise is !
!
,forwhih theinlusionissatisedbythehypothesis (h
2 ).
Let us assume the property Synt(H
n
) and prove Synt(H
n+1
). Let D be the set of all
diretions. A relation
!
1 inH
n+1
an bewritten astheomposition
!
k1
k2D
sine disjoint ourrenes ommute. For eah diretion k in D, the subproof at k is in H
n .
Sine Synt(H
n
),it an be rewritteninH
n
so thatitmathes
!
1 Æ
!
!
1 :
Re-assembling allsubproofs, we geta proofmathing
! Æ
!
!
; k2D
whih isa proofinH
n+1
. Itan be reorderedas
!
k1
k2D
Æ
!
k
k2D
!
k1
: k2D
We have shownthat
!
1
H
n+1
!
k1
k2D
Æ
!
k
k2D
!
k1
: k2D
That is,
!
1
Hn+1
!
1
Æ
!
k
k2D
!
1
:
Composingthestep at therooton bothsides,andthenusing(h
1
)and itssymmetriimage,
we get
!
!
1
!
H
n+1
!
1 Æ
!
Æ
!
k
k2D
Æ
!
!
1
We onludebya simpleaseanalysis,using(h
2 ).
Proposition7andtheorem1havetwo onditions. Therstisaommutativityondition,
and in general ould be dedued from orollary 4. The seond has to be proved by hand.
However ifthe numberof axioms is nite, the number of possibleombinations of equality
stepsmathingthepremiseisalsonite. Thusitispossibletostudyeahofthemseparately.
2.3 Example
ThetheoryCgwheretheonlyaxiomisleftommutativityiswellknowntobesyntati. We
givea very shortproof below. The axiom is:
x(yz)=y(xz)
ThesizeoftermsisunhangedbyE-equality,whihalsodenesaompatibleorderingonT.
Theonditionh
1
issatisedsinetheaxiomislinearandtheourreneofnon-variableterms
isat most1 (orollary5). Twosuessiveappliationsof theaxiom attheemptyourrene
annihilate eah other. Sine !
!
1
!
21
!
, theonlyremaining ase to onsiderinorder to
show (h
2 ) is !
!
2
!
,whih is equalto !
2
!
!
2
. The proof shema forthis relationand its
redutionisshown bythe diagrambelow (anyyleis asubset oftheidentityrelation).
((Æ)) 2
-
((Æ))
R
((Æ)) ((Æ))
I
2
2
((Æ))
((Æ))
2.4 Uniation in equational theories
Inthissetionwedesribehowuniationanbesolvedinsyntatitheories. Theproblemof
uniationis,givenasetofterms,tondamostgeneralsubstitutionthatidentiesallterms
of the set. In fat, it is simpler to manipulate multi-sets of terms, alled multi-equations.
Sine the satisability of a multi-equation is often redued to the satisability of several
multi-equations, it is also onvenient to generalize uniation problems to onjuntions of
multi-equations alleduniands.
Uniands are either multi-equations or onjuntion or disjuntion of uniands. They
arewrittenwithlettersU andV. ConjuntionanddisjuntionofuniandsarewrittenU^V
and U _V, respetively. The set of solutions of a onjuntion (respetively disjuntion)of
uniands is the intersetion (respetively union)of the sets of solutions of the uniands.
Thus it is possible to onsider uniands equal modulo assoiativity and ommutativity of
^ and _ and modulo distributivityof one over the other. Then uniands an always be
written asdisjuntionsof onjuntionsof multi-equations.
It is also very onvenient to restrit the set of solutions of a uniand U by some set of
variablesW. We write9W U fortheuniandomposedof these restritions. The9 ats
as a binder, and we onsider uniands equal modulo renaming of variables bound by 9's,
exhangeofonseutive9's,andremovalofvauous9's. Itisonvenienttoaddauniand?
that hasno solutionand whih isused to representfailure. Uniandswererst introdued
by C Kirhner [Kir85℄ and existential uniands were used later by J.-P. Jouannaud and
C. Kirhner[KJ90 ℄. A more abstrat presentationof uniandsan befoundin[Rem92b℄.
A omplete set of uniers for a uniand U is a set S of solutions of U suh that any
other solution is an instane of at least one solution of S. An equational theory is unitary
unifying if any solvable onjuntion of multi-equations admits a omplete set of solutions
omposed of aunique substitution. A general methodfor ndingompleteset ofuniers of
a uniandU isto transformU intoasimpleruniandthathasexatlythesame solutions.
Thus,solvingauniationproblemisdonebybuildingahainofequivalentuniands,eah
beingobtained byrewritingthe preedingone with avery simplerule.
Uniationintheemptytheorymaybedesribedbytherulesof gure1. Fusionmerges
=_ e^ =_ e 0
---
g
=_ e=_ e 0
(Fuse)
f(
1
;:::
p
)=_ f(
1
;:::
p )=_ e
---
g
1 _
=
1
^:::
p _
=
p
^f(
1
;:::
p )=_ e
(Deompose)
f(
1
;:::
p
)=_ g(
1
;:::
q )=_ e
---
g
?
(Fail) iff 6=g,
(7!)(e)
---
g
9 (e^=_ )
(Generalize) if2V(e)nenV()^ 2= V,
Figure 1: Rulesforuniationinthe emptytheory
twomulti-equationsthatshareaommontermvariableintoasinglemulti-equation. Collision
redues a multi-equation that ontains two terms with dierent top symbols to the empty
uniand ?. Deomposition splits a multi-equation that ontains two non-variable terms
with the same top symbol into a theonjuntion of multi-equations omposed of equations
between the orresponding subterms. Generalization replaes a non-empty ourrene of a
usedto redue theheight of terms ina uniandand prevent dupliation of terms byother
rules. For instane, if the right terms premise in rule Deompose were not variables, the
onlusionwoulddupliateterms,whihouldpreventtermination. Itwouldbealsopossible
to fator rules Deompose and Generalize into a single rule that would not requireany
termofthepremise tobesmall. Below, we useanunrestritedform of generalizationwhere
maybe a variable, alledU-Generalize.
The four rules above applied in any order redue any system of multi-equation to a
ompletely deomposed one. A ompletely deomposed uniand is one for whih no multi-
equation has more thanone non-variable term. An equational theory is stritif a terman
never be a sub-term of an E-equal term. In a strit theory, it is immediate to write an
algorithmthattellswhetheraompletelydeomposeduniandissolvable,andthatreturns
a prinipalunierifone exists. See[Rem92b ℄ formore detailsor[Kir85, Rem90℄ foramore
thoroughbutslightlydierent presentation.
In equationaltheories, deompositiononlyresfor some pairsof symbols,alleddeom-
posablesymbols. Collisionresonlywhenthetopsymbolsareinompatible. Tobeomplete,
there mustbe other transformations,alled mutations, thattogether withpreviousrules re-
dueanyuniandintoaompletelydeomposeduniand. Mutationmaynotexistifthere
isnoompletesetofrulesthatan beaddedtofusionanddeompositionandthatterminate
on anyinputwith a ompletelydeomposedsystem. Mutation oftenintrodues disjuntion
ofuniands.
Syntati theories have a very simple mutation that, moreover, an be automatially
deduedfrom asyntati presentationofthetheory. Multi-equationsan alwaysberedued
bylookingat thetopsymbolofterms,whihleadsto eÆient algorithmsthat aresimilarto
theMartelli-Montanariuniationalgorithm intheemptytheory [MM82℄.
Mutation in syntati theories
In syntati theories, the mutation is a generalization of deompositionand is derived from
theform oftheaxioms.
Denition 5 LetE beasyntatitheory. Let andbetwonon-variableterms. Wedene
deomposition of theequation =_ to bethe followingsystem,written De( =_ ):
^
i2[1;p℄
=i _
=
=i
We denegeneralization of theequation =_ to bethedisjuntion ofsystems
_
q2E(f;g) 0
9V(q)
^ 8
<
:
i _
=q l
=i
i2[1;p℄
i _
=q r
=j
j2[1;q℄
1
A
written Gen( =_ ), where the axioms of E(f;g) have been renamed so that they do not
share any variable with theterms and . We dene mutationof theequation =_ to be
thedisjuntionof systems
_ (
Gen(=_ )_De( =_ ) ifTop()=Top()
Gen(=_ ) otherwise
Thissystemis writtenMut( =_ ).
Theorem 2 If E is a syntati presentation and and aretwo nonvariable terms,then
=_
-
---
g
Mut( =_ )
Proof: The following is proved is [Kir85℄. We rst show that the redution is orret. Let
and be two terms and a solution of the equation =_ . We show that satises
Mut( =_ ). We usethefollowingremark
8; 2T;
!
1
=)
^ (
Top()=Top()
8i2[1; %(Top())℄;
=i
=
E
=i
Sine thetheory issyntati, there existsaproofof theform
!
1
0 Æ
!
0
!
1 :
If there isno stepat theempty ourrene, thenthetopsymbols of and must be equal,
and thesystemDe( =_ )issatisedby. Ifone axiomqisusedat theemptyourrene,
it must be in E(Top( 0
);Top( 0
)), and there must be a substitution of domain V(q) for
whih
0
=(q l
) and
0
=(q r
)
The substitutionjV(q)+ isa solutionofthe system
^ 8
<
:
i _
=q l
=i
i2[1;p℄
i _
=q r
=j
j2[1;q℄
Itfollowsfromtheremarkthatq isinE(Top();Top())andisasolutionofGen( =_ ).
Conversely, let us assume that is a solution of Mut( =_ ). If it is a solution of
Gen( =_ ),then there isan axiom q of E(Top();Top()) anda substitution suhthat
thesubstitution jV(q)+ is asolutionof thesystem
^ (
i _
=q l
=i
i2[1;p℄
i _
=q r
=j
j 2[1;q℄
By omposingthe proofsof theseequalities we get
(jV(q)+)()
!(jV(q)+)(q l
)
(jV(q)+)()
!(jV(q)+)(q r
)
whihsimpliesto
()
!(q l
) and ()
! (q r
)
Thus ()
! (). The ase where the top symbols are equal and is a solution of
De( =_ ) isimmediate.
Togetanalgorithmforsolvinguniation,theexisteneofmutationisnotsuÆient;the
terminationof mutationtogether withthe otherrulesmustalso beproved.
Remark 2 The presentation of left ommutativity in the previous setion is syntati, but
the orresponding mutation does not provide a uniation algorithm sinethe mutationitself
might not terminate. A solution is proposed in [Kir85 ℄.
3 Reord terms
Reord terms, usedas types of reordobjets, enable a naturalextension of funtional lan-
guages with reords. Reords are produts of variable size with labeled omponents. The
keyideaisthattypesmustreetthestrutureofvaluesandthereforereordtypesmustbe
produts ofdierent sizeswithnamed omponents. Werst studya simpliationofreord
termsobtainedbyforgettinglabelsandaessingomponentsbypositioninsteadofbyname:
these struturesare innitarytuples.
3.1 Innitary tuples
LetC bea set ofsymbols givenwith theirarities(C
n )
n2IN
. LetK be omposed of
asort Type and
aountable olletion of sorts(Row(n))
n2IN .
Letbe thesignatureomposedof thefollowingsymbols,given withtheirsorts:
`::Row(0))Type
`f
::
%(f)
) f 2C;2K
`
n
::TypeRow(n+1))Row(n) n2IN
LetE be theset ofaxioms
f
Row(n)
(
1
n
1
;:::
p
n
p )=f
Type
(
1
;:::
p )
n
f
Row(n+1)(
1
;:::
p )
(f .n)
Allaxiomsareollapse-free, regularand linear.
LetV be adenumerableset ofvariableswith innitelymanyvariables ofevery sort.
Denition 6 The algebraof innitarytuples istheequational theoryT(;V)=E.
The followingtwo innitarytuples areE-equal
j
0
f Type
g Row(1)
j j
j
1
j
0
f Type
1
j
j
g
Type
g Row(1)
j j
j
Theorem 3 The presentation E issyntati.
Proof: Lemma 7 is not suÆient beause the ommutativity ondition is not satised; for
instanethe proof
f Type
(
i )
I
n
f
Row(n)
(
i )
I
n+1
(
i )
I
2
R
f
Row(n+1)
i
n
(
i
n+1
i )
f Type
(
i )
n
f Type
(
i )
n+1
f
Row(n+1)
(
i )
where indexing expression
i2I
is written
I
for short, annot start with a step at the empty
ourrene.
Of ourse, this proof is subsumed by the proof below for reord terms. In partiular,
theorem1anbeused,leadingtoashorterproof,butitwouldrequireontrollingtermswith
an ordering (asinthenext setion). Infatthere would beno instane oftherelation
!
Æ
!
k
k2IN
!
We give adiretproof. Infatweshowthat
!
n
!
1
!
n
!
1
byindutionon n. We willusethe followingremarks,whih areimmediateonsequenes of
theform of theaxioms.
Twosuessivestepsattheemptyourrenemustbeinverseandtheyannihilateeah
other. This solvestheinitial ase(n iszero).
Two appliations of axiomsat disjoint ourrenes, orat ourrenes suh that one is
prexof theother butat leasttoo diretionsshorter,ommute.
A proof betweentwo termswiththe sametop symbolannothave exatlyone step at
theemptyourrene.
Let usassumethat thepropertyistrue fornand onsideraproof mathing
!
n+1
!
1
!
Weonsiderthesubproofof n+1
!
1
at a diretioni.
If it does not start or end with an appliation of an axiom at the empty ourrene,
then thisequality step ommutes with one of the equalitysteps at the empty ourrene in
the original proof. Thus the original proof is of the form !
n
!
1
!
1
!
1
, and by indution
hypothesis itis also oftheform n
!
1 1
!
1 .
Otherwise,the subproofat ourrene ihas at least two stepsat theempty ourrene;
thusit mathes
!
p
!
1
!
q
!
1
for some p and q whose sum is stritly smaller than n. By the indution hypothesis, this
relationis asub-relation of
p
!
1
!
q
!
1
Re-omposingthiswith theoriginalproof,the problemredues to previousase.
Themutation fortheinnitarytuplealgebra:
f
Row(n)
(
i )
i2[1;p℄
_
=( n
)=_ e
---
g
9(
i
;
i )
i2[1;p℄
V
8
>
>
>
>
>
<
>
>
>
>
>
:
(
n
)=_ e
=_ f Type
(
i )
i2[1;p℄
=_ f
Row(n+1)
(
i )
i2[1;p℄
i _
=
i
n
i
for i2[1;p℄
Mutate
Forallother pairsofterms (;),iftheyhaveidentialtopsymbols,theyaredeomposable,
Theorem 4 Uniation in the innitary tuple algebra isdeidable andunitary unifying.
Proof: Thetheoryisstrit (we anndaompatibleorderingaswe willdo belowforreord
terms). Therefore, therulesof mutation, deomposition,ollision, fusionand generalization
appliedanyorderformaompletesemi-algorithmforuniation. Itisunitarysinemutation
doesnotintrodueanydisjuntion. It remainsto prove termination.
LetT n
bethesubsetsofT restritedtothesortsTypeandRow(k)forksmallerorequal
to n. Generalized deompositionsand fusion arestable on the sets T n
,and fora system of
uniandsthey derease inthefollowinglexiographi ordering:
thenumberof symbols f
Row(n)
inthelexiographi order of inreasingn,
thenumberof all other symbols,
thesum ofheightsof termsof theuniand,
thenumberof multi-equations.
Thisguarantees theterminationof therewrittingproess.
Remark 3 Theintrodution of an inniteolletion of opies of the original set of symbols
C mightbeonsidered luxurious,while two opies Type and Row would seemsuÆient. The
main symbol would havesignature TypeRow )Row. Theaxioms would be
f Row
(
1
n
1
;:::
p
n
p )=f
Type
(
1
;:::
p )f
Row(1;:::p)
Butevenifthepresentationremainedsyntati,terminationouldnotbeguaranteedasabove.
Remark 4 We an onsider the set of raw terms, that is, the algebra T 0
built from the all
symbols C extended witha binarysymbol and aunary symbol . Toany term in T there
orresponds araw term obtained from by removingall supersriptsof symbols. Conversely,
for any raw term 0
and any sort , there is at most one term of sort whoseerasure is 0
.
Thisallows us to denea term of T by giving its erasure and its sort.
3.2 Reord terms
Wegeneralizethetheoryofinnitarytuplestothetheoryofreordterms,whereomponents
are named. We desribe the theory and show that it is syntati and that uniation is
deidable.
Thealgebraofreordtermsisdenerelativelyto aolletionofsymbolsgivenwiththeir
arities (C
n )
n2IN
. Let L be a ountable set of labels. Labels are written a, b, and `, nite
subsetof L are written L and K theset of all of them iswritten P
f
(L). We also write a:L
forfag[L.
LetK be theset omposed of
asort Type,and
aniteolletion ofsorts (Row(L)
L2P
f (L)
.
Letbe thesignatureomposedof thefollowingsymbolsgiven withtheirsorts:
`::Row(;))Type
`f
::
%(f)
) f 2C;2K
`(`
L
: ; )::TypeRow(`:L))Row(L) `2L;L2P
f
(Lnf`g)
We dene projetion symbols to be all symbols
` L
: ;
. We write D for the new set of
symbols.
Left ommutativity axioms. For any labels a and b and any nitesubset of labels L
that donotontain them,
a L
:;
b a:L
: ;
=b L
:;
a b:L
:;
(a.b;L)
Distributivityaxioms. Foranysymbolf,anylabel aand anynitesubsetof labels L
that donotontain a,
f
Row(L)
(a L
:
1
;
1
;:::a L
:
p
;
p )=a
L
:f Type
(
1
;:::
p );f
Row(a:L)
(
1
;:::
p )
(f .a;L)
Allaxiomsareollapse-free, regularand linear.
LetV bea denumerablesetof variableswithinnitelymanyvariablesof every sort.
Denition 7 The algebraof reordterms (alsoalled thereordalgebra) is theequational
theory T(;V)=E.
Belowaretwo E-equal reordterms:
j
(a
;
)
f Type
g
Row(fag)
j j
j
(b
fag
)
j
(a
;
)
f Type
(b fag
)
j
j
g
Type
g
Row(fag)
j j
j
Theorem 5 Thepresentation E is syntati.
Proof: LetT n
bethesubsetoftermsthatuseonlythesortsTypeorRow(L),whereCard(L)
isatmostn. Thesequeneofthesesets isinreasingand itsunionisT. Thusitisenoughto
show Synt(T
n
) foranyinteger n. Letnbean integer. We showSynt(T n
) usingtheorem 1.
Let
n
be the usual size (sum of weights of symbols) where symbols are weighted as
follows. Symbols f
Row(L)
of arityq have a weigh of 2(n CardL)+q. Symbols f Type
weigh their arity q augmented by 1, and all other symbols weight 1. The size of a term is
stritlylargerthanthesizeof anyof itssubterms; thesizeisonstant on E-equalitylasses.
Thusitdenes a ompatibleordering inT n
by < if
n
()<
n ().
The ondition (h
1
) is always satised: left ommutativity axioms are of depth greater
than two, and soare distributivityaxioms forsymbols of non zero arity. Left distributivity
axiomsforonstant symbols f aresuhthat theequalityrelations !
f.a;L=
!
1
areempty.
Theondition(h
2 ) is
!
Æ
!
k
k2D
!
H
!
1 Æ
!
!
1
Weshowitforall instanesof thepremise:
!
q=
Æ
!
s =k
!
k2D
!
t=
We writeZ forthe intermediate relation
Æ
!
s
k
=k
!
k2D
Case Z is empty: Theaxiomsq and tmustbeinverseand annihilateeah other,thatis,
theequalityrelationis inludedintheidentityrelation.
Caseq is (f.a;L): Iff were ofarityzero,S wouldbeempty(rstase). Theourrene
1 insis notpossible, and s
2
must beanother axiom(f .b;a:L), where b isdistint from a.
Then tmustbe theaxiom (a.b;L). We onludewith:
!
f.a;L=
!
f.b;a:L =2
!
a.b;L =
i2[1;%(f)℄
!
a.b;L=i
!
f.b;L=
!
f.a;b:L =2
Case q is (a.f;L): Then t must be (f .b;L). If a and b were equal, Z would be the
identity (rst ase). At least one appliation of an axiom (a.b;L ) at eah ourrene i
between1 and thearity off isneeded to hange thesymbols (a L
: ; ) into (b L
: ; ). We
onludewith:
!
a.f;L=
i2[1;%(f)℄
!
a.b;L=i
!
f.b;L =
!
f .b;L=2
!
a.b;L=
!
a.f;L=2
Caseq is (a.b;L): Iftisa distributivityaxiom,thenbysymmetrywefallintoone ofthe
preeding ase; otherwise it is an axiom (.b;L ). Sine 1 is a variable ourrene of q,the
rule !
s1;1
ommutes withq, and we ignore thisase. If and a were equal, the sequene Z
wouldbe theidentity(rst ase). So tmustbe theaxiom (a.;b:L ). We onludewith:
!
a.b;L =
!
a.;b:L=2
!
b.;L =
!
b.;a:L =2
!
a.;L =
!
a.b;:L =2
Notethat thetwo rst inlusionsan be dedued from thefollowingyle (anyomposition
ofsixof these rulesis asubset oftheidentityrelation):
a.b;L;
-
f .b;a:L;2
a.f;b:L;2
R
I
f .a;L ;
b.f;L;
i2[1;%(f)℄
The lastinlusionruleformstheyle:
a.;b:L ;2
-
a.b;L;
b.;L;
R
I
.b;a:L;2
b.a;:L ;2
i2[1;%(f)℄
.a;L ;
Sine the theory is syntati, we automatially derive the mutation rule in the reord
termalgebra:
f
Row(L)
(
i )
i2[1;p℄
_
=a L
:; =_ e
---
g
9(
i
;
i )
i2[1;p℄
V
8
>
>
>
>
>
>
<
>
>
>
>
>
>
: a
L
:;=_ e
=_ f Type
(
i )
i2[1;p℄
=_ f
Row(a:L)
(
i )
i2[1;p℄
i _
=a L
:
i
;
i
for i2[1;p℄
Mutate(a.f)
a L
: ;=_ b L
:; =_ e
---
g
9 V
8
>
>
<
>
>
: b
L
:; =_ e
=_ b a:L
:;
=_ a b:L
: ;
Mutate(a.b)
Theorem 6 Uniation in the reord algebra is deidable and unitary unifying.
Proof: The theory is strit (we exhibited a ompatible ordering). Therefore, the rules for
mutation, deomposition, ollision, fusion and generalization applied any order a omplete
semi-algorithm foruniation. The algorithm is unitary sine mutation doesnot introdue
anydisjuntion. Itremainsto prove termination.
Alltransformationsarestable inthesets T n
and dereasein thefollowinglexiographi
ordering:
thenumberofsymbolsf
Row(L)
inthelexiographiorderofdereasingCard(L)(that
is,biggersets ount less: mutate (a.f) ),
the number of symbols a L
: ; ounted in the lexiographi order of dereasing
Card(L) (mutate (a.b)),
thenumberof othersymbols (othermutations and deomposition),
thesum of heights ofterms (generalization),
thenumberof multi-equations(fusion).
This guarantees theterminationof theproess.
3.3 Raw terms
Let C 0
be the set of symbols C extended with a symbol and the olletion of symbols
(a: ; )
a2L
. Terms of the algebra T(C 0
;V) are alled raw terms. To any reord term, we
assoiate the raw termobtained by erasing all supersripts of symbols. Conversely, forany
raw term 0
and anysort , there is at most one reord termwhose erasure is 0
. Thusany
reordterm ofsortisompletelydenedbyitserasure 0
andthesort. Intherestofthe
paperwe willmostly use this notation and often drop thesort whenever it is impliit from
theontext.
Projetion symbols assoiate to the right; that is, (a: ;b: ;) stands for (a : ;
b: ;). In formulaswesometimes write
(a
i :
i )
i2[1;p℄
;
for(a
1 :
1
;:::a
p :
p
;).
3.4 Examples of Reord terms
When reord terms are used as types of reords in ML, the types of elds must rst say
whethertheeldisabsent orpresentandinthelastasewhetheritisanarrowtypeorsome
other struturedtype. Forinstane, a type ould be !( a:pre(!);). However,
typesthatwouldtelltheirstruturebeforetellingthattheeldisdenedmustbeforbidden:
!a:!; is shouldnotbe a orrettype. These onstrainsare, ofourse, realized
usingsorts. Thepropertiesofthesetion1allowreordtermstoberestritedbyasignature
ompatiblewith its equations,and stillusethe same uniationalgorithm.
We give two examplesof restrited reordterms usedas typesin MLwith reords. The
rstinstanedistinguishesaonstantsymbolabs andaunarysymbolpre inC. Thesignature
0
on thetwo sortstype and eld is:
0
`::eld )type
0
`abs
::eld 2K
0
`pre ::type )eld
0
`f Type
::type
%(f)
)type f 2Cnfabs;preg
0
`(`
L
: ; )::eld eld )eld `2L;L2P
f
(Lnf`g)
The signature 0
is ompatible with the equations of the reordalgebra. We dene simple
reord terms as reord terms that are well sorted for 0
. They have a very simple reord
struture. TermsofthesortRow(L)areeitherofdepth0(reduedtoavariableorasymbol)
orareof theform (a: ;). By indution,they arealways ofthe form
(a
1 :
1
;:::a
p :
p
;)
where iseitherabs oravariable,inludingtheasewherepiszeroandthetermisredued
to .
The generalityof reord termalgebras is better justied byomplex reords terms. The
problemwith simplereord terms is the inabilityto merge two reords dened on dierent
elds. Forinstane, the two reordtypes ( a:pre();b:pre();abs) and (a :pre();
abs) annot be unied, sineon eld b thiswould require pre() be uniable withabs. A
solutionis to separate the aess information from the struture informationinelds. The
two reords ould be typed with (a:pre:;b:pre:;abs:) and (a:pre: ;abs:).
They do not yet unify. But if we write instead (a:
a
:;b:
b
:;abs:) and
( a: 0
a
: ;abs: 0
),thenthey areuniedbythesubstitution:
a 7!
0
a
7!
b
7!abs
0
7!b:
b
;
Generi reord terms are well sorted reords terms for the following signature 00
. Distin-
00
is denedon thethree sortstype,ag, andeld by:
00
`::eld )type
00
`abs
::ag 2K
00
`pre
::ag 2K
00
`:
::ag type )eld 2K
00
`f Type
::type
%(f)
)type f 2Cnfabs;pre;:g
00
`(`
L
: ; )::eld eld )eld `2L;L2P
f
(Lnf`g)
Thesignatureisstillompatiblewiththeequations. TermsofthesortRow(L)annowhave
a more omplexstruturesuh as
(a: ;):(b: ; 0
)
If aand bwere equal,thiswouldsimplifyinto
(a::;: 0
)
Wesaythatthelatterisaanonialformbuttheformerisnot. Inthenextsetionwestudy
anonial formsof reordterms ingeneral.
4 Approximations of terms
The omplexreordtype (a:pre: ;) an intuitivelybeunderstoodasthetypeof some
reordwhoseeldaispresentwithtype andwhosepreseneofother eldsisdenedby.
However, it is harderto understand the objets that would have the reordtype equal to
( a:pre: ;(b:pre ;):). Substituting by(b: 0
; 00
) wouldleadtotheE-equalreord
type (a:pre: ;b:pre: 0
;: 00
),whih is lessgeneral but has a more intuitive meaning.
The substitution 7! ( b: 0
; 00
) doesnot impose anymore struture on the type of . It
just\reads"informationform inthesensethatanynon-variableinstaneof isneessarily
an instane of(b: 0
; 00
).
Canonialtermsarereord typesinwhiha symbol(a: ; ) an onlyour belowsome
other symbol but (b: ; ) or the symbol , and E-anonial terms are those that are E-
equaltoanonialterms. TherearetermsthatarenotE-anonial. Forinstane,theterm
aboveis not. We rst denealassof \reversible"substitutionsalledexpansions. Then we
showthatanytermanbetransformedbyexpansioninto atermthatisE-anonial. There
exist least E-anonial expansions; however, expansions do not ommute with uniation.
Allowingthereverseofexpansions,alledontrations, leadstoE-anonialapproximations,
whihommute withuniation.
4.1 Expansions
Denition 8 An elementarysubstitution of W is asubstitutionof thefollowingform:
7!a: ; isan elementary expansion ofW if is inW and and arenot inW.
7! isan elementary renaming ofW if is inW and is outsideof W.
7! isan elementary fusionof W if and areinW.
7!f(
i )
i2[1;p℄
isan elementary struturation of W if isinW and
i
are alloutside
A perfet omposition of W is any omposition
1 Æ:::
p
suh that there existsa sequene
(W
i )
i2[0;p℄
of sets of variablessatisfying:
1. W
0
=W;
2.
i
isan elementarysubstitutionof W
i
;
3. W
i
isequalto V((W
i 1 )).
Anexpansionisaperfetompositionofelementaryexpansions. An-expansionisaperfet
ompositionof elementary expansionsand renamings.
Notation
We writeexpansionswithletters', ,and . Weindiateelementarysubstitutionsbya\^"
aent: ',^ .^ The notation
:V -
T
isnotwelladaptedto desribe perfet ompositions. We write
V
-
W
fora perfet omposition of V suh that W is theset of variablesof theimage of V. We
an ompose them asfollows:
V
-
W
-
W 0
We also drawdiagrams with theonvention thatontinuous linesare universally quantied
whiledashedlines areexistentiallyquantied. Forinstane
V
-
W
j
j
'
j
?
?
W 0
-
:
isread\For any substitution from V to W and any expansion fromV to W 0
, there exista
substitution of W 0
and an expansion of W suh that Æ' and Æ are E-equal." All
diagramsommutes moduloE-equality,exept ifexpliitlymentionedotherwise.
Lemma8 Any substitution whose domain is in W an be written as a perfet omposition
of elementary substitutions of W.
Proof: Thelemmaisrstshownforthesubstitutionofavariablebyaterm,byindutionon
thesizeof theterm. The general aseis thenshownbyindutionon thesizeof thedomain
ofthe substitution.
Lemma9 A substitution is an expansionof W if and onlyif:
all symbols of the image of are projetion symbols;
all variables of the image of are outside of W; and
all terms of (W) arelinear (a variable does notour twie) and disjoint (no variable
Conretely,anexpansion 'issum
2dom(') ('
)where '
are
7!a
1 :
1
;:::a
p :
p
;
and expansions '
arepairwisedisjoint.
Proof: Any suh substitutionistrivially anexpansion. Conversely,the set ofsuhsubstitu-
tions ontains elementary expansions and is losed by omposition with elementary expan-
sions.
Remark 5 The set of expansions is losed by E-equality. Proving the E-equality of two
expansions an always be done using left ommutativity axioms only.
Lemma 10 If is a renaming of W and ' is an expansion of (W), then there exists an
expansion of W andarenamingof (W)suhthat Æ'andÆ areequal,andonversely,
inverting the rolesof renamings and expansions.
W
-
:
j
j
?
j
j
? '
:
-
:
W
-
:
j
j
'
j
j
?
?
:
-
:
Proof: Fortherst diagram,therenamingan bedeomposedintothesumof tworenam-
ings 0
equalto jW 0
and 00
equalto nW 0
whereW 0
is 1
(dom(')). Take 00
+! 1
for,
and!Æ'Æ 0
for where! renamesvariablesofim(') awayfromallother variableinvolved.
Fortheseonddiagram,therenaminganbedeomposedintothesumoftworenamings
0
equalto jW 0
and 00
equalto nW 0
,whereW 0
is im('). Take( 0
Æ')+! 1
for and
!Æ 00
for,where ! renames variables ofim(!
00
) away formall other variablesinvolved.
Inbothases, it is easy to prove that is an expansion, and sothediagram ommutes,
asrequired.
Lemma 11 If a perfet omposition of elementary substitutions is an -expansion, then all
elementary substitutions are renamings or expansions.
Proof: Let betheperfet ompositionof W
0 .
W
0
^
1
-
W
1
^
p
-
W
p
If thesequene ontains astruturation 7!f(
i )
i2[1;p℄
,then im() ontainsthesymbolf.
Otherwise it ontains a fusion(7! ), where and are insome W
i
. If and are the
images of distint variables 0
and 0
of W
0
, then the images by of 0
and 0
will notbe
disjoint. Otherwise, and are in the image of a ommon variable 0
and
1 Æ:::
i will
notbe linear. Inall ases, annotbe an-expansion.
Corollary 12 Two substitutions that perfetly ompose into an -expansion are -
expansions.
Lemma 13 ForanysetofvariablesW,anyelementary
substitution ^ of W, and any expansion ' of W, there
existsanexpansion of(W^ )andasubstitution suh
that Æ ^ and Æ' are E-equal on W, that is, the
diagram on the right ommutes modulo E-equality.
W
^
-
:
j
j
'
j
j
?
?
:
-
:
Proof: Itisenoughtoshowthelemmaforsubstitutionswithdisjointimages'(W)and(W^ ).
Thelemma thenfollows by introduingarenamingof theimageof 'outsideof theimage
of ,^ applying the lemma to Æ' instead of ', and replaing the resulting substitution
by Æ 1
. Similarly,theimages an be assumed disjoint from the domains withoutloss of
generality.
We rst show thelemma foranexpansion' oftheform
7!a
1 :
1
;:::a
p :
p
;
0
Ifthedomainof^ isnotreduedto ,thenthetwo substitutionsommute,and is ,^ and
is '. Otherwisewe reasonbyases on :^
If^ is arenaming(7!),then'Æ^ for and theidentityfor.
If ^ is a fusion (7!),then take 7!'() for both and . Otherwisethe image
of^ isoutside ofW.
If ^ is an expansion (7! a
j :
j
;
0
) for j in [1;p
i
℄, take the renaming
j 7!
j for
andthe expansion7!(a
k :
k )
k2K
;
0
whereK is[1;p
i
℄nfjg for .
If ^ is an expansion ( 7! b:
b
;
0
), then take (
0 7! (a
k :
k )
k2[1;p
i
℄
;
0
) for and
theexpansion(
0
7!b:
b
;
0
) for,where
0
isa variable distintfrom all others.
If^ is a struturation(7!f(
j )
j2[1;q℄
), thentake theexpansion
j 7!(a
k :
k )
k2[1;p
i
℄
;
0
j2[1;q℄
for andthestruturation
k
7!f(
k )
i2[1;p℄
k2[0;p
i
℄
for,whereall variables
k
are distintand distintfrom allothers.
Ageneralexpansion'isthedisjointsum
i2[1;p℄
('
i
)ofsimpleexpansions. Ifitisnotdisjoint
from,^ thereexistsoneexpansion('
1
forinstane)thathasthesamedomainas.^ Applying
thelemma with'
1 gives
1
and. Take
1 +
i2[2;p℄
('
i
) for .
Remark 6 If ^ isan expansion, then ^ isan -expansion.
Proposition 14 For any substitution of W and any
expansion 'ofW,thereexistsan expansion of (W)
and a substitution of '(W) suh that Æand Æ'
are E-equal on W, that is, the diagram on the right
ommutes moduloE-equality.
W
-
:
j
j
'
j
j
?
?
:
-
:
Proof: By indutionon the number of elementarysubstitutionsthat ompose , we obtain
thefollowingdiagram:
W
^
1
-
: :
^
n
-
:
j
j
'
0
j
j
?
? '
1
? '
n 1
? '
n
:
1
-
: :
n
-
: