OutlineMotivationWhyisTablingofGeneralInterestDeniteProgramsAlgorithmsTablingApplicationsNormalProgramsAlgorithmsTablingApplicationsImplementation2 MotivationSolvesinadequaciesofPrologSL ID: 441774
Download Pdf The PPT/PDF document "TabledLogicPrograms:Principles,Practicea..." 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.
TabledLogicPrograms:Principles,PracticeandApplicationsC.R.RamakrishnanI.V.RamakrishnanKonstantinosSagonasTerranceSwiftDavidS.WarrenAnnotatedversionofTutorialSlidespresentedatJointInternationalConferenceandSymposiumonLogicProgramming,Bonn,Germany1996.1 OutlineMotivation:WhyisTablingofGeneralInterest?DenitePrograms:{Algorithms{TablingApplicationsNormalPrograms{Algorithms{TablingApplicationsImplementation2 MotivationSolvesinadequaciesofProlog(SLDNF){Terminationfore.g.Datalogprogramsancestor(X,Y):-parent(X,Y).ancestor(X,Y):-ancestor(X,Z),parent(Z,Y).{Redundantsubcomputationsjoin(X,Y):-supplemental(X,X2),rel_3(X2,Y).supplemental(X,Y):-rel_1(X,X1),rel_2(X1,Y).rel1 rel2 rel3 (a,b) (b,e) (e,g)(a,c) (c,e) (e,h)(a,d) (d,f) (f,i)InSLDresolution,8joinoperationsareperformedontheaboveexample,whileifsupplementalistabled,therewillbeonly6joinoperations.Inextremecases,redundantsubcomputationscanleadtoexponentialdatacomplexityforProlog.(Seetheknap-sackproblembelow).Tablinghaspolynomialdatacomplexityfordatalogprogramswithnegation.3 MotivationAllowsLogicProgrammingtobeusedwithdisk-residentdata.{Aditi[112],Validitybothhaveaset-at-a-timeinterfacetodisk.{Aschedulingstrategyfortablingisiterationequivalenttosemi-naiveevaluationofamagicprogram[44].4 MotivationTablingisapplicabletoprogramswithnegation.Infact,tablingcanalsohandleloopsthroughnegation.Itthuscanimplementthree-valuedsemanticsfornegationsuchastheWell-FoundedSemantics[114]{Allowslogicprogramstoadequatelyhandleinconsistencies.Thevillagebarbershaveseveryoneinthevil-lagewhodoesnotshavehimself[40].shaves(barber,Person):-villager(Person),notshaves(Person,Person).shaves(doctor,doctor).villager(barber).villager(mayor).villager(doctor).{AllowslogicprogrammingsystemstobeusedtoexploreKnowledgeRepresentation.{TablingasdenedbelowforWFShaspoly-nomialdatacompletity.5 MotivationTherehasbeenalotofresearchintoit.{TablingandRelatedResearchFormulation[41],[17],[108],[38],[60],[98],[115],[120],[15],[14],[20],[22],[33],[19],[105],[34],[94],[54],[110],[23],[27]ImplementationandSystems[6],[116],[64],[42],[2],[55],[82],[84],[106],[107],[93],[7],[21],[43],[44],[96],[121],[45],[83],[95][92],Optimizations[30]6 Motivation{MagicSetsandRelatedResearch(e.g.Alexan-derMethod)Formulation[87],[5],[97],[111],[18],[69],[67],[8],[59],[73],[103],[39],[49],[79],[9],[101],[89][66]ImplementationandSystems[6],[24],[112],[80],[99],[118],[119],[37],[48],[52],[68]Optimizations[78],[70],[90],[91],[88],[61],[102],[51],[50],[104],[16]Bibliographyisincomplete:{itconsidersonlyformulationsofevaluationstrategiesandnotgeneraltheoriesofDatalog,updates,etc.{DoesnotconsidersomenewerareassuchasTabling/MagicSetsandconstraints.7 MotivationPracticalandResearchApplications{Parsing[72],[1],[63],[62]{ProgramAnalysis[71],[58],[57],[86],[31]{SoftwareVerication[100]{GraphicsandDataVisualization[46],[26]{DiagnosisSystems[32],[28]{Other[13],[77]SQL3Standardincludesrecursion.8 DeniteProgramsManyformulationsoftablingaremoreorlessequiv-alentfordeniteprograms.EarleyDeduction(1970)BackchainIteration(1981)OLDT(1986)AlexanderMethod(1986)SLD-AL(QSQR)(1986-1989)MagicTemplates(1986-88)ExtensionTables(1987)SLG(1993)LogicPushDownAutomata(1994)ATabledEvaluationcanbecharacterizedbyOperationsplusaSearchStrategy.9 DenitePrograms q(a). q(b). q(c).e(a,b). e(a,d). e(b,c).p(X,Z) :- p(X,Y),p(Y,Z).:- table p/2. SubgoalAnswers10 DenitePrograms11 DenitePrograms12 DenitePrograms:TablingThesearchstrategyforthatprogramwasatuple-at-a-timestrategyresemblingProlog's[45].Onederivationpath(ortree)mayneedtocon-sumeanswersfromanotherderivationpath(ortree)Maybemorethanoneanswerforagiventabledsubgoal13 DenitePrograms:TablingFornitecomputations,atabledevaluationcanbeseenasasequenceofforests.GivenaforestFanewforestisdeterminedbyoneofthefollowingoperations.Denition1newsubgoal.GivenanodeNwithselectedtabledliteralB,whereBisnotinF,createanewtreewithrootB.programclauseresolution.GivenanodeNthatisarootnodeB,orhasselectednon-tabledliteralB,resolveagainstBapro-gramclausethathasnotpreviouslybeenusedforresolutionagainstBinN.answerresolution.GivenanactivenodeNwithselectedliteralB,resolveanansweragainstBthathasnotbeenpreviouslyusedforresolutionagainstBinN.completionIfSisasetofsubgoalsthathavebeencompletelyevaluatedremovealltreeswhoserootisasubgoalinS.Non-failurenodeshavetheformAnswer Template: goal listThestatusofanode|active,interiororan-swer|isdeterminedrespectivelybywhetherthe14 selectedliteralofthenodeistabled,non-tabled,orifthegoal listisempty.15 DenitePrograms:TablingWhatdoesCompletelyEvaluatedmean?Asubgoaliscompletelyevaluatediithasallofitspossibleanswers.AsubgoalSiscompletelyevaluatedwhenallpossibleoperationshavebeendoneonitsnodes,andthenodesoftreesuponwhichSdepends.Agroundsubgoaliscompletelyevaluatedwhenananswerisderivedforit.IncrementalCompletionisnecessaryforecientevaluationofprograms.16 DenitePrograms:Tabling17 DenitePrograms:TablingSubgoalDependencyGraph IncrementalCompletioncanbeperformedaSCCatatime,orasetofSCCsatatime.18 DenitePrograms:MagicMagicprovidesterminationpropertiessimilartotabling,alongwithgoalorientation.Howisapro-gramevaluatedusingMagic?Considersg(X,Y):-X=Y.sg(X,Y):-p(X,Z),sg(Z,Z1),p(Y,Z1).Magicusuallyassumesabottom-upevaluationstrategysuchassemi-naive.Thisstrategyitera-tivelyderivesadeltasetofpreviouslyunderivedanswers,andplugstheseanswersintoappropriateplacesintheprogramtocreateanewdeltaset.19 DenitePrograms:MagicSplitprogramupintoEDBandIDB.AddaltertothebeginningofeachIDBclausetomakesurethatwhenevertheclauseisacti-vated,itwillhavethesamebindingsasinatop-downevaluation.sg(X,Y):-call(sg(X,Y)),X=Y.sg(X,Y):-call(sg(X,Y)),p(X,Z),sg(Z,Z1),p(Y,Z1).Makesurethatthepropercallingltersarede-rived.call(sg(Z,Z1)):-call(sg(X1,X)),p(X,Z).Addamagicseedtorepresenttheoriginalquery.call(sg(1,X)).Thisisonlyasimpleversionofmagic.20 DenitePrograms:MagicPerformalinearsemi-naiverewriteofthemagicprogram:call(sg(1,X)).call(sg(Z,Z1)):-delta_call(sg(X1,X)),p(X,Z).sg(X,Y):-delta_call(sg(X,Y)),X=Y.sg(X,Y):-delta_call(sg(X,Y)),p(X,Z),sg_t-2(Z,Z1),p(Y,Z1).sg(X,Y):-call_t-1(sg(X,Y)),p(X,Z),delta_sg(Z,Z1),p(Y,Z1). Eachderivedpredicatecanbethoughtofasconsistingofasequenceofthedelta-setsproducedateachiteration.Thus,thesetoffactsavailableattheendofiterationtconsistsofthersttdeltasetsforeachpredicate.Attimet,thesecondrulewilljoincallsrstproducedattimet 1(delta call/1)withappropriatesg/2factsfromt 2.21 Attimet,thethirdrulewilljoinallcallsproducedbytheendoft 1withthesg/2factsrstproducedattimet 1.22 DenitePrograms:MagicAddasimpleEDBtotheprogram:call(sg(1,X)).call(sg(Z,Z1)):-delta_call(sg(X1,X)),p(X,Z).sg(X,Y):-delta_call(sg(X,Y)),X=Y.sg(X,Y):-delta_call(sg(X,Y)),p(X,Z),sg_t-1(Z,Z1),p(Y,Z1).sg(X,Y):-call_t(sg(X,Y)),p(X,Z),delta_sg(Z,Z1),p(Y,Z1).p(1,3).p(1,4).p(2,3).p(2,4). Iteration0:call(sg(1;Y))added(magicseed).Iteration1:sg(1;1),call(sg(3;Y)),call(sg(4;Y))added.Iteration2:sg(3;3),sg(4;4)added.Iteration3:sg(1;2),sg(1;1)eachderivedtwice,sg(1;2)added.Iteration4:Fixpoint.23 DenitePrograms:GrammarsConsiderthegrammarexpr--expr+termexpr--termterm--term*factorterm--factorfactor--(expr)factor--integer(Int)24 DenitePrograms:GrammarsAtranslationintoProlog-styleDCGs.expr--term,addterm.addterm--[].addterm--[+],expr.term--factor,multfactor.multfactor--[].multfactor--[*],term.factor--[I],{integer(I)}.factor--['('],expr,[')'].theprogrammerhasexecutedleft-recursioneliminationandleft-factoring.grammarnowhasright-associativeoperatorsratherthantheleft-associativeoperatorsoftheoriginalgrammar.25 DenitePrograms:GrammarsThesamegrammarusingtabling.:-tableexpr/2,term/2.expr--expr,[+],term.expr--term.term--term,[*],factor.term--factor.factor--['('],expr,[')'].factor--[Int],{integer(Int)}.Syntacticvariantoforiginalgrammar.Hasnoassociativityproblem26 DenitePrograms:GrammarsApplyingtablingtoaDCGgrammarcaneec-tivelygiveEarleyParsing[41]{SupplementaryTabling(SupplementaryMagic)canconvertthegrammartoChomskyNormalForm1.EarleyParsingofgrammarsinChomskyNormalFormtakesatmostO(N3)forambiguousgram-mars;atmostO(N2)forunambiguousgram-mars;andislinearforalargeclassofgrammars.AdditionaloptimizationssuchasLeftFactoringcanbeperformedbyCRAoptimizationsasde-scribedin[30]. 1ImplementingEarley'sDottedRules.27 DenitePrograms:GrammarsItisecienttorepresentsentencesinDatalogwhenusingtabling(seebelowinImplementa-tion).'C'(every,0,1).'C'(man,1,2).'C'(loves,2,3).'C'(a,3,4).'C'(woman,4,5).Tabling(andEarleyParsing)oerusefulcom-plexityadvantagesforothergrammaticalformalismssuchascategorialgrammars[1].28 DenitePrograms:DynamicProgrammingTheminimumeditdistanceproblem:ndthemin-imumnumberofinsertions,deletions,orreplace-mentstoturnonestringintoanother.:-tablemed/3.med(0,0,0).med(0,M,M):-M0.med(N,0,N):-N0.med(N,M,C):-N0,M0,N1isN-1,M1isM-1,med(N1,M,C1),C1aisC1+1,med(N,M1,C2),C2aisC2+1,med(N1,M1,C3),a(N,A),b(M,B),(A==B-C3a=C3;C3aisC3+1),min(C1a,C2a,Cm1),min(Cm1,C3a,C).c.f.[65]pg.153{154foranequivalentimperativesolution.29 DenitePrograms:DynamicProgrammingSolutionstomed/3recursivelycreateaMNarray:30 DenitePrograms:DynamicProgrammingTheknap-sackproblem:Givennitems,eachofintegersizeki(1n),andaknap-sacksizeK.determinewhetherthereisasubsetoftheitemsthatsumstoK.Findsuchasubset.31 DenitePrograms:DynamicProgrammingAPrologsolutiontotheknapsackproblem.ks(0,0).ks(I,K):-I0,I1isI-1,ks(I1,K).ks(I,K):-I0,item_size(I,Ki),K1isK-Ki,K1=0,I1isI-1,ks(I1,K1).item_size(1,2).item_size(2,3).item_size(3,5).item_size(4,6).Worst-casecomlexityis2I.32 DenitePrograms:DynamicProgrammingAtablingsolutiontotheknapsackproblem.:-tableks/2.ks(0,0).ks(I,K):-I0,I1isI-1,ks(I1,K).ks(I,K):-I0,item_size(I,Ki),K1isK-Ki,K1=0,I1isI-1,ks(I1,K1).item_size(1,2).item_size(2,3).item_size(3,5).item_size(4,6).Worst-casecomplexityisI2.33 DenitePrograms:DynamicProgrammingButhowdoyoundthesubset(s)?ksp(0,0,[]).ksp(I,K,P):-I0,I1isI-1,ks(I1,K),ksp(I1,K,P).ksp(I,K,[I|P]):-I0,item_size(I,Ki),K1isK-Ki,K1=0,I1isI-1,ks(I1,K1),ksp(I1,K1,P).Notethatks/2doesnotrepeatcomputations.cf.[65]pg.110foranequivalentimperativesolution.34 DenitePrograms:DynamicProgrammingNotethatwiththegoal-orientationoftabling,incertainproblemsitmaynotbenecessarytobuildanentirearray.OnesuchcaseoccurswhentablingisusedintheUnicationFactoringcom-pileroptimization[29].[48]oersotherapproachestodynamicprogram-mingusingtabling.35 DenitePrograms:ApplicationsProgramAnalysisExpoitstheabilityoftabledevaluationtondminimalmodelsofdeniteprogramsGeneralStrategy:AbstractCompilation(e.g.,see[35,53]){Fromagivensource(concrete)program,obtainanab-stractprogram.{Concretesemanticsofabstractprogramabstractsemanticsofconcreteprogram.{Evaluateabstractprogramusingsomecompleteeval-uationstrategy.36 Applications:ProgramAnalysisExample:GroundnessAnalysis(from[25])append([],Ys,Ys).append([X|Xs],Ys,[X|Zs]):-append(Xs,Ys,Zs).+g_append(g,Y,Y).g_append(X1,Ys,Z1):-iff(X1,X,Xs),iff(Z1,X,Zs),g_append(Xs,Ys,Zs).iff(g,g,g).iff(n,n,n).iff(n,n,g).iff(n,g,n).Eleganceofformulation(\specication-based").Easeofimplementation.Appliestoimperative[85],functional[31]andlogic[25]programanalysis.Ecientenoughforsimplelogicandfunctionalprogramanalysis[31]tobeputincompilers.37 Applications:ProgramAnalysisSemanticequationscanbeexpressedasmetapro-gramsExample:Whileprogramsinterp(S 1;S 2)--interp(S 1),interp(S 2).interp(ifEthenS telseS f)--expr eval(E,Val),Val==true-interp(S 1);interp(S 2).interp(whileEdoS)--expr eval(E,Val),Val==true-interp(S),interp(whileEdoS);[]interp(X:=E)--expr eval(E,Val),store(Val,X)....expr eval((E 1+E 2),Val)--......38 Applications:ProgramAnalysisGeneratingabstractprograms:ExpressabstractsemanticsasmetaprogramsPartiallyevaluateabstractsemanticequationswrt.input(concrete)program39 MetaprogrammingandTablingPowerofcombiningmetaprogrammingwithtablingyieldsabilitytoexpressavarietyofsemantics.Applications:ProgramanalysisModelchecking(seeCCS,below)ConstraintlanguagesKnowledgerepresentation(seeNegation,below)40 DenitePrograms:ApplicationsCCSasaHornProgram:(Y.S.Ramakrishna):-tabletrans/3.%Prefix:Act.PAct-Ptrans(pref(Act,P),Act,P).%Choice:P=P1+P2trans(choice(P,_Q),Act_a,P1):-trans(P,Act_a,P1).trans(choice(_P,Q),Act_a,Q1):-trans(Q,Act_a,Q1).%Parallel:P=Q|Rtrans(par(P,Q),Act_a,par(P1,Q)):-trans(P,Act_a,P1).trans(par(P,Q),Act_a,par(P,Q1)):-trans(Q,Act_a,Q1).%RepresentCoactionstrans(par(P,Q),tau,par(P1,Q1)):-trans(P,Act_a,P1),trans(Q,Act_b,Q1),comp(Act_a,Act_b).trans(par(P,Q),tau,par(P1,Q1)):-trans(P,Act_a,P1),trans(Q,Act_b,Q1),comp(Act_b,Act_a).%Restriction:P\LAct-P1\Ltrans(rest(P,L),Act_a,rest(P1,L)):-trans(P,Act_a,P1),legitimate_action(Act_a,L).%Relabelling:P=Q[f]trans(relab(P,Hom_f),Act_b,relab(P1,Hom_f)):-trans(P,Act_a,P1),map(Hom_f,Act_a,Act_b).41 %TransitiveRedefinitiontrans(P,Act_a,Q):-def(P,R),trans(R,Act_a,Q).42 Applications:ProgramAnalysisThepreviousmeta-interpreter,whencombinedwithamodelcheckingalgorithmcanbeusedforvericationofconcurrentsystems.Timeandspaceutilizationareroughlycompa-rablewithspecial-purposemodelcheckers43 DenitePrograms:TopicsinDeniteTablingRecallthatatabledevaluationcanbecharacter-izedbyoperationsplusscheduling.ChangesinScheduling:LocalandBreadth-FirstChangesinOperations:CheckingforVariancevs.Subsumption44 DenitePrograms:SchedulingTabledevaluationshavenewsubgoaloperationandanswerresolutionoperationwhichmustbescheduledalongwiththeprogramclauseresolutionstepofSLD.Canreturnanswersassoonastheyarederived,orpostponetheirreturn.Cancreateanewtreeassoonasthereisase-lectedliteralforit,orpostponethisoperation.Prolog'sstrategyisapproximatedbypostponingneitherthereturnofanswersorthecreationofnewtrees.PostponinganswerreturnoutofanSCCuntilanSCCiscompletelyevaluatedgiveslocaleval-uation[45].Postponingbothoperationsuntiltheendofaniteration,givesbreadth-rstevaluation,typi-45 calofsemi-naivemagicevaluations.(JointworkwithJ.Freire).46 DenitePrograms:TablingandMagicConsideratuple-at-a-timeevaluationofsame-generation47 DenitePrograms:TablingandMagicNowconsideraset-at-a-timeevaluationInparticular,thisishowasemi-naiveevaluationwouldevaluateamagic-rewrittensame-generationprogram.48 DenitePrograms:TablingandMagicRelationshavebeenoftenstudied:[111],[18],[103],[15],[106],[36].AsymptoticallyEquivalent:Aversionofmagictemplatesundernaiveevaluationisasymptot-icallyequivalenttoaversionofQSQRtabling[97].IterationEquivalent:Aversionofmagictem-platesundersemi-naiveevaluationisasymptot-icallyiterationequivalenttoaversionoftabling[45].Thismeans{Ateachiterationamagicfactisaddedifanewsubgoaliscalled{Ateachiterationanon-magicfactisderived(added)ifanewanswerisderived(added).49 DenitePrograms:TablingandMagicTablingstartsfromresolutionandisaprogram-mer'sviewofcombiningtop-downandbottom-up.Magicstartsfromsemi-naiveevaluationandisadatabasequeryprocessor'sviewofcombiningtop-downandbottom-up.Tablingcapturesdisk-accessmethodsofmagicviaBreadth-FirstTabling.MagiccapturesthedynamicdependenciesoftablingviaOrderedSearch[79]Bothallowsubsumptionorvarianceofcallsoranswers.Re\rectionsinafun-housemirror?50 DenitePrograms:OperationsTheoperationsmentionedbeforeassumedavari-antcheckforsubgoalsandanswers.Alternatelyonecouldusesubgoalsubsumptionoranswersubsump-tion.Considertheprogramp(X):-p(f(X)).p(a).Minimalmodelisfp(a)g.Aspreviouslydened,thetablingevaluationofaquery?-p(X)wouldcreateaninnitenumberoftrees.p(X),p(f(X)),p(f(f(X))),...Subgoalsubsumptionaddressesthisproblem.51 DenitePrograms:SubgoalSubsumptionDenition2newnon-subsumedsubgoal.GivenanodeNwithselectedtabledliteralB,whereBisnotsubsumedbyasubgoalinF,createanewtreewithrootB.Theorem1LetPbeaprogramwithanitemodelinwhicheverypredicateistabled,andEbeanevaluationconsistingofnewnon-subsumedsubgoal,programclauseresolution,an-swerresolutionandcompletion.ThenEwillcorrectlyterminateafteranitenumberofoperations.Originallystatedin[108]usingOLDTformal-ism.52 DenitePrograms:SubgoalSubsumptionSubgoalSubsumptioncanalsobeofuseforDat-alogprogramsConsiderasame-generationprogram.sg(X,X).sg(X,Y):-sg(Y,X).sg(X,Y):-up(X,X1),sg(X1,X2),down(X2,Y).53 DenitePrograms:SubgoalSubsumptionForthequerysg(f;f)(X;Y)theannotationissg(f,f)(X,X).sg(f,f)(X,Y):-sg(f,f)(Y,X).sg(f,f)(X,Y):-up(X,X1),sg(b,f)(X1,X2),down(X2,Y).sg(b,f)(X,X).sg(b,f)(X,Y):-sg(f,b)(Y,X).sg(b,f)(X,Y):-up(X,X1),sg(b,f)(X1,X2),down(X2,Y).sg(f,b)(X,X).sg(f,b)(X,Y):-sg(b,f)(Y,X).sg(f,b)(X,Y):-up(X,X1),sg(b,f)(X1,X2),down(X2,Y).54 DenitePrograms:AnswerSubsumptionDenition3(non-subsuming)answerresolution.GivenanactivenodeNwithselectedliteralB,resolveananswerAagainstBif{AthathasnotbeenpreviouslyusedbyN.{AisnotsubsumedbyanyotheranswerinthetreeforB.Thistendstobemostusefulwhensubsumptionisusedonapartialorderotherthanthatofterms.Inthe3-valuedinformationorderingtrueandfalsearegreaterthanundened.Therefore,trueanswerssubsumeundenedanswers.Subsumptioncanbegeneralizedtoimplicationforbothsubgoalsandanswers.Inanappropriateconstraintdomainp(X):(X2))p(X):(X3)55 DenitePrograms:AnswerSubsumptionAnswerSubsumptionmodelsminandmaxag-gregateoperators.Example:ndtheshortestdistancebetweentwopeopleinthesamegeneration.sgi(X,X)(0).sgi(X,Y)(I):-anc(X,Z),subsumes(min)(sgi(Z,Z1),I1),anc(Y,Z1),IisI1+1.:-subsumes(min)(sgi(joan,carl),I).56 Variancevs.SubsumptionCallVariance+AnswerVariancegivesProlog-styleobservablesthataresuitableformeta-interpretation.CallVariance+AnswerSubsumptionisusefulfornon-stratiednegation.Callvarianceinnon-\rounderingprogramsavoidsconstructivenega-tion.Answersubsumptionisusedtohandleun-certainanswers.CallSubsumptionisusefulforminimalmodelcomputationsofdeniteorstratiedprograms.57 TablingProgramswithNegationRealisticprogramsusenegation,howisnegationcombinedwithtabling?CanthegreaterexpressivepoweroftablingalsobeusedasabasisforaLogicProgrammingim-plementationsofNon-MonotonicReasoning?Intuition:Thewell-foundedsemantics(WFS)treatsallpathswithinnitepositiverecursionasfailed,andallpathswithinniterecursionthroughnega-tionasundened.Thustheloop-checkingfeaturesoftablingcanbeusedtoevaluateWFS.58 NegationThefollowingprogamusesnegationinastraight-forwardway,butmaycausePrologtogointoaninniteloop.get_best_choices(Course,Teacher,Final):-can_teach(Course,Initial_choice),best_choice(Course,Initial_choice,Final_choice).best_choice(Course,Teacher,Teacher):-notbetter_choice(Course,Teacher).best_choice(Course,Teacher,Final):-just_as_good_choice(Course,Teacher,Other),best_choice(Course,Other,Final).better_choice(Course,Teacher):-can_teach(Course,Teacher1),not(Tearcher1=Teacher),rates(Course,Teacher1,Rank1),rates(Course,Teacher,Rank),Rank1Rank.just_as_good_choice(Course,Teacher,Other):-can_teach(Course,Other),not(Other=Teacher),rates(Course,Other,Rank1),rates(Course,Teacher,Rank),59 Rank1=Rank.60 Negation:TowardsWFSthroughstratication61 Negation:TowardsWFSthroughstraticationLowerstraticationclassesarecomputedbyDeterminingadependencygraph(DG)Determiningwhethercomponentsinthedepen-dencygraphcontaincyclesthroughnegationExamples:PredicateStratication[4]:singleDGforentireprogram,basedonpredicatedependencies.LocalStratication[75]:singleDGforentire(grounded)program,basedonatomdependen-cies.62 Negation:TowardsWFSthroughstratication63 Negation:TowardsWFSthroughstraticationThebasicideaofformingadependencygraphandcheckingforloopsthroughnegationisperformedit-erativelyinthehigherstraticationclassessuchasmodularstratication[89]andweakstratication[74].Weconsiderthehighestofthese,DynamicStratication[76,11]indetail.ThepowerofDynamicstraticationcanbeseenfromthefollowingtheoremTheorem2[76]AprogramisDynamicallyStratiediithasatwo-valuedwell-foundedmodel.64 Negation:DynamicStraticationDynamicstraticationiterativelyndsaninter-pretationIforagroundprogram,andreducestherestoftheprogramwithrespecttoI.StartwithI0=;Ah:-A1;:::;Am;notAm+1;:::;notAnTodeterminepositivefactsndtheleastxpointoftheoperator{TI(T)=fA:thereisaclauseB L1;:::;LninPandagroundsubstitutionsuchthatA=Bandforevery1neitherLiistrueinI,orLi2Tg;Todeterminenegativefacts,ndthegreatestxpointoftheoperator{FI(F)=fA:foreveryclauseB L1;:::;LninPandagroundsubstitutionsuchthatA=Bandthereissome(1n),suchthatLiisfalseinIorLi2Fg.65 NegationConsidertheprogram:p(b).p(c):-notp(a).p(X):-t(X,Y,Z),notp(Y),notp(Z).t(a,b,a).t(a,a,b).thegroundinstantiationofthisprogramis:p(b).p(c):-notp(a).p(a):-t(a,a,a),notp(a),notp(a).p(a):-t(a,a,b),notp(a),notp(b).:p(a):-t(a,b,a),notp(b),notp(a).:p(c):-t(c,c,c),notp(c),notp(c).t(a,b,a).t(a,a,b).66 NegationTherstpartialmodel,I0is;sotheoperatorseectivelyworkontheprogramp(b).p(c):-undef.p(a):-t(a,a,a),undef,undef.p(a):-t(a,a,b),undef,undef.:p(a):-t(a,b,a),undef,undef.:p(c):-t(c,c,c),undef,undef.t(a,b,a).t(a,a,b).WhosexpointgivesI1inwhichItrue1=fp(b);t(a;a;b);t(a;b;a)garetrueandIfalse1=ft(a;a;a);t(a;a;c);:::g67 arefalse.68 NegationThusthesecondreductionisp(c):-undef.p(b).t(a,b,a).t(a,a,b).NowItrue2=Itrue1,whileIfalse2=Ifalse1[fp(a)g,andthethirdreductionisp(c).p(b).t(a,b,a).t(a,a,b).Whichaddsp(c)toItrue3.FurtheriterationswillnotchangeI3,whichis,infact,amodelfortheprogram.Anyundenedliteralsattheendofthisitera-tiveprocessmaybesaidtobeintheultimatestratum.69 NegationThemethodjustshownwaspurebottom-up.Tomakeitgoal-orientedrequiresanotionofrel-evance.Assumingaleft-to-rightcomputationrule:{InProlog,relevantliteralsforaselectedclausebelongtoafailingprex.p(a):-t(a,b,a),notp(b),notp(a).{Togetthisdynamicstraticationanevalua-tioncannotviewonlyaprex.p(a):-t(a,a,b),notp(a),notp(a).Arerelevantliteralsallthoseinabodyforaselectedclause?70 Negation71 Negation72 Negation73 NegationTheseoperationscanbeexpressedinSLG-styleterminologyasfollows:negativereturnGivenanodeN:Answer template Delay listjnotB;Goal listwhereBistrueinFcreateafailurenodeasthechildofB.IfBisfailed,createauniquechildAnswer template Delay listjGoal listwithappropriatestatus.delayGivenanodeN:Answer template Delay listjnotB;Goal listdelayevaluationofnotBbycreatingachildofN:Answer template notB;Delay listjGoal listsimplificationGivenananswerAwhosede-laylistcontainsaliteralL,ifListrueinF,removeLfromthedelaylistofA.IfLisfalseinF,removeAfromthetable.74 NegationIsthisprogrammingorspecication?Left-to-rightdynamicstraticationallowsonlyfail-ingprexesFMi(F)=fA:foreveryclauseB L1;:::;LninPandagroundsubstitutionsuchthatA=Band(1)issome(1n),suchthatLiisfalseinMiorLi2F;(2)thereexistsafailingprex:forallj(1j 1),LjistrueinIg.ByadjustingtheoperationsofSLG,atablingstrategySLGRDcanbeformulatedwiththefol-lowingproperty.Theorem3[94]GivenagroundprogramP,anSLGRDevaluationwillonlydelayonencounter-ingaliteralintheultimateleft-to-rightdynamicstratum.Weconjecturethatasimilartheoremispossible75 forotherformalismssuchasWell-FoundedOrderedSearch[101].76 Meta-InterpretinginWFSTometa-interpretaprogramwithloops,tablethemeta-interpreter.:-tabledemo/1.demo(true).demo(','(A,B)):-!,demo(A),demo(B).demo(notA):-!,notdemo(A).demo(A):-clause(A,B),demo(B).NoteUseofcutswithtabledpredicates77 NegationAmeta-interpreterforwell-foundedsemanticswithexplicitnegation(WFSX)[3]demo(_)(true).demo(X)(','(A,B)):-!,demo(X)(A),demo(X)(B).demo(t)(not(A)):-!,not(demo(tu)(A)).demo(tu)(not(A)):-!,not(demo(t)(A)).demo(t)(A):-rule(A,B),demo(t)(B).demo(tu)(A):-rule(A,B),demo(tu)(B),exchange(A,A_opp),demo(tu)(not(A_opp)).exchange(-B,B):-!.exchange(B,-B).NoteuseofHilogandTabling78 NegationSimilarmeta-interpreterstransformationscanbeperformedforHead-CycleFreeDisjunctiveLogicPrograms[10]GeneralizedHornPrograms[12]ExtendedDatabases[117,109]ImexNegation[56]ArestrictiontoWFSoftheactionlanguageA[47].Tablingcanalsobeusedasapreprocessorforstablemodelcomputations.79 NegationAnExtendedLogicProgram(C.Damasio)perforation(X)-sudden_pain(X),abd_tenderness(X),peritoneal_irritation(X),not_believedhigh_amylase(X).pancreatitis(X)-sudden_pain(X),abd_tenderness(X),peritoneal_irritation(X),not_believedjobert(X).-nourish(X)-perforation(X).-nourish(X)-pancreatitis(X).h2_antagonist(X)-pancreatitis(X).h2_antagonist(X)-perforation(X).surgery_indication(X)-perforation(X).-surgery_indication(X)-pancreatitis(X).80 anesthesia(X)-surgery_indication(X).81 NegationSupposeapatientcomesinwithsudden_pain(patient)-true.abd_tenderness(patient)-true.peritoneal_irritation(patient)-true.AparaconsistentmodelisderivedIndicationsarecontradictory.Thepatienthasbothaperforationandpancreatitis.Asaresult,thereisanindicationforsurgeryandanindica-tionagainst.Nonetheless,thepatientshouldbegivenh2 antagonistsandshouldnotbenourished.82 NegationSupposeanamylasetestisperformedandcomesbackhigh.Thenthebeliefintheperforationwillbewith-drawn,aswillthesurgeryindication.Alternatively,supposetheuserdidnotwanttomakeanepistimologicalcommitmentaboutJobert'sSyndrome.Dene:jobert-unknown.whereunknown-notunknown.pancreatitis(patient)wouldthereforehavetruth-valueunknown.Thedelayedclausewouldbepancreatitis(patient):-believed notjobert.Therearefourtruthvaluestouse:true,false,bothandneither.83 ImplementationofTablingSomeImplementationsofTablingSemi-NaiveModel:Coral,Aditi,LDL,LogicBaseWAMModel:PortableSLG,XSB2,[81]providesarelativelyrecentsurvey.Currently:SystemsbasedontheWAMmodelareaboutanorderofmagnitudefasterforin-memorydata,andhaveatighterintegrationwithProlog.Systemsbasedonthesemi-naivemodelhaveatighterintegrationwithdisk. 2TablingfeaturesinXSBwereimplementedbyJ.FreireandP.Raoalongwiththeauthors.84 ImplementationofTablingFeaturesnecessaryfortabling(fromaPrologper-spective).Mechanismtosuspendandresumeacomputa-tionMechanismtoaccesstablesMechanismtodetect(incremental)completionMechanismtohandleundenedliteralsinaclause85 ImplementationofTablingIssue:SuspensionandResumptionofsubgoals.Suspensionisusedtowaitforanswers,towaitforinformationaboutanegativesubgoalortodelaythestartofanewtree.Resumingisnecessarytoreturnanswers,tore-turninformationaboutanegativegoal,ortocreateatreeforasuspendedsubgoal.Thevarioustablingstrategies|batched,local,breadth-rst|arere\rectedattheimplementa-tionlevelbysuspendingandresumingcomputationpaths.Semi-naivecanalsobeseenasaparticularwaytosuspendandresumecomputations.AWAM-basedstrategycanresumesuspendedenvironmentsby{re-executingacomputationpath;or{restoringacomputationpathusingaforwardtrail.86 ImplementationofTabling:TableAccessMechanismsSubgoalCheck/Insert{Tabling:new(non-subsuming)subgoal{Magic:CreatingadeltasetofmagicfactsAnswerCheck/Insert{Tabling:Interningananswerinthetable{Magic:Creatingadeltasetofnon-magicfactsAnswerBacktracking{Tabling:(non-subsuming)answerresolution{Magic:Joiningadeltasetofmagicornon-magicfacts.ExamplesofImplementationStructuresCoraluseshash-consedvaluesforgroundterms.XSBusestries(ImplementedbyP.Rao[84]).87 ImplementationofTabling:TableAccessrt(b,V,d)rt(a,g(b,c),c)rt(a,f(a,b),a)rt(a,f(a,V),V)Triesallowcheck/insertinasinglepassandmakestheduplicatechecknearlycostless.88 ImplementationofTablingIssue:Howtoincrementallycompleteatable.XSBusesastack-basedmechanism[21]VanillaMagicusesastaticallydenedcontrolstrategy.Orderedsearchusesadynamiccontrolstrategy[79]Issue:Howtohandleunknown/undenedliteralsOneissueinvolvesdynamicallychangingthecom-putationruleAsecondissueinvolvesrepresentingatomsthatareneithertruenorfalse.XSBimplementsdelayandsimplication[95]WFOS[101]usestheAlternatingFixpointof[113]89 ImplementationofTabling:OptimizationsTablingisweakforacyclicright-recursivequeriesLeft:ancestor(X,Y):-parent(X,Y).ancestor(X,Y):-ancestor(X,Z),parent(Z,Y).Right:ancestor(X,Y):-parent(X,Y).ancestor(X,Y):-parent(X,Z),ancestor(Z,Y).WhatifparentisachainoflengthN?ThenNcalls:a(1,X),a(2,X),a(3,X),...,a(n,X)ButO(N2)answersa(1,2),a(1,3),a(1,4),...,a(1,n)a(2,3),a(2,4),...,a(2,n)a(3,4),...,a(3,n):a(n-1,n)90 ImplementationofTabling:OptimizationsApproachestorightrecursionproblemIftherecursionisacyclicandnon-repeating,useSLD!UseTail-recursionoptimizationtoonlyreturnanswerstotheoriginalquery.Linearinnumberofanswersinthisexample.[88],[16].Transformrightrecursionintoleftrecursionifpossible,usingNRSU-factoring[70].{Thisstrategyworksforrightrecursionunderallqueryforms,butdoesnotworkforin-stance,forsamegenerationorfortherightrecursionsintheCCSexample.91 ImplementationofTablingCopyAvoidanceStructuralrecursionisacyclicforProlog-styletermsappend([],L,L).append([H|T].L,[H|T1]):-append(T.L,T1).whichcanbeseentohavearightrecursiveform:append([],L,L).append(Term.L,[H|T1]):-cons(Term,H,T),append(T.L,T1).Considerthequeryappend([a,b,X],[c],Y).Thefollowingqueriesaremadeappend([a,b,X],[c],Y).append([b,X],[c],Y).append([X],[c],Y).append([],[c],Y).Stillquadraticinthesizeoftherstargumentifyoumustcopyfromexecutionareatotable.Otherpossiblesolutions:InternGroundStructuresinTable92 Can,inprinciple,usestructure-sharingtechniquesfornon-groundterms.[33][104].93 ImplementationofTablingjoin(X,Y):-supplemental(X,X2),rel_3(X2,Y).supplemental(X,X2):-rel_1(X,X1),rel_2(X1,X2).Wherejoin/2andsupplemental/2aretabled,maybemoreecientthanjoin(X,Y):-rel_1(X,X1),rel_2(X1,X2),rel_3(X2,Y).AsimpleoptimizationconsistsoffoldingEDBpredicatesintonewtabledpredicates.ThisiscalledSupplementalMagicSets[8]orSupple-mentalTabling.BothrediscoverEarley'sobservationthatthecom-plexityofgrammarprocessingisproportionalto94 thenumberofnon-terminalsontheRHSofaproduction[41].95 SummaryTablingandMagicareusuallydierentformula-tionsofthesamealgorithms.Tablingthuspro-videsapotentialwaytopeformdiskaccesse-cientlyfromalogicprogram.TablingcanbetightlycoupledwithProlog,sothatitispossibletoprogramwithtablingTablingprovidesapropercomputationalbasisforcertainformsofNon-monotonicreasoning.Tablingaddspowertologicprogramminginad-dressingimportantapplicationareassuchaspro-gramverication,executionofprogramanaly-sis,grammar-processing,andreasoningforintel-ligentagents.96 References[1]E.Aarts.InvestigationsinLogicLanguageandComputation.PhDthesis,UniversityofUtrecht,1995.[2]J.Alferes,C.Damasio,andL.Pereira.SLXatop-downderivationprocedureforprogramswithexplicitnegation.InM.Bruynooghe,editor,IntlLogicProgrammingSymp,pages424{439,1994.[3]J.Alferes,C.Damasio,andL.Pereira.Alogicprogrammingsystemfornon-monotonicreasoning.JournalofAutomatedReasoning,1995.[4]K.Apt,H.Blair,andA.Walker.Towardsatheoryofdeclarativeknowledge.InJ.Minker,editor,FoundationsofDeductiveDatabasesandLogicProgramming,pages19{88.MorganKaufmann,1988.[5]F.Banchilhon,D.Maier,Y.Sagiv,andJ.Ullman.Magicsetsandotherstrangewaystoimplementlogicprograms.InPODS.ACM,1986.[6]F.BanchilhonandR.Ramakrishnan.Anamateur'sintroductiontorecursivequeryprocessingstrategies.InProc.ofSIGMOD1986Conf.,pages16{52.ACM,1986.[7]J.Barklund.Tabulationoffunctionsinlogicprograms.Technicalreport,UppsalaUniversity,1995.[8]C.BeeriandR.Ramakrishnan.Onthepowerofmagic.J.LogicProgramming,10(3):255{299,1991.[9]C.Beeri,R.Ramakrishnan,D.Srivastava,andS.Sudarshan.Extendingthewell-foundedandvalidsemanticsforaggregateion.InInternationalLogicProgrammingSymposium,1993.[10]R.Ben-EliahuandR.Dechter.Propositionalsemanticsfordisjunctivelogicprograms.InJointInternationalConferenceandSymposiumonLogicProgramming,1992.[11]N.BidoitandC.Froidevaux.Negationbydefaultandunstratiablelogicprograms.Theo-reticalComputerScience,78:85{112,1991.[12]H.BlairandV.S.Subrahmanian.Paraconsistentlogicprogramming.TheoreticalComputerScience,68:135{154,1989.[13]R.Bol.Loopcheckinginpartialdeduction.JournalofLogicProgramming,16:25{46,1993.[14]R.BolandL.Degerstedt.Tabulatedresolutionforwell-foundedsemantics.InProc.oftheSymp.onLogicProgramming,1993.[15]R.BolandL.Degerstedt.Theunderlyingsearchformagictemplatesandtabulation.InProc.oftheTenthInt'lConf.onLogicProgramming,pages793{812,1993.97 [16]S.Brass.SLDMagic|animprovedmagicsettechnique.InB.NovikovandJ.Schmidt,editors,AdvancesinDatabasesandInformationSystems,1996.[17]D.R.BroughandA.Walker.Somepracticalpropertiesoflogicprogramminginterpreters.InH.Aiso,editor,InternationalConferenceonFIfthGenerationComputerSystems,pages149{158,1984.[18]F.Bry.Queryevaluationinrecursivedatabases:Bottom-upandtop-downreconciled.InDeductiveandObkect-OrientedDatabases,pages25{44,1990.[19]W.Chen.Queryevaluationofalternatingxpointlogic.Technicalreport,SMU,1994.[20]W.ChenandL.Adams.Constructivenegationofgenerallogicprograms.Technicalreport,SMU,1994.[21]W.Chen,T.Swift,andD.S.Warren.Ecienttop-downcomputationofqueriesunderthewell-foundedsemantics.J.LogicProgramming,24(3):161{199,September1995.[22]W.ChenandD.S.Warren.Computationofstablemodelsanditsintegrationwithlogicalqueryevaluation.IEEETransactionsonKnowledgeandDataEngineering,1995.[23]WeidongChenandDavidS.Warren.TabledEvaluationwithDelayingforGeneralLogicPrograms.JournaloftheACM,43(1):20{74,January1996.[24]D.Chimenti,R.Gamboa,R.Krishnamurthy,S.Naqvi,S.Tsur,andC.Zaniolo.TheLDLsystemprototype.IEEETransactionsonKnowledgeandDataEngineering,2:76{89,1990.[25]M.CodishandB.Demoen.Analysinglogicprogramsusing\Prop"-ositionallogicprogramsandaMagicwand.InILPS,pages114{129.MITPress,1993.(ToappearinJLP).[26]M.Consens,A.Mendelzon,andD.Vista.Deductivedatabasesupportfordatavisualization.Technicalreport,U.Toronto,1994.[27]C.Damasio.ParaconsistencyandNegationinLogicPrograms.PhDthesis,Univ.NovadeLisboa,1995.[28]C.Damasio,W.Nejdl,L.Pereira,andM.Schroeder.Model-baseddiagnosispreferencesandstrategiesrepresentationwithlogicmeta-programming.1995.[29]S.Dawson,C.R.Ramakrishnan,S.Skiena,andT.Swift.Principlesandpracticeofunicationfactoring.ACMTransactionsonProgrammingLanguagesandSystems,September1996.[30]S.Dawson,C.R.Ramakrishnan,I.V.Ramakrishnan,andT.Swift.Optimizingclauseres-olution:Beyondunicationfactoring.InProc.oftheInt'lLogicProgrammingSymposium,1995.[31]S.Dawson,C.R.Ramakrishnan,andD.S.Warren.Practicalprogramanalysisusinggeneralpurposelogicprogrammingsystems|acasestudy.InACMPLDI,1996.ToAppear.98 [32]I.deAlmeidaMoraandJ.Alferes.Modellingdiagnosissystemswithlogicprogramming.Technicalreport,Univ.NovadeLisboa,1995.[33]E.VillemontdelaClergerie.Layersharing:animprovedstructure-sharingframework.InProc.ofthe20th.Symp.onPrinciplesofProgrammingLanguages,pages345{359,1993.[34]E.VillemontdelaClergerieandB.Lang.Lpda:Anotherlookattabulationinlogicpro-gramming.InInternationalConferenceonLogicProgramming,pages470{488,1994.[35]S.DebrayandD.S.Warren.Functionalcomputationsinlogicprograms.ACMTOPLAS,11(3):451{481,July1989.[36]LarsDegerstedtandUlfNilsson.MagicComputationforWell-foundedSemantics.InJurgenDix,LuisMonizPereira,andTeodorC.Przymusinski,editors,Non-MonotonicExtensionsofLogicProgramming,number927inLNAI,pages181{204.Springer-Verlag,June1994.[37]M.Derr,S.Morishita,andG.Phipps.DesignandimplementationoftheGlue-Naildatabasesystem.InProc.oftheSIGMOD1993Conf.,pages147{156.ACM,1993.[38]S.Dietrich.ExtensionTablesforRecursiveQueryEvaluation.PhDthesis,SUNYatStonyBrook,1987.[39]F.DongandL.V.Lakshmanan.Deductivedatabaseswithincompleteinformation.InJointInternationalConferenceandSymposiumonLogicProgramming,1992.[40]P.Dung.Negationashypothesis:Anabductivefoundationforlogicprogramming.InInter-nationalLogicProgrammingConference,pages1{17,1991.[41]JayEarley.Anecientcontext-freeparsingalgorithm.CommunicationsoftheACM,13(2):94{102,1970.[42]C.FanandS.Dietrich.Extensiontablebuilt-insforprolog.Software|PracticeandExpe-rience,22:573{597,1992.[43]J.Freire,R.Hu,T.Swift,andD.S.Warren.Parallelizingtabledevaluation.In7thInterna-tionalPLILPSymposium,pages115{132.Springer-Verlag,1995.[44]J.Freire,T.Swift,andD.S.Warren.TreatingI/Oseriously:Resolutionreconsideredfordisk.Technicalreport,SUNYatStonyBrook,1995.[45]J.Freire,T.Swift,andD.S.Warren.Beyonddepth-rst:Improvingtabledlogicprogramsthroughalternativeschedulingstrategies.In8thInternationalPLILPSymposium.Springer-Verlag,1996.[46]H.Gao.DeclarativePictureDescriptionandInterpretationinLogic.PhDthesis,DepartmentofComputerScience,SUNYatStonyBrook,1993.99 [47]M.GelfondandV.Lifshitz.Representingactionsinextendedlogicprogramming.InJointInt'lConfandSymponLogicProgramming,pages559{573,1992.[48]S.Greco,D.Sacca,andC.Zaniolo.Dynamicprogrammingoptimizationforlogicquerieswithaggregates.InInternationalSymposiumonLogicProgramming,pages575{589,1993.[49]A.GuptaandI.Mumick.Magicsetstransformationsinnon-recursivesystems.InPODS,pages354{367,1992.[50]J.Han.Compilationandevaluationoflinearmutualrecursions.InformationSciences,69:157{183,1993.[51]J.HanandL.Liu.Ecientevaluationofmultiplelinearrecursions.IEEETransactionsonSoftwareEngineering,17(12):1241{1252,1991.[52]J.Han,L.Liu,andZ.Xie.LogicBase:Adeductivedatabasesystemprototype.Technicalreport,SimonFraserUniversity,1994.[53]M.Hermenegildo,R.Warren,andS.K.Debray.Global\rowanalysisasapracticalcompilationtool.JournalofLogicProgramming,13(1,2,3and4):349{366,1992.[54]G.Janssens,M.Bruynooghie,andV.Dumortier.Ablueprintforanabstractmachinefortheabstractinterpretationof(constraint)logicprograms.InInternationalLogicProgrammingSymposium,pages336{351,1995.[55]B.JayaramanandK.Moon.Implementationofsubsetlogicprogrms.Technicalreport,Dept.ofComputerScience,SUNYBualo,1994.[56]C.Jonker.ConstraintsandNegationsinLogicPrograms.PhDthesis,UtrechtUniversity,1994.[57]T.Kanamori.Abstractinterpretationbasedonalexandertemplates.JournalofLogicPro-gramming,15:31{54,1993.[58]T.KanamoriandT.Kawamura.Abstractinterpretationbasedonoldtresolution.JournalofLogicProgramming,15:1{30,1993.[59]D.KempandP.Stuckey.Semanticsoflogicprogramswithaggregates.InInternationalLogicProgrammingSymposium,pages387{404,1991.[60]D.KempandR.Topor.Completenessofatop-downqueryevaluationprocedureforstratieddatabases.InLogicProgramming:Proc.oftheFifthInt'lConf.andSymp.,pages178{194,1988.[61]DavidB.Kemp,KotagiriRamamohanarao,andZoltanSomogyi.Right-,left-andmulti-linearruletransformationsthatmaintaincontextinformation.InProceedingsofthe16thConferenceonVeryLargeDataBases,pages380{391,1990.100 [62]R.Larson,D.S.Warren,J.Freire,andK.Sagonas.Semantica.MITPress,1995.Inpreparation.[63]R.Larson,D.S.Warren,J.Freire,andK.Sagonas.Syntactica.MITPress,1995.[64]AlexandreLefebvre.Recursiveaggregatesintheeks-v1system.TechnicalReportKB34,ECRC,1991.[65]U.Manber.IntroductiontoAlgorithms:ACreativeApproach.Addison-Wesley,1989.[66]S.Morishita.AnExtensionofVanGelder'sAlternatingFixpointtoMagicPrograms.JournalofComputerSystemSciences,52:506{521,June1996.[67]I.Mumick,S.Finklestein,R.Ramakrishnan,andH.Pirahesh.Magicconditions.InPODS,1990.[68]I.MumickandH.Pirahesh.ImplementationofMagic-setsinaRelationalDatabaseSystem.InProceedingsoftheACMSIGMODInternationalConferenceontheManagementofData,pages103{114,1994.[69]I.Mumick,H.Pirahesh,andR.Ramakrishnan.Themagicofduplicatesandaggregates.InProc.ofthe16thInt'lConf.onVeryLargeDataBases,pages264{277.VLDBEnd.,1990.[70]J.Naughton,R.Ramakrishnan,Y.Sagiv,andJ.Ullman.Argumentreductionthroughfactoring.InProc.ofthe15thInt'lConf.onVeryLargeDataBases,pages173{182.VLDBEnd.,1989.[71]UlfNilsson.Abstractinterpretation:Akindofmagic.InPLILP91,pages299{310,1991.[72]F.C.N.PereiraandD.H.D.Warren.Parsingasdeduction.InProceedingsofthe21stAnnualMeetingoftheAssociationforComputationalLinguistics,pages137{144,1983.[73]G.Phipps,M.Derr,andK.Ross.Glue-Nail:Adeductivedatabasesystem.pages308{317,1991.[74]H.PrzymusinskaandT.Przymusinski.Weaklyperfectmodelsemanticsforlogicprograms.In5thInternationalConferenceandSymposiumonLogicProgramming,pages1106{1123,1988.[75]T.C.Przymusinski.Onthedeclarativesemanticsofdeductivedatabasesandlogicprogram-ming.InJ.Minker,editor,FoundationsofDeductiveDatabasesandLogicProgramming,pages193{216.MorganKaufmann,1988.[76]T.C.Przymusinski.Everylogicprogramhasanaturalstraticationandaniteratedleastxedpointmodel.InPODS,pages11{21,1989.[77]R.Ramakrishnan,editor.ApplicationsofLogicDatabases.KluwerAcademicPublishers,1995.101 [78]R.Ramakrishnan,C.Beeri,andR.Krishnamurthi.Optimizingexistentialdatalogqueries.InProc.oftheACMSymp.onPrinciplesofDatabaseSystems,pages89{102.ACM,1988.[79]R.Ramakrishnan,D.Srivastava,andS.Sudarshan.Controllingthesearchinbottom-upevaluation.InProc.oftheJointInt'lConf.andSymp.onLogicProgramming,1992.[80]RaghuRamakrishnan,DiveshSrivastava,S.Sudarshan,andPraveenSeshadri.Implemen-tationoftheCORALDeductiveDatabaseSystem.InProceedingsoftheACMSIGMODInternationalConferenceontheManagementofData,pages167{176,1993.[81]RaghuRamakrishnanandJereyD.Ullman.Asurveyofdeductivedatabasesystems.JournalofLogicProgramming,23(2):125{149,1995.[82]R.RameshandW.Chen.AportablemethodofintegratingSLGresolutionintoPrologsystems.InProc.oftheSymp.onLogicProgramming,1994.[83]P.Rao,C.R.Ramakrishnan,andI.V.Ramakrishnan.Athreadintimesavestablingtime.In1996JointInternationalConferenceandSymposiumonLogicProgramming,1996.[84]P.Rao,I.V.Ramakrishnan,K.Sagonas,T.Swift,andD.S.Warren.Ecienttableaccessmechanismsforlogicprograms.InInternationalConferenceonLogicProgramming,1995.ToAppear.[85]T.Reps.Demandinterproceduralprogramanalysisusinglogicdatabases.InR.Ramakrish-nan,editor,ApplicationsofLogicDatabases.KluwerAcademic,1994.[86]T.Reps.Shapeanalysisasageneralizedpathproblem.InACMSymposiumonPartialEvaluationandSemantics-basedProgramManipulation,pages1{11.ACMPress,1995.[87]J.Rohmer,R.Lescoeur,andJ.Kerisit.TheAlexandermethod:atechniquefortheprocessingofrecursiveatomsindeductivedatabases.NewGenerationComputing,4:522{528,1986.[88]K.Ross.Modularacyclicityandtailrecursioninlogicprograms.InProc.of10thPODS,1991.[89]K.A.Ross.Modularstraticationandmagicsetsfordatalogprogramswithnegation.InJACM,pages1216{1266,1994.[90]D.SaccaandC.Zaniolo.Thegeneralizedcountingmethodforrecursivelogicqueries.Theo-reticalComputerScience,62:187{220,1989.[91]Y.Sagiv.Isthereanythingbetterthanmagic?InProc.ofthe1990NorthAmericanConference,pages235{254,1990.[92]K.Sagonas.TheSLG-WAM:ASearch-EcientEngineforWell-FoundedEvaluationofNormalLogicPrograms.PhDthesis,SUNYatStonyBrook,1996.102 [93]K.Sagonas,T.Swift,andD.S.Warren.XSBasanecientdeductivedatabaseengine.InProc.ofSIGMOD1994Conf.ACM,1994.[94]K.Sagonas,T.Swift,andD.S.Warren.Thelimitsofxed-ordercomputation.Technicalreport,SUNYatStonyBrook,1995.[95]K.Sagonas,T.Swift,andD.S.Warren.Anabstractmachineforcomputingthewell-foundedsemantics.InJointInternationalConferenceandSymposiumonLogicProgramming.,1996.[96]K.Sagonas,T.Swift,andD.S.Warren.Anabstractmachineforxed-orderstratiedpro-grams.InProc.of13thConferenceonAutomatedDeduction.,1996.[97]H.Seki.OnthepowerofAlexandrertemplates.InProc.of8thPODS,pages150{159.ACM,1989.[98]H.SekiandH.Itoh.AqueryevaluationmethodforstratiedprogramsundertheextendedCWA.InLogicProgramming:Proc.oftheFifthInt'lConf.andSymp.,pages195{211,1988.[99]O.Shmueli,S.Tsur,andC.Zaniolo.Compilationofsettermsinthelogicdatalanguage(LDL).JournalofLogicProgramming,12:89{119,1992.[100]S.Smolka,O.Sokolsky,andS.Zhang.Modelcheckinginthemodal-calculus.InIEEELICS,1994.[101]P.StuckeyandS.Sudarshan.Well-foundedorderedsearch.In13thconferenceonFoundationsofSoftwareTechnologyandTheoreticalComputerScience,pages161{172,1993.[102]S.Sudarshan.OptimizingBottom-upQueryEvaluationforDeductiveDatabases.PhDthesis,UniversityofWisconsin,1992.[103]S.SudarshanandR.Ramakrishnan.Aggregationandrelevanceindeductivedatabases.InProc.ofthe17thInt'lConf.onVeryLargeDataBases,pages501{511.VLDBEnd.,1991.[104]S.SudarshanandR.Ramakrishnan.Optimizationsofbottom-upevaluationwithnon-groundterms.InProc.oftheSymp.onLogicProgramming,1993.[105]T.Swift.EcientEvaluationofNormalLogicPrograms.PhDthesis,SUNYatStonyBrook,1994.[106]T.SwiftandD.S.Warren.AnabstractmachineforSLGresolution:deniteprograms.InProceedingsoftheSymposiumonLogicProgramming,pages633{654,1994.[107]T.SwiftandD.S.Warren.AnalysisofsequentialSLGevaluation.InProceedingsoftheSymposiumonLogicProgramming,pages219{238,1994.[108]H.TamakiandT.Sato.OLDTresolutionwithtabulation.InThirdInt'lConf.onLogicProgramming,pages84{98,1986.103 [109]F.Teusink.Aproofprocedureforextendedlogicprograms.InInternationalLogicProgram-mingSymposium,pages235{249,1993.[110]D.Toman.Top-downbeatsbottom-upforconstraintextensionsofdatalog.InInternationalLogicProgrammingSymposium,pages98{115,1995.[111]J.Ullman.Bottom-upbeatstop-downfordatalog.InProc.of8thPODS,pages140{149.ACM,1989.[112]J.Vaghani,K.Ramamohanorao,D.Kemp,Z.Somogyi,andP.Stuckey.DesignoverviewoftheAditideductivedatabasesystem.InSeventhInt'lConf.onDataEngineering,pages240{247,1991.[113]A.vanGelder.Thealternatingxpointoflogicprogramswithnegation.InProc.of8thPODS,pages1{10.ACM,1989.[114]A.vanGelder,K.A.Ross,andJ.S.Schlipf.Unfoundedsetsandwell-foundedsemanticsforgenerallogicprograms.JACM,38(3):620{650,1991.[115]L.Vieille.Recursivequeryprocessing:Thepoweroflogic.TheoreticalComputerScience,69:1{53,1989.[116]L.Vieille,P.Bayer,V.Kuchenho,andA.Lefebvre.EKS-V1,ashortoverview.InAAAI-90WorkshoponKnowledgeBaseManagementSystems,1990.[117]G.Wagner.Reasoningwithinconsistencyinextendeddeductivedatabases.InInternationalWorkshoponLogicProgrammingandNon-MonotonicReasoning,pages300{315,1994.[118]A.Walker.TheSyllogexpertdatabasesystem.Technicalreport,IBM,1992.[119]A.Walker.Backchainiteration:Towardsapracticalinferencemethodthatissimpleenoughtobeprovedterminating,sound,andcomplete.J.AutomatedReasoning,11(1):1{23,1993.OriginallyformulatedinNewYorkUniversityTR34,1981.[120]D.S.Warren.Memoingforlogicprogramswithapplicationstoabstractinterpretatinoandpartialdeduction.CommunicationsoftheACM,1992.[121]J.Wunderwald.Aportableimplementationofmemoingevaluation.InLOPSTR95,1995.104 11. (answer) p(b,c)9. (interior) p(b,Z) :- e(b,Z),q(Z) 8. (active) p(b,Z) :- p(b,Y),p(Y,Z)7a. p(b,Z)10. (interior) p(b,c) :- q(c) q(a). q(b). q(c).e(a,b). e(a,d). e(b,c).p(X,Z) :- p(X,Y),p(Y,Z).:- table p/2. SubgoalAnswers 105 q(a). q(b). q(c).e(a,b). e(a,d). e(b,c).p(X,Z) :- p(X,Y),p(Y,Z).:- table p/2. 14. (active)15. (interior)SubgoalAnswers106 15. (interior)p(c,Z) :- e(c,Y),q(Y)107 123411233321322aet p(1,3)p(1,4)p(2,3).p(2,4). sg(1,Y)sg(1,1)sg(2,Y)sg(2,2)sg(3,3)AnswersSubgoals 12. sg(1,2)12. sg(1,1)failfailfail108 sg(1,Y)sg(1,1)sg(2,Y)sg(2,2)sg(3,3)AnswersSubgoals 3. sg(1,Y):-p(Y,4)3. sg(1,Y):-p(Y,4)3. sg(1,1)3. sg(1,2)3. sg(1,1)109 lr-dynamically stratifiedweakly stratified110 just_as_good_choice/3get_best_choices/3 can_teach/2rates/2 111 112 113 114 f/2g/2bd223332.12.1aV1115