Under consideration for publication in Theory and

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

UnderonsiderationforpubliationinTheoryandPratieofLogiProgramming1TransformationsofLogiProgramswithGoalsasArgumentsALBERTOPETTOROSSIDipartimentodiInformatia,SistemieProduzione,UniversitadiRomaTorVergata,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,weformallydenetheoperationalsemantisofourextendedlogiprogramminglanguage.ThissemantisisasimplevariantofLD-resolution.WhensuitableonditionsaresatisedthissemantisagreeswithLD-resolutionand,thus,theprogramswritteninourextendedlanguageanberunbyordinaryPrologsystems.Ourtransformationrulesareshowntopreservetheoperationalsemantisandtermi-nation.KEYWORDS:programtransformation,unfold/foldtransformationrules,higherorderlogiprogramming,ontinuations1IntrodutionProgramtransformationisaverypowerfulandwidelyreognizedmethodologyforderivingprogramsfromspeiations.Therules+strategiesapproahtoprogramtransformationwasadvoatedinthe1970sbyBurstallandDarlington(1977)fordevelopingrstorderfuntionalprograms.SinethenBurstallandDarlington’sapproahhasbeenfollowedinavarietyoflanguageparadigms,inludinglogiallanguages(TamakiandSato1984)andhigherorderfuntionallanguages(Sands1996).Thedistintivefeatureoftherules+strategiesapproahisthatitallowsustoseparatetheonernofprovingtheorretnessofprogramswithrespettospeiationsfromtheonernofahievingomputationaleÆieny.Indeed,theorretnessofthederivedprogramsisensuredbytheuseofsemantispreservingtransformationrules,whereastheomputationaleÆienyisahievedthroughthe2A.PettorossiandM.Proiettiuseofsuitablestrategieswhihguidetheappliationoftherules.Thepreservationofthesemantisisprovedoneandforall,forsomegivensetsoftransformationrules,andifwerestritourselvestosuitablelassesofprograms,weanalsoguar-anteetheeetivenessofthestrategiesforimprovingeÆ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-eedsinP2ithelistlonsistsof0’sonly.Programswithgoalvariablesandgoalarguments,suhasP1andP2intheaboveexample,arenotallowedbytheusualrstordersyntaxofHornlauses,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,withoutaetingprogramterminationandwithoutinreasingnondeterminism.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,thenitenessofallLD-derivations(Apt1997;VasakandPotter1986).But,unfortunatel

1 / 51
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功