UnderonsiderationforpubliationinTheoryandPratieofLogiProgramming1TransformationsofLogiProgramswithGoalsasArgumentsALBERTOPETTOROSSIDipartimentodiInformatia,SistemieProduzione,Universit adiRomaTorVergata,ViadelPolitenio1,I-00133Roma,Italy(e-mail:alberto.pettorossiuniroma2.it)MAURIZIOPROIETTIIASI-CNR,VialeManzoni30,I-00185Roma,Italy(e-mail:proiettiiasi.rm.nr.it)AbstratWeonsiderasimpleextensionoflogiprogrammingwherevariablesmayrangeovergoalsandgoalsmaybeargumentsofprediates.Inthislanguageweanwritelogiprogramswhihusegoalsasdata.Wegivepratialevidenethat,byexploitingthisapabilitywhentransformingprograms,weanimproveprogrameÆieny.Weproposeasetofprogramtransformationruleswhihextendthefamiliarunfoldingandfoldingrulesandallowustomanipulatelauseswithgoalswhihourasargu-mentsofprediates.Inordertoprovetheorretnessofthesetransformationrules,weformallyde netheoperationalsemantisofourextendedlogiprogramminglanguage.ThissemantisisasimplevariantofLD-resolution.Whensuitableonditionsaresatis edthissemantisagreeswithLD-resolutionand,thus,theprogramswritteninourextendedlanguageanberunbyordinaryPrologsystems.Ourtransformationrulesareshowntopreservetheoperationalsemantisandtermi-nation.KEYWORDS:programtransformation,unfold/foldtransformationrules,higherorderlogiprogramming,ontinuations1IntrodutionProgramtransformationisaverypowerfulandwidelyreognizedmethodologyforderivingprogramsfromspei ations.Therules+strategiesapproahtoprogramtransformationwasadvoatedinthe1970sbyBurstallandDarlington(1977)fordeveloping rstorderfuntionalprograms.SinethenBurstallandDarlington’sapproahhasbeenfollowedinavarietyoflanguageparadigms,inludinglogiallanguages(TamakiandSato1984)andhigherorderfuntionallanguages(Sands1996).Thedistintivefeatureoftherules+strategiesapproahisthatitallowsustoseparatetheonernofprovingtheorretnessofprogramswithrespettospei ationsfromtheonernofahievingomputationaleÆieny.Indeed,theorretnessofthederivedprogramsisensuredbytheuseofsemantispreservingtransformationrules,whereastheomputationaleÆienyisahievedthroughthe2A.PettorossiandM.Proiettiuseofsuitablestrategieswhihguidetheappliationoftherules.Thepreservationofthesemantisisprovedoneandforall,forsomegivensetsoftransformationrules,andifwerestritourselvestosuitablelassesofprograms,weanalsoguar-anteethee etivenessofthestrategiesforimprovingeÆieny.Inthispaperwewillarguethroughsomeexamples,thatasimpleextensionoflogiprogrammingmaygiveextrapowertotheprogramtransformationmethod-ologybasedonrulesandstrategies.Thisextensiononsistsinallowingtheuseofvariableswhihrangeovergoals,alledgoalvariables,andtheuseofgoalswhihareargumentsofprediates,alledgoalarguments.Inthepratieoflogiprogrammingtheideaofhavinggoalvariablesandgoalargumentsisnotnovel.Thereadermaylook,forinstane,at(SterlingandShapiro1986;Warren1982).Goalvariablesandgoalargumentsanbeusedforexpress-ingthemeaningoflogialonnetivesandforwritingprogramsinaontinuationpassingstyle(TarauandBoyer1990;Wand1980)asthefollowingexampleshows.Example1ThefollowingprogramP1:F_GFF_GGexpressesthemeaningoftheoronnetive.ThefollowingprogramP2:p([℄;Cont)Contp([XjXs℄;Cont)p(Xs;q(X;Cont))q(0;Cont)ContusesthegoalvariableContwhihdenotesaontinuation.Thegoalp(l;true)su-eedsinP2i thelistlonsistsof0’sonly. Programswithgoalvariablesandgoalarguments,suhasP1andP2intheaboveexample,arenotallowedbytheusual rstordersyntaxofHornlauses,wherevariablesannotourasatomsandprediatesymbolsaredistintfromfuntionsymbols.Nevertheless,theseprogramsanberunbyordinaryPrologsystemswhoseoperationalsemantisisbasedonLD-resolution,thatis,SLD-resolutionwiththeleftmostseletionrule.FortheoneptsofLD-resolution,LD-derivation,andLD-treethereadermayreferto(Apt1997)Theextensionoflogiprogrammingweonsiderinthispaper,allowsustowriteprogramswhihusegoalsasdata.Thisextensionturnsouttobeusefulforper-formingprogrammanipulationswhiharerequiredduringprogramtransformationandareotherwiseimpossible.Forinstane,wewillseethatbyusinggoalvariablesandgoalarguments,weareabletoperformgoalrearrangements(alsoalledgoalreorderingsin(Bossietal.1996))whihareoftenrequiredforfolding,withouta etingprogramterminationandwithoutinreasingnondeterminism.Goalrearrangementisalongstandingissueinlogiprogramtransformation.Indeed,althoughtheunfold/foldtransformationrulesbyTamakiandSato(1984)preservetheleastHerbrandmodel,theymayrequiregoalrearrangementsandthus,theymaynotpreservetheoperationalsemantisbasedonLD-resolution.Moreover,goalrearrangementsmayinreasenondeterminismbyrequiringthatprediateallsTransformationsofLogiProgramswithGoalsasArguments3havetobeevaluatedbeforetheirargumentsaresuÆientlyinstantiated,andinmanyPrologsystems,insuÆientlyinstantiatedallsofbuilt-inprediatesmayauseerrorsatrun-time.In(BossiandCoo1994)ithasbeenprovedthatbyrul-ingoutgoalrearrangements,ifsomesuitableonditionshold,thentheunfolding,folding,andgoalreplaementtransformationrulespreservetheoperationalseman-tisoflogiprogramsbasedonLD-resolutionand,inpartiular,theserulespreserveuniversaltermination,thatis,the nitenessofallLD-derivations(Apt1997;VasakandPotter1986).But,unfortunatel