Functional computations in logic programs

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

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

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

资源描述

FunctionalComputationsinLogicPrograms†SaumyaK.DebrayDepartmentofComputerScienceTheUniversityofArizonaTucson,AZ85721DavidS.WarrenDepartmentofComputerScienceStateUniversityofNewYorkatStonyBrookStonyBrook,NY11794Abstract:Whiletheabilitytosimulatenondeterminismandcomputemultiplesolutionsforasinglequeryisapowerfulandattractivefeatureoflogicprogramminglanguages,itisexpensiveinbothtimeandspace.Sinceprogramsinsuchlanguagesareveryoftenfunctional,i.e.donotproducemorethanonedistinctsolutionforasingleinput,thisoverheadisespeciallyundesirable.Thispaperdescribeshowpro-gramsmaybeanalyzedstaticallytodeterminewhichliteralsandpredicatesarefunctional,andhowtheprogrammaythenbeoptimizedusingthisinformation.Ournotionof‘‘functionality’’subsumesthenotionof‘‘determinacy’’thathasbeenconsideredbyvariousresearchers.Ouralgorithmislessreliantonlanguagefeaturessuchasthecut,andthusextendsmoreeasilytoparallelexecutionstrategies,thanothersthathavebeenproposed.CategoriesandSubjectDescriptors:D.3[Software]:ProgrammingLanguages;D.3.2[ProgrammingLanguages]:LanguageClassifications−nonprocedurallanguages;D.3.4[ProgrammingLanguages]:Processors−compilers,optimization;I.2[ComputingMethodologies]:ArtificialIntelligence;I.2.3[ArtificialIntelligence]:DeductionandTheoremProving−logicprogramming.hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh†ApreliminaryversionofthispaperwaspresentedattheThirdInternationalConferenceonLogicProgramming,London,July1986.ThisworkwassupportedinpartbytheNationalScienceFoundationundergrantnumberDCR-8407688.1.IntroductionInrecentyears,therehasbeenagreatdealofinterestinlogicprogramminglanguages,thebestknownofthesebeingProlog.Theabilitytosimulatenondeterminismisapowerfulfeatureofsuchlanguages.Itpermitsthesuccinctandreadilyunderstandableexpressionoflogicalalternativesthatrequirecomplexconstructsinmanyprogramminglanguages.However,theadditionalruntimesupportneededforthis,e.g.theabilitytorememberpreviousstatesandbacktracktothemonfailure,canincurasignificantover-head.Thisisespeciallyundesirablesincepredicatesinlogicprogramsareveryoftenfunctional,anddonotneedthisgeneralizedbacktrackingability.Knowledgeaboutthefunctionalityofpredicatescanbeusedtomakesignificantimprovementsinthespaceandtimerequirementsofaprogram.Knowingthatapredicateisfunctionalmaymakeitpossible,forexample,toavoidhavingtorecordasystemstatetobacktrackto,effectearlyreclamationofspaceontheruntimestack,andavoidunnecessarysearch.Traditionally,themeansofcontrollingProlog’ssearchhasbeenthroughcutsinsertedbythepro-grammer.This,however,makesprogramshardertounderstandandreasonaboutdeclaratively[20,22].Analternativeistotreatthecutasalow-levelprimitivethatshouldbeusedinfrequentlybytheprogram-mer,ifatall,butwhichmaybeintroducedbycompilersinthecourseofgeneratingoptimizedcodeforexecutioninasequentialenvironment.Inthisview,thecutisseen,notasalanguagefeatureintrinsictologicprogramming,butasanimplementationfeatureofsequentialProlog.(Itisnotobviouswhethercutsareveryusefulinparallelexecutionschemes.)Toemphasizethedistinctionbetweenuser-suppliedcutsandthosegeneratedbythecompiler,wewillrefertothelatteras‘‘savecp/cuttopairs’’(thereasonforthesenamesisdiscussedinSection5.1).Itthenbecomestheresponsibilityofthecompilertodeter-minewhichpartsoftheprograminvolveredundantsearchthatcanbeeliminatedbyinsertingsavecp/cuttopairs.Thispaperexploreswaysofdoingthisbyinferringfunctionalityofpredicatesandliterals.Aspecialcaseoffunctionality,thatofdeterminacy,hasbeeninvestigatedbyMellish[16],Naish[19]andSawamuraandTakeshima[23].DeransartandMaluszynski,takingadifferentapproach,havecharacterizedsuchbehavioroflogicprogramsintermsofattributegrammars,butintherestrictedsettingofdefiniteclauseprograms[DeransartMaluszynski1985].Theseauthorshavenotconsideredtherela-tionshipbetweenfunctionalcomputationsandnegationbyfailure,orinvestigatedconnectionswithdependencytheoryindatabases.AnotionsimilartothatoffunctionalityhasbeenconsideredbyMendel-zonintherestrictedsettingofdatabases,i.e.assumingthatfunctionsymbolsareabsent,andthatsomepredicatesaredefinedentirelybygroundfacts[17].Ourapproachisbothmoregeneralandlessopera-tional.Itdoesnotrelyexclusivelyonuser-suppliedcutstoinferfunctionality,therebypromotingwhatwebelieveisabetterprogrammingstyle.Italsoenablesustooptimizecertaincaseswhereaparticularcallofapredicatemaybefunctionaleventhoughthepredicateitselfisnot.Thereaderisassumedtobeacquaintedwiththebasicconceptsoflogicprogramming,anintroduc-tiontowhichmaybefoundin[14].Theremainderofthispaperisorganizedasfollows:Section2intro-ducesvariousconceptsthatareusedlaterinthepaper.Section3definesanddiscussesthenotionsoffunctionalityandmutualexclusion.Section4describesanalgorithmforthestaticinferenceof2functionality.Section5discussessomecompile-timeoptimizationsthatarepossiblewithknowledgeoffunctionality.Section6concludeswithasummary.2.Preliminaries2.1.TheLanguageThelanguageconsideredhereisessentiallythatoffirstorderpredicatelogic.Ithascountablesetsofvariables,functionsymbolsandpredicatesymbols,thesesetsbeingmutuallydisjoint.Eachfunctionandpredicatesymbolisassociatedw

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

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

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

×
保存成功