/
Definitional trees Definitional trees

Definitional trees - PDF document

test
test . @test
Follow
378 views
Uploaded On 2017-04-05

Definitional trees - PPT Presentation

Weintroduceahierarchicalstructurecalledde ID: 336170

Weintroduceahierarchicalstructure calledde

Share:

Link:

Embed:

Download Presentation from below link

Download Pdf The PPT/PDF document "Definitional trees" is the property of its rightful owner. Permission is granted to download and print the materials on this web site for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.


Presentation Transcript

AlgebraicandLogicProgramming(ALP'92)Volterra,Italy,Sept.1992,SpringerLNCSVol.632,pages143-157.De¯nitionalTreesSergioAntoy?DepartmentofComputerSciencePortlandStateUniversityPortland,Oregon97207-0751Abstract.Rewritingisacomputationalparadigmthatspeci¯estheactions,butnotthecontrol.Weintroduceahierarchicalstructurerepre-senting,atahighlevelofabstraction,aformofcontrol.Itsapplicationsolvesaspeci¯cproblemarisinginthedesignandimplementationofinherentlysequential,lazy,functionalprogramminglanguagesbasedonrewriting.Forexample,weshowhowtoextendtheexpressivepowerofLog(F)andhowtoimprovethee±ciencyofanimplementationofBA-BEL.Ourframeworkprovidesanotionofdegreeofparallelismofanoperationandshowsthattheelementsofanecessarysetofredexesarerelatedbyanand-orrelation.Bothconcepts¯ndapplicationinparallelimplementationsofrewriting.Inanenvironmentinwhichcomputationscanbeexecutedinparallelweareabletodetectsequentialcomputationsinordertominimizeoverheadsand/oroptimizeexecution.Conversely,weareabletodetectwheninherentlysequentialcomputationscanbeexecutedinparallelwithoutperformingunnecessaryrewrites.1IntroductionandMotivationsRewritesystemsaretheunderlyingmodelofcomputationofanincreasinglylargenumberoffunctional,equational,and/ormulti-paradigmprogramminglanguages.Acomputationintheselanguagesisa¯niteorin¯nitesequencet0;t1;:::oftermsinwhichthetermti+1isobtainedbyrewritingsomesub-termsofti.Rewritesystemsspecifytheactions,butnotthecontrol,thatis,whichredexesofatermshouldberewritten.Thisinformationisembodiedinarewritestrategy.Forthesakeofboththee±ciencyandtheterminationofacomputationwearegenerallyinterestedinparallelstrategies,althoughparallelismisnottheo-reticallynecessaryforweaklyorthogonalrewritesystems,theclassconsideredinthisnote[10].Twoemergingapproachestoe±cientparallelrewritingemphasizerespectively\quantity"and\quality".The¯rstoneattemptstorewritesimulta-neouslyalarge,possiblymaximal,setofredexesofaterm[6,11].Thisapproachhasgreaterpotential,buthasthedrawbackofrequiringspecializedarchitectures.Thesecondapproachisconcernedwiththetrade-o®betweenthegeneralityofaclassofrewritesystemsandthee±ciencyofanormalizingstrategyforsystemsintheclass.Oure®ortbelongstothiscategory[7,8,10,13,20{23].?SupportedbytheNationalScienceFoundationGrantNo.CCR-8908565. Weintroduceahierarchicalstructure,calledde¯nitionaltree,containingrewriterulesandshowsomeofitsapplicationstothecontrolaspectsofarewritestrategy.First,weconsideraclassofsystemswhoserulesarecontainableinasimpli¯ed,non-parallelformofde¯nitionaltrees.Thisclassisinterestinginitsownright,sinceitproperlycontainstherewritesystemsunderlyingbothDF¤[17{19]andanimplementationofBABEL[14{16].Ourresultsextendtheexpressivepowerofthe¯rstandimproveanimplementationofthesecond.Then,weconsideramoregeneral,parallelformofde¯nitionaltreeswhichareabletocontaintherulesofanyweaklyorthogonalrewritesystem.Thesetreescanbeusedforcomputingnecessarysetsofredexes[22],andshowingthatnecessarysetshaveaninternalstructureintheformofanand-orrelationamongtheirelements.Wediscusshowaparallelrewritestrategymaytakeadvantageofthisknowledge.Ourreasoningismadepossiblebythelevelofabstractioncapturedinade¯nitionaltree,whichishigherthanthatofcorrespondingconceptsdiscussedin[22].2PreliminariesandNotationWeconsideratermrewritingsystemRwithamany-sortedsignaturepartitionedintoasetCofconstructorsandasetDof(de¯ned)operations.Foreachsorts,weassumeanarbitrary,but¯xedordering,calledstandard,amongtheconstructorsofs.Xdenotesasetofsortedvariables.Variablesaredenotedbyuppercaselettersor,whenanonymous,bythesymbol\".Foranysignature§,T(§)isthesetoftermsbuiltover§.Anytermreferredtointhisnotetypechecks.Theleadingsymbolorprincipalfunctorofatermtiscalledtherootoft.TheelementsofT(C),T(C[X),andT(C[D)arerespectivelycalledvalues,constructorterms,andgroundterms.Wecallnon-valueanygroundtermdi®erentfromavalue.Atermtoftheformf(x1;:::;xn),wherefisanoperationsymbolandtheargumentsareconstructorterms,iscalledanf-rootedconstructorterm.TherulesinRarecharacterizedbyhavinganoperation-rootedconstructortermastheleftside,thatis,Rfollowstheconstructordiscipline[21].Anoccurrenceisapathidentifyingasubterminaterm.Anoccurrenceisapossiblyemptystringofdot-separatedintegersoroccurrences,i.e.,thesymbol\¢"isoverloaded.Theemptyoccurrenceofatermtisdenotedby¤andidenti¯estitself.Theoccurrencep¢i,forsomeoccurrencepandpositiveintegeri,identi¯esthei-thargumentofthesubtermoftidenti¯edby(at)p.Fortermstandt0,occurrencep,andvariableX,t=pdenotesthesubtermoftatp,andt[pÃt0]denotesoccurrencesubstitution.3SequentialDe¯nitionalTreesInthissectionwede¯neahierarchicalstructure,calledade¯nitionaltree,thatcontainsasetofrewriterules.Weareinterestedinoperations,calledinductivelysequential,whoseentiresetofde¯ningrulescanbestoredinthisstructure.Theclassoftheinductivelysequentialoperationsislimitedandwewilllater144 extendthisclassbyextendingtheconceptofade¯nitionaltree.Inthissectionwealsoprovesomesimplepropertiesofrewritesystems,calledalsoinductivelysequential,whoseoperationsareallinductivelysequential.Ourinterestinthesesystemsismotivatedbythefactthatcomputationsininductivelysequentialsystemscanbeexecutedsequentially,thatis,withoutanyinherentparallelism,andbythefactthattheclassofinductivelysequentialsystemsislargerthanthoseunderlyingcertainfunctionallazyprogramminglanguages.Wewillprovetheseclaimsinfollowingsections.Thesymbolsbranch,rule,andexempt,appearinginthenextde¯nition,areuninterpretedfunctionsusedtoclassifythenodesofthetree.Apatternisanoperation-rootedconstructortermcontainedineachnodeofatree.De¯nition1.Tisapartialde¯nitionaltree,orpdt,ifandonlyifoneofthefollowingcasesholds:T=branch(¿;o;¹T);where¿isapattern,oistheoccurrenceofavariableof¿,thesortof¿=ohasconstructorsc1;:::;ckinstandardordering,¹TisasequenceT1;:::;Tkofpdtssuchthatforalliin1;:::;kthepatternintherootofTiis¿[oÃci(X1;:::;Xn)],wherenisthearityofciandX1;:::;Xnarenewvariables.T=rule(¿;l!r);where¿isapatternandl!risarewriterulesuchthatl´¿.T=exempt(¿);where¿isapattern.De¯nition2.Tisade¯nitionaltreeofanoperationfifandonlyifTisapdtwithf(X1;:::;Xn)asthepatternargument,wherenisthearityoffandX1;:::;Xnarenewvariables.De¯nition3.WecallinductivelysequentialanoperationfofarewritesystemRifandonlyifthereexistsade¯nitionaltreeToffsuchthattherulescontainedinTareallandonlytherulesde¯ningfinR.WecallinductivelysequentialarewritesystemRifandonlyifanyoperationofRisinductivelysequential.Exemptnodesarepresentinatreeofanincompletelyde¯nedoperation.Patternsdonotneedexplicitrepresentationinade¯nitionaltree.However,wewillkeepthemaroundwhentheirpresencesimpli¯esthepresentationofourideas.Forexample,considertherulesde¯ningtheoperations\lessthanorequalto"and\integerdivisionby2"de¯nedonthenaturalnumbers,whoseconstructorsinstandardorderingare0ands.0·!trues()·0!falses(X)·s(Y)!X·Yhalf(0)!0half(s(0))!0half(s(s(X)))!s(half(X))(1)145 Correspondingde¯nitionaltreesare:branch(1;hrule(0·!true);branch(2;hrule(s()·0!false);rule(s(X)·s(Y)!X·Y)ii))branch(1;hrule(half(0)!0);branch(1¢1;hrule(half(s(0))!0);rule(half(s(s(X)))!s(half(X)))ii))(2)Figure1showsthesametreesinpictorialrepresentation.Anoperationmayhavedistinctde¯nitionaltrees.Wedonotaddressthisproblemperse.Inthe¯nalpartofthisnotewewillshowanoperationwithtwo\non-isomorphic"de¯nitionaltreesanddiscusssomeimplicationsofthisfact.X1·X20·X2trues(X3)·X2s(X3)·0falses(X3)·s(X2)X3·X2half(X1)half(0)0half(s(X2))half(s(0))0half(s(s(X3)))s(half(X3))Fig.1.Pictorialrepresentationofthede¯nitionaltreesoftheoperationsde¯nedindisplay(1).Theboldfacedsymbolinthepatternargumentofabranchnodeistherootofthesubtermidenti¯edbytheoccurrenceargument.Theruleargumentofarulenodeisshown\vertically"andthepatternargumentis\merged"withtherule'sleftside.4.Wecallcompleteanoperationfifandonlyifthereexistsade¯nitionaltreeoffwithnoexemptnodes.WecallcompleteaninductivelysequentialrewritesystemRifandonlyifanyoperationofRiscomplete.146 Wenowstatetwosimpleresultsaboutinductivelysequentialrewritesystems.WefollowKlop'sterminology[12]andcallorthogonalaleft-linear,non-overlappingrewritesystem,andweaklyorthogonalaleft-linearsystemwhosecriticalpairsarealltrivial,thatis,ifht;t0iisacriticalpair,thentissyntacticallyequaltot0.Forrelatedconceptsandterminologyseealso[5,8,21].Lemma5.AnyinductivelysequentialrewritesystemRisorthogonal.Lemma6.Ifaninductivelysequentialrewritesystemiscomplete,thenagroundtermisanormalformifandonlyifitisavalue.4SequentialNormalizationInthissectionweusede¯nitionaltreestocomputenormalforms.Weshowhowto¯ndaneededredex[8]inatermandconsequentlyhowtoobtainanormalizingrewritestrategy.Ourmotivationistwofold:(1)weusetheseresultstoextendtheexpressivepowerofsomeinherentlysequential,lazy,functionalprogramminglanguagesbasedonrewritingand/ortoimprovethee±ciencyoftheirimplementationsand(2)weapplytheseresultstotheanalysisofnecessarysetsofredexesusedinaparallelnormalizingstrategyapplicabletoalargerclassofrewritesystems.Thefollowingintuitive,informaldescriptionofourstrategymighthelpun-derstandingtheconsiderabledetailsofitsde¯nition.Ourstrategyisbasedonafunction,¸,whichtakesanon-valuetandreturnsanoccurrenceooft.Thesubtermoftatomustbeeventuallyrewritteninordertorewritettoavalue.Thefunction¸isde¯nedbymeansofanotherfunction,',whichtakesagroundf-rootedtermt,forsomeoperationf,andade¯nitionaltreeToff,andthroughatraversalofTreturnstheoccurrencesoughtby¸.De¯nition7.Lettbeanon-value.¸(t)=8o¢¸(t=o)iftisconstructor-rootedandt=oisanyoutermostoperation-rootedsubtermoft;'(t;Tf)iftisf-rooted,forsomeoperationf,andTfisade¯nitionaltreeoff.'(t;T)=8¤ifT=rule(l!r)orT=exempt;'(t;Ti)ifT=branch(o;hT1;:::;Tki)andt=ohassortsandrootthei-thconstructor(instandardordering)ofs;1o¢¸(t=o)ifT=branch(o;:::)andt=oisoperation-rooted.(3)WecanusetheequationsofDe¯nition7tocompute¸(t),forsomenon-valuet,byregardingtheleftsideofeachequationasaproceduredeclarationandtherightsideastheprocedure'sbody.Fromthisproceduralinterpretationof¸,theapplicationof¸tosomegroundoperation-rootedtermgeneratesasequenceof0When'iscalledfrom¸,tisaninstanceofthepatternofTi.147 recursivecallsto'and/or¸consistingof\segments",eachbeginningwithacallto¸followedbyoneormorecallsto'.Thestructureofatypicalsequenceis:¸(t0);'(t0;T01);'(t0;T02);:::;¸(t1);'(t1;T11);'(t1;T12);:::(4)Forourpurposes,onlytheargumentsof¸and'inthissequenceareinteresting.Sinceourde¯nitionof¸and'isnonprocedural,somecareisrequiredtode¯nethesequencewedesire.De¯nition8.IfRisaninductivelysequentialrewritesystemandtisagroundoperation-rootedterm,thenthe¸-sequenceSgeneratedbytisde¯nedasfollows:{EachelementofSisaninputtoeither¸or'.Inputsto¸and'arerespectivelycalled¸-elementsand'-elementsofS.{The¯rstelementofSisthe¸-elementt.{Ifsomexisay-elementofS,whereyiseither¸or',theny(x)isaninstanceoftheleftsideofanequationofDe¯nition7.Theinstanceofthecorrespondingrightsideiseither¤,inwhichcasexisthelastelementofS,orcontainsasubexpressiony0(x0),wherey0iseither¸or'andx0istheinputtoy0,inwhichcasex0isthey0-elementofSfollowingx.AnysubsequenceofSbeginningwitha¸-elementxandendingeitherjustbeforethefollowing¸-elementorattheendofthesequenceifno¸-elementfollowsxinSiscalledasegmentofS.Lemma9.IfRisaninductivelysequentialrewritesystemandtisanon-value,then¸isde¯nedont.Proof.Withoutlossofgeneralityweconsiderthecaseinwhichtisoperation-rooted.Weaskthereadertoverifythatif¸or'haveaninputxintheirrespectivedomains,thenanyrecursiveapplicationof¸or'generatedbytheinputxhasaninputinthefunction'srespectivedomain.Byhypothesis,theinitialinputto¸isinthedomainof¸,thusweshowonlythatany¸-sequenceSgeneratedbytis¯nite.WeprovethateachsegmentofSis¯niteandthatthereareonlya¯nitenumberofsegmentsinS.Ifforsomeintegersiandj,hti;Tijiandhti;Ti(j+1)iaretwoconsecutive'-elementsofasegmentofS,thenTi(j+1)isapropersubtreeofTij.Thus,thesegmentis¯nite.Likewise,ifforsomeintegeri,tiandti+1arethe¸-elementsoftwoconsecutivesegmentsofS,thenti+1isapropersubtermofti.Thus,Sis¯niteand¸(t)isde¯ned.Ratherlooselyspeaking,wenowprovethatinordertonormalizeatermtwemusteventuallyrewritethesubtermoftatoccurrence¸(t).Thedi±cultyliesinformalizing\eventually."Theformalizationofthisidearequirestheconceptsofdescendant(orresidual)ofatermandneededredex.Aformalde¯nition,quitetechnical,ofdescendantsofasubtermsinatermtafteranother(notnecessarilydistinct)subtermoftisrewritten,canbefoundin[8].Alessformal,butmoreintuitive,formulationisproposedin[13].Supposewehavearewritesequencet¤!t0andasubtermsoft.Thedescendantsofsint0arecomputedasfollows.148 Underlinetherootofsandperformtherewritesequencet¤!t0.Thedescendantsofsint0arethesubtermsoft0whichhaveanunderlinedroot.Then,aredexsinatermtisneededifineveryrewritesequenceofttonormalformadescendantofsisrewritten.Lemma10.IfRisaninductivelysequentialrewritesystemand,forsomeintegersiandmi,ti;hti;Ti1i;hti;Ti2i;:::;hti;Timiiisthei-thsegmentofthe¸-sequencegeneratedbysomegroundoperation-rootedtermt,then(1)tiisoperation-rootedand(2)foralljin1;:::;mi,ifrisarewriteruleofR,thenrcannotrewriteanydescendantoftiattherootunlessriscontainedinthepdtTij.Proof.Theproofofclaim(1)isasimpleinductiononi.Theclaimisassumedforthe¯rstsegment,andbyde¯nitionof',everytimeanewsegmentSbegins,i.e.,arecursivecallto¸isgenerated,theargumentof¸,i.e.,theinitialelementofS,isoperation-rooted.Wenowprove(2)byinductiononj.Letfbetherootofti,forsomeoperationf.Basecase:j=1.AnydescendantofticanberewrittenattherootonlybyarewriteruleofRde¯ningf.Anysuchruleiscontainedinade¯nitionaltreeToff.Bycase2ofthede¯nitionof¸andbyde¯nitionof¸-sequence,Ti1isade¯nitionaltreeoff.Ind.case:Weassumetheclaimforsomejin1;:::;mi¡1,andprovetheclaimforj+1.Bythede¯nitionsof'andde¯nitionaltree,thefollowingconditionshold:(a)Tij=branch(o;hT1;:::;Tki),forsomeoccurrenceoofti,k�0,andpartialde¯nitionaltreesT1;:::;Tk;(b)therootofthesubtermoftiatoissomeconstructorc;(c)Ti(j+1)=Tnforsomenin1;:::;k;and(d)foralllin1;:::;k,ifl6=n,thentherootofthesubtermatoccurrenceooftheleftsideofanyrulercontainedinTlisaconstructordi®erentfromc.Thusrcannotrewriteanydescendantoftiattheroot,andtheclaimholdsforj+1also.Theorem11.IfRisaninductivelysequentialrewritesystemandtisagroundoperation-rootedterm,thennodescendantt00oftcanberewrittentoheadnormalformunlessthesubtermoft00atoccurrence¸(t)hasbeenrewrittentoheadnormalform.Proof.Theproofisbyinductiononthenumberofsegmentsinthe¸-sequencegeneratedbyt,whichwedenotet;ht;T1i;:::ht;Tmi;t0;ht0;T01i;:::Basecase:Thereisonlyonesegmentand,byde¯nitionof',¸(t)=¤.Sincetisoperation-rooted,tcanberewrittentoheadnormalformonlybyrewritingadescendantoftattheroot.Ind.case:Thefollowingconditionshold:(a)t0=t=o,forsomeoccurrenceooft;(b)¸(t0)=o0,forsomeoccurrenceo0oft0;(c)¸(t)=o¢o0;and(d)weassumetheclaimfort0.ByLemma10,t00canberewrittenattherootonlybyarulecontainedinTm.Byde¯nitionofde¯nitionaltree,thesubtermatointheleftsideofanyrulecontainedinTmisconstructor-rooted.Byconstruction,t0isoperation-rooted,thusnodescendantt00oftcanberewrittenbyanyrulecontainedinTm,hencebyanyruleofR,unlessthesubtermoft00atoccurrenceo,whichisadescendantoft0,isaheadnormalform.Bytheinductivehypothesis,nodescendantoft0canberewrittentoheadnormalform,withoutrewritingto149 aheadnormalformitssubtermato0.Sinceforanyterms,occurrencepofs,andoccurrencep0ofs=p,theequation(s=p)=p0=s=(p¢p0)holds,nodescendantt00oftcanberewrittentoheadnormalformwithoutrewritingthesubtermoft00atoccurrence¸(t)toaheadnormalform.Thisresultdirectlysuggestsaone-steprewritestrategythatwecaneasilyprovenormalizing.Ourstrategyissomewhatspecial,sinceoninputatermt,ratherthanselectingaredexoft,selectstheoccurrenceofasubtermoftwhichshouldberewritten,butmightbeirreducible.Whenthestrategyselectstheoccurrenceofanirreduciblesubtermoft,we\loseinterest"infurtherrewritingt,sincethenormalformoft,ifany,willcontainde¯nedsymbols.WewillcomebacktothispointafterCorollary14.De¯nition12.Wecalloutermost-neededtheone-steprewritestrategyofaninductivelysequentialrewritesystemthatinanynon-valuetselectsforrewritingthesubtermoftatoccurrence¸(t).Corollary13.IfRisaninductivelysequentialrewritesystemandt+!vinR,forsomenon-valuetandvaluev,then¸(t)istheoccurrenceofaneededredexoft.Proof.Iftisoperation-rooted,thensomedescendantt0oftmustberewrittenattheroottonormalizet.Rewritingthesubtermoft0at¸(t)(toheadnormalform)isnecessarytorewritet0,hencet,toheadnormalform,hencetonormalizet.Thus,inanyrewritesequenceofttonormalformthesubtermatoccurrence¸(t)ofsomedescendantoftisrewritten,hence¸(t)istheoccurrenceofaneededredexoft.Iftisconstructor-rooted,then¸(t)=o¢¸(t=o),forsomeoccurrenceoofanoutermostoperation-rootedsubtermoft.Theconstructordisciplineensuresthattcanberewrittentonormalformonlyifadescendantoft=oisrewrittentonormalform,andthepreviouscaseapplies.Corollary14.IfRisaninductivelysequentialcompleterewritesystem,thentheoutermost-neededstrategyisnormalizing.Proof.We¯rstprovethatforanynon-valuet,¸(t)istheoccurrenceofaneededredexoft.ByLemma9,¸(t)isde¯ned.ByTheorem11,¸(t)isoperation-rooted.ByLemma6,thenormalformoftisavalue,thusbyCorollary13,¸(t)istheoccurrenceofaneededredexoft.HuetandL¶evy[8]provethattherepeatedrewritingofsomeneededredexofatermtleadstothenormalformoft,ifitexists.7mustbechangedtomaketheoutermost-neededstrategynormalizingforincompletesystemsalso.Therequiredchangeis:'(t;exempt)=o¢¸(t=o)(5)whereoistheoccurrenceofanarbitraryoutermostoperation-rootedpropersubtermoft.Anapproachsuitableforapplicationstoprogramminglanguagesconsistsinraisinganexceptionif¸(t)istheoccurrenceofanirreduciblesubtermoft.150 5ParallelDe¯nitionalTreesInductivelysequentialoperationsarenotas\powerful"aswemightoccasionallydesire.Considerforexamplethefollowingthreealternativede¯nitionsofthebooleanconjunctionoperatordenotedbythein¯xsymbol\_".true_!truefalse_Y!Y_true!trueX_false!X_true!truetrue_!truefalse_false!false(6)Theoperator\_"isinductivelysequentialaccordingtothe¯rsttwode¯nitions,butitisnotaccordingtothethirdoneknownas\parallel-or".Weobtainastructuresimilartoade¯nitionaltreefortheparallel-oroper-ationby\collapsing"therootsofthede¯nitionaltreesofthetwoinductivelysequentialoperationsofdisplay(6).De¯nition15formalizesthisidea.Figure2pictoriallyrepresentstheresulting\tree".ForthesakeofsymmetrywehaveduplicatedaruleinthetreeofFigure2.Also,therearetwoexemptnodesinthetree,althoughtheoperation\_"iscomplete.ThistreeisbuiltaccordingtothealgorithmdescribedintheproofofTheorem19.X1_X2true_X2truefalse_X2X1_truetrueX1_falsefalse_truefalse_falsetrue_falsefalse_falsefalsefalse²²Fig.2.Pictorialrepresentationofaparallelde¯nitionaltreeoftheoperationparallel-orde¯nedindisplay(6).Thearcslinkingafathertochildrenbelongingtothesamesequentialcomponentofthetreearejoinedtogether.Thesymbol\²"representsanexemptnode.De¯nition15.Tisapartialparallelde¯nitionaltree,orppdt,ifandonlyifoneofthefollowingcasesholds:T=branch(¿;¹o;¹¹T);where¿isapattern,¹oisalisto1;:::;okofoccurrencesofdistinctvariablesof¿,foralljin1;:::;k,thesortof¿=ojhasconstructors151 cj1;:::;cjkjinstandardordering,and¹¹Tisasequence¹T1;:::;¹Tkofsequencesofppdts,suchthatforalljin1;:::;k,¹Tj=Tj1;:::;Tjkjandforalliin1;:::;kj,thepatternintherootofTjiis¿[ojÃcji(X1;:::;Xn)],wherenisthearityofcjiandX1;:::;Xnarenewvariables.T=rule(¿;l!r);where¿isapatternandl!risarewriterulesuchthatl´¿.T=exempt(¿);where¿isapattern.Theppdts¹T1;:::;¹TkarereferredtoassequentialcomponentsofT.Apartialparallelde¯nitionaltreeisaspecialcaseofapartialde¯nitionaltree,namely,oneinwhichtheoccurrenceargumentofanybranchnodeisasequenceofoccurrencesoflength1.Whenwewanttoemphasizethisdi®erencewewillusetheadjectives\sequential"or\parallel".Whenthedi®erenceisirrelevantorclearfromthecontextwewillsimplyuse\de¯nitionaltree".De¯nition16.Tisaparallelde¯nitionaltreeofanoperationfifandonlyifTisappdtwithf(X1;:::;Xn)aspatternargument,wherenisthearityoffandX1;:::;Xnarenewvariables.Thenextresultsentailtheconceptofsubsumptionordering[9],aquasi-orderingrelationontermsdenotedbythein¯xoperator\·"anditsderivatives\",\´",etc.Wesaythatt·t0whent0isaninstanceoft,thatis,thereexistsasubstitution¾suchthat¾(t)=t0.Overlappingisallowedinweaklyorthogonalrewritesystems.Anysuchsys-temmaycontainsomerulesubsumedbysomeotherrule.Subsumedrulesareuselessinthesensethattheireliminationdoesnotchange(theexistenceof)thenormalformofanyterm.Subsumedrulesdonotalways¯tinparallelde¯ni-tionaltrees,thuswecharacterizetheminthenextde¯nitiontoeliminatethemlater.17.Arulel!rinaweaklyorthogonalrewritesystemRisuselessifandonlyifthereexistsanotherrulel0!r0inRsuchthatl0l.Aruleisusefulifandonlyifitisnotuseless.Lemma18.IfRisaweaklyorthogonalrewritesystemandR0isobtainedfromRbyremovinganyuselessrule,then,forallgroundtermstandt0,t¤!Rt0ifandonlyift¤!R0t0.Theorem19.IffisanoperationofaweaklyorthogonalrewritesystemR,thenthereexistsaparallelde¯nitionaltreeToffsuchthattherulescontainedinTareallandonlytheusefulrulesde¯ningfinR.Proof.Ourproofisconstructivebymeansofanalgorithmthatoninputfoutputsaparallelde¯nitionaltreeTwiththecharacteristicwearelookingfor.TheconstructionofTisiterative.AteachiterationweaddanewnodetoT.TheadditionofanodeNisatwo-stepprocess.First,wecomputethepattern152 argument¿ofN,which,exceptfortherootofTwhosepatternargumentisalwaysf(X1;:::;Xn),isdeterminedbythefatherofN.Second,wecompare,accordingtothesubsumptionordering,¿withtheleftsidesoftheusefulrulesde¯ningf.TheresultofthecomparisondetermineswhetherNshouldbeabranch,rule,orexemptnode.WenowdescribetheconstructionofanodeNgivenitspatternargument¿.If¿´l,forsomerulel!r,thenN=rule(l!r);elseif¿l,forsomerulel!r,thenN=branch(¹o;¹¹T),where¹ocontainsalltheoccurrencesofvariablesof¿andthepatternsintheppdtsof¹¹Tarecomputedaccordingtothede¯nitionofparallelde¯nitionaltree;elseN=exempt.WeaskthereadertoverifythattheconstructionofTterminateswithaparallelde¯nitionaltreeoftheusefulrulesoff.Thealgorithmimplicitlyde¯nedbytheproofofTheorem19tendstobuild\bushy"parallelde¯nitionaltrees,sinceasequentialcomponentofthetreeisgeneratedforeachvariableofeachtemplate.Thesetreesareusefultoshowthatourapproachtoparallelismcanbeappliedtothewholeclassofweaklyorthog-onalrewritesystems.Wewilldiscusslaterhowwemayusede¯nitionaltreestodiscoverorcontrolthedegreeofparallelismofacomputation.Buildingdef-initionaltreeswiththeabovealgorithmisinappropriatefortheseapplications.Generally,weareinterestedin¯ndingwhetheranoperationhasasequential,ratherthanparallelde¯nitionaltree.Often,thoughnotalways,\thinner"treesseempreferable,ifthecomputationalresourcesavailabletoanimplementationofourstrategyarelimited.6ParallelNormalizationInthissectionweaddressthenormalizationprobleminweaklyorthogonalrewritesystemsbyexploitingparallelde¯nitionaltrees.Wereformulatepar-allelversionsofthefunctions¸and'de¯nedinSection4inmuchthesamewayinwhichparalleltreesreformulatesequentialones.Thenewfunction¸,oninputagroundtermt,returnsasetSofoccurrencesofsubtermsoftthatshouldberewritten.Theoldfunction¸canberegardedasthespecialcaseofthenewoneinwhichthesetSisasingleton.Wefurtheroverloadthesymbol\¢"asfollows:theexpressiono¢fo1;:::;okg,forsomeoccurrenceoandsetofoccurrencesfo1;:::;okg,forsomek¸0,denotesthesetofoccurrencesfo¢o1;:::;o¢okg;inparticular,itdenotestheemptysetofoccurrenceswhenk=0.153 De¯nition20.Lettbeagroundterm.¸(t)=8[o2¹oo¢¸(t=o)iftisconstructor-rootedand¹oisthesetofoccurrencesofoutermostoperation-rootedsubtermsoft;'(t;Tf)iftisf-rooted,forsomeoperationf,andTfisaparallelde¯nionaltreeoff.'(t;T)=8ÁifT=exempt;f¤gifT=rule(l!r);[k=18'(t;Tji)ifT=branch(ho1;:::;oki;hT1;:::;Tki),forsomek�0,t=ohassortsandrootthei-thconstructorofs,andTj=Tj1;:::;Tjkj,forjin1;:::k;oj¢¸(t=oj)ift=ojisoperation-rooted.(7)Wenowdiscusstheextensiontotheparallelcaseoftheresultspresentedintheprevioussectionsforthesequentialcase.Wepresentourideaswithlessdetailthanbeforeandworkoutonlythekeystepsofthisextension,namelytheevolutionoftheconceptsof¸-sequenceandneededredex.Fromtheproceduralinterpretationviewpoint,¸oninputsomegroundoperation-rootedtermtgeneratesatreeratherthanasequenceofrecursivecalls.Wecallthisstructurethe¸-treegeneratedbytandeither¸-nodeor'-nodeanynodeofthistree.IfTisa¸-tree,thenanypathfromtherootofTdownaleafisjusta¸-sequence.Thenotionofsegmentisreplacedbythatofpre¯xofT.Apre¯xconsistsofa¸-nodenandthedescendantsofndownallthepathsbeginningatnandendingeitherbeforeanother¸-nodeorataleafifthereisno¸-nodedownapath.Lemma9isextendedtoanygroundterm:IfRisaweaklyorthogonalrewritesystemandtisagroundterm,then¸isde¯nedont.Theproofisconceptuallyidentical.ToreformulateLemma10weneedtheconceptofi-thfrontierofapre¯x.Thei-thfrontierofapre¯xP,forsomei�0,isthesetof'-nodesofPatdepthiplusalltheleavesofPatdepthnotgreaterthani.Inotherwords,thesetoftheendnodesofthepre¯xesoflengthuptoiofallthesegmentsbeginningattherootofP.Then,wecanprove,byinductiononi,that:IfRisaweaklyorthogonalrewritesystemandPisapre¯xofthe¸-treegeneratedbysomegroundoperation-rootedtermt,then(1)the¸-nodet0ofPisanoperation-rootedterm,and(2)foralli�0,ifrisaruleofR,thenrcannotrewriteanydescendantoft0attheroot,unlessriscontainedinappdtofthei-thfrontierofP.Theconceptofneededredexismeaninglessinweaklyorthogonalrewritesystems.SekarandRamakrishnan[22]replaceitwiththatofnecessarysetofredexes.AsetSofredexesinatermtisanecessarysetifineveryreductionsequencethattakesttoitsnormalform,atleastoneredexinSoritsdescendantisrewritten.Necessarysetstaketheplaceofneededredexesinthesensethattheparallelrewritestrategythatateverysteprewritesalltheredexesofanecessarysetisnormalizing[22].Thede¯nitionofnecessarysetissubtle,sinceanecessary154 setremainsnecessaryevenifweaddredexestoit.Thus,itisfurtherprovedin[22]thatwhenthenecessarysetconsideredbythestrategyisminimal,thestrategyisoptimalamongthosethatdonotexaminetherightsidesofrules.Thus,theextendedTheorem11is:IfRisaweaklyorthogonalrewritesystemandtisagroundoperation-rootedterm,thennodescendantt0oftcanberewrittentoheadnormalformunlessforsomeoccurrenceoin¸(t),thesubtermoft0atohasbeenrewrittentoheadnormalform.TheproofissimilartothatofTheorem11withtheonlydi®erencethatnowwehavesetsofredexesratherthanasingleredex.FromthisresultwederiveandeasilyprovetheextensionofCorollary13,thatis:IfRisaweaklyorthogonalrewritesystemandt¤!vinR,forsomegroundtermtandvaluev,then¸(t)isanecessarysetofoccurrenceoft.Aconsequenceofthelastresultisthattheextensionoftheoutermost-neededstrategytotheparallelcaseyieldsexactlythestrategybasedonnecessarysetsgivenin[22].Theoutermost-neededstrategyisthesequentialcaseofthisparallelstrategy,namelythatinwhichthenecessarysetisalwaysasingleton.Theimplementationofthestrategy,bymeansofanautomatondiscussedin[22],canthusbeusedfortheoutermost-neededstrategytoo.7RelatedWorkandApplicationsThenotionofsequentialityhasbeenwidelyinvestigated.Seminalworkonnor-malizingstrategiesappearsin[8,20].Theproblemisfurtheranalyzedand/orsummarizedin[4,13,21].Thedi±cultyofthenormalizationproblemledtoanumberofvariationsoftheconceptofsequentiality[3,7,13,23].Thecomparisonofinductivesequentialitywiththeseapproachesisoutsidethescopeofthisnote.Rather,wefocusonafewspeci¯cissues.We¯rstdiscusssequentialapplications.Forexample,thesystemLog(F)[17{19]isconcernedwithaclassDF¤ofrewritesystemsandalazyrewritestrategyforthesesystems.DF¤bansop-erationswithnon-purecolumns[1]toguaranteetermination.Brie°y,foranyi,thei-thargumentintheleftsidesofalltherewriterulesde¯ninganoper-ationiseitheralwaysorneveravariable.Further,non-variableargumentsintheleftsideofarewriterulearelimitedtoaconstructorsymbolappliedtoatupleofvariables.Theseconditionsmakeprogramsmoredi±culttowriteandtounderstand,textuallylonger,andlesse±cient.TheprogramminglanguageBABEL[14{16],whichcombinesfunctions,re-lations,andlaziness,freestheprogrammerfromtheaboverestrictions,buten-forcesthemontheimplementation.Sourceprogramsaretransformedintose-manticallyequivalentuniform,i.e.,non-subuni¯ableand°at,programsbeforeexecution[14].ProgramsinthisclassareexactlythesameastheprogramsinDF¤andtheirexecutionsincurasimilarlossofe±ciency.Therewritesystemsunderlyingtheseprogramsarenon-overlappingandwecaneasilyshowthattheyareasubsetoftheinductivelysequentialsystems.Thissubsetisproper,since,forexample,neitheroperationofdisplay(1)isuniform.OurresultsallowusbothtoextendtheclassDF¤andtoavoidintermediateuniformprogramsintheimplementationofBABELwithoutjeopardizingtermi-155 nation.Theargumentsofnon-purecolumnsneedtoberewrittenifandonlyiftheyareselectedaccordingto¸.Wenowdiscusshowde¯nitionaltreescanbeappliedtoparallelcomputa-tions.Wehaveseen,intheparallel-orexample,thatrestrictingtherulesofarewritesystemchangesthesemanticsofcomputations.Thus,ratherthanre-strictingtheformoftherewriterules,anoppositeapproachconsistsofrelaxingthelazinessoftherewritestrategy.Forexample,theparallel-outermoststrategy,whichrewritesinparallelalloutermostredexesofaterm,isnormalizing[20],al-thoughitislikelytoperformunnecessaryrewrites.SekarandRamakrishnan[22]re¯nethisstrategybyoptimallyminimizingunnecessaryrewrites.Ourresearchshowsanalternativeapproachtothecomputationofnecessarysetsandshedssomelightontheirinternalstructure.Necessarysetsarecomputedin[22]bythealgorithmFindNS.Inthisalgo-rithmasetofoccurrencesdenotedD0isarbitrarilychosenaslongasthematchsetofthemaximalconstructorpre¯xofFindNS'sargumentiscovered.Since\fore±ciency,itiscrucialtoselectasmallD0"[22]thenon-determinismislargelyremovedinanimplementationoftherewritestrategybychosingsomeD0withminimumsize.Aconsequenceofthisminimizationisthelossofinformationusefulincontrollingsomeaspectsofaparallelrewritestrategy,e.g.,synchro-nizationand/orallocationofprocessors.Wewillshowthispointshortlyinasetofexamples.Ourapproachcontainsasimilaraspectofnon-determinism.Anoperationmayhaveseveral\signi¯cantly"di®erentde¯nitionaltrees,evensequentialones,andourresultsdonotdependonanyparticulartree.Inourapproachthemin-imizationofanecessarysetisequivalenttominimizingthenumberofsequen-tialcomponentsofade¯nitionaltree.Theequalityoperationbetweennaturalnumbers,de¯nedbelow,isanexampleofoperationwith\non-isomorphic"def-initionaltrees.0=0!true0=s()!falses()=0!falses(X)=s(Y)!X=Y(8)Thereexisttwodistinctsequentialtreesof\=",bothhaveabranchnodeattheroot.Theoccurrenceargumentsintherootnodesofthesetreesarerespectively1and2.Thisimpliesthatbothargumentsoftheoperationmustbeheadnormalformstoapplyarewriteruleattheroot.Thisisratherobviousfromthede¯ningrules,butifasimilarconditionis\pusheddeeper",i.e.,ifitoccursonlyinapropersubsetoftherules,thentheconditionbecomesmoredi±culttodetectwithoutsuitableconceptualtools.Wediscussinanexamplehowwecantakeadvantageofthecharacteristicsof\="pointedoutbyitsde¯nitionaltrees.Considertheoperations\·"ofdisplay(1),parallel-or,and\="de¯nedabove.Theseoperationsarequitedi®erentasfarastheparallelevaluationoftheirargumentsisconcerned.Theoperation\·"hasauniquesequentialdef-initionaltree.Unlesswearewillingtoperformunnecessaryrewrites,wemustrewritethe¯rstargumentofa\·"-rootedtermtoheadnormalformbefore156 decidingonthesecondargument.Theoperationparallel-orhasaparalleldef-initionaltree,butnotasequentialone.Wewanttorewritebothargumentsofaparallel-or-rootedtermuntiloneofthemisaheadnormalform,andthenwecandecidewhethertokeeprewritingtheotherargument.Aminimalnecessarysetmaycontaintwoelements,andtheseelementsareinanorrelation.Theoperation\="hastwodistinctsequentialde¯nitionaltrees.Wecanrewriteoneargumentaftertheotherorbothargumentsinparalleluntilbothbecomeheadnormalforms.Aminimalnecessarysetalwayscontainsatmostoneelement.However,thereexistnon-minimalnecessarysetswhicharestilloptimalinthesenseof[22].Theelementsofthesesetsareinanandrelation.Someimplicationsofthestructureofanecessarysetfollow.Althoughbothoperations\·"and\="areinherentlysequential,ifbothoccurinacomputa-tionandwehavesomeextracomputationalresourcestoallocate,\="mustbepreferredto\·".Althoughtheargumentsofbothoperationsparallel-orand\="canberewritteninparallelwithoutwastedrewrites,themutualrelationshipsbetweentheelementsofthesetofparallelcomputationsofeachoperationre°ectthestructureofthecorrespondingnecessaryset.Inthe¯rstcasethecomputa-tionofoneargumentofparallel-ormustbeabletostopthecomputationoftheotherargument,whereasinthesecondcasethecomputationofoneargumentof\="isindependentofthatoftheotherargument,sincetheoutcomeofrewritingoneargumenthasnoin°uenceontheneedofrewritingtheotherargument.8ConcludingRemarksRewritingisacomputationalparadigmthatspeci¯estheactions,butnotthecontrol.De¯nitionaltreesareahigh-levelabstractiontospecifyorinfersomeaspectsofthecontrol.Theproblemofbuildingde¯nitionaltreesfromrewritesystemshasbeenaddressedonlymarginallyinTheorem19.Somealgorithmsforthistaskarepresentedin[24].Wehaveshowntheapplicationde¯nitionaltreestotwointerestingclassesofrewritesystems,oneappropriateforsequentialcomputations,theotherforparallelones.Anapplicationofourresultstoinherentlysequentialcomputationsallowsustoextendtheexpressivepowerofsomeprogramminglanguagesbasedonrewritingand/orthee±ciencyoftheirimplementations.Anapplicationofourresultstoparallelcomputationsallowsustodetectopportunitiesforparallelrewritinginsequentialcomputations,withoutwastedrewritesandwithasimplercontrol.De¯nitionaltreesarenotlimitedtoweaklyorthogonalrewritesystems.Struc-turesverysimilartode¯nitionaltrees,butstoringsetsofrulesinbothleavesandbranches,havebeenappliedwithinterestingresults[2]toaclassofrewritesys-temslargerthanthosediscussedinthisnote.References1.SergioAntoy.Designstrategiesforrewriterules.InS.KaplanaandM.Okada,editor,CTRS'90,pages333{341,Montreal,Canada,June1990.Lect.Notesin157 Comp.Sci.,Vol.516.2.SergioAntoy.Non-determinismandlazyevaluationinlogicprogramming.InT.P.ClementandK.-K.Lau,editors,LOPSTR'91,pages318{331,Manchester,UK,July1991.Springer-Verlag.3.G.Boudol.Computationalsemanticsoftermrewritingsystems.InMauriceNi-vatandJohnC.Reynolds,editors,Algebraicmethodsinsemantics,chapter5.CambridgeUniversityPress,Cambridge,UK,1985.4.L.G.BoumaandH.R.Walters.Implementingalgebraicspeci¯cations.InJ.A.Bergstra,J.Heering,andP.Klint,editors,AlgebraicSpeci¯cation,chapter5.Addison-Wesley,Wokingham,England,1989.5.N.DershowitzandJ.Jouannaud.Rewritesystems.InJ.vanLeeuwen,editor,HandbookofTheoreticalComputerScienceB:FormalMethodsandSemantics,chapter6,pages243{320.NorthHolland,Amsterdam,1990.6.J.Goguen,J.Meseguer,S.Leinwand,T.Winkler,andH.Aida.Therewriterulemachineproject.TechnicalReportSRI-CSL-89-6,SRIInternational,MenloPark,CA,1989.7.C.M.Ho®mannandM.J.O'Donnell.Implementationofaninterpreterforabstractequations.In11thACMSymposiumonthePrincipleofProgrammingLanguages,SaltLakeCity,1984.8.G.HuetandJ.-J.L¶evy.Computationsinorthogonaltermrewritingsystems.InJ.-L.LassezandG.Plotkin,editors,Computationallogic:essaysinhonourofAlanRobinson.MITPress,Cambridge,MA,1991.Previousversion:Callbyneedcomputationsinnon-ambiguouslineartermrewritingsystems,TechnicalReport359,INRIA,LeChesnay,France,1979.9.G¶erardHuet.Con°uentreductions:Abstractpropertiesandapplicationstoterm-rewritingsystems.JACM,27:797{821,1980.10.J.R.Kennaway.Sequentialevaluationstrategiesforparallel-orandrelatedreduc-tionsystems.AnnalsofPureandAppliedLogic,43:31{56,1989.11.ClaudeKirchnerandPatrickViry.Implementingparallelrewriting.InPLILP'90,pages1{15,LinkÄoping,Sweden,August1990.Lect.NotesinComp.Sci.,Vol.456.12.J.W.Klop.TermRewritingSystems.InS.Abramsky,D.Gabbay,andT.Maibaum,editors,HandbookofLogicinComputerScience,Vol.II,pages1{112.OxfordUniversityPress,1992.Previousversion:Termrewritingsystems,TechnicalReportCS-R9073,StichtingMathematischCentrum,Amsterdam,1990.13.JanWillemKlopandAartMiddeldorp.Sequentialityinorthogonaltermrewritingsystems.TechnicalReportCS-R8932,StichtingMathematischCentrum,Amster-dam,TheNetherlands,1989.14.H.Kuchen,R.Loogen,J.J.Moreno-Navarro,andM.Rodr¶³guez-Artalejo.Graph-basedimplementationofafunctionallanguage.InESOP'90,pages279{290,1990.Lect.NotesinComp.Sci.,432.15.J.J.Moreno-Navarro,H.Kuchen,R.Loogen,andM.Rodr¶³guez-Artalejo.Lazynarrowinginagraphmachine.InConf.onAlgebraicandLogicProgr.,1990.Lect.NotesinComp.Sci.,463.16.J.J.Moreno-NavarroandM.Rodr¶³guez-Artalejo.Logicprogrammingwithfunc-tionsandpredicates:ThelanguageBABEL.JournalofLogicProgramming,12:191{223,1992.17.SanjaiNarain.LOG(F):Anoptimalcombinationoflogicprogramming,rewriting,andlazyevaluation.PhDthesis,UniversityofCalifornia,LosAngeles,CA,1988.18.SanjaiNarain.Optimizationbynon-deterministic,lazyrewriting.InRTA'89,pages326{342,ChapelHill,NC,1989.Lect.NotesinComp.Sci.,Vol.355.158 19.SanjaiNarain.Lazyevaluationinlogicprogramming.InThirdIEEEConferenceonComputerLanguages,pages218{227,NewOrleans,1990.20.MichaelJ.O'Donnell.ComputinginSystemsDescribedbyEquations.Springer-Verlag,1977.Lect.NotesinComp.Sci.,Vol.58.21.MichaelJ.O'Donnell.EquationalLogicasaProgrammingLanguage.MITPress,1985.22.R.C.SekarandI.V.Ramakrishnan.Programminginequationallogic:Beyondstrongsequentiality.InProceedingsoftheFifthAnnualIEEESymposiumonLogicinComputerScience,pages230{241,Philadelphia,PA,June1990.23.SatishThatte.Are¯nementofstrongsequentialityfortermrewritingwithcon-structors.InformationandComputation,72:46{65,1987.24.YonggongYan.Buildingde¯nitionaltrees.Master'sproject,PortlandStateUni-versity,Portland,OR,March1992.159