/
TabledLogicPrograms:Principles,PracticeandApplicationsC.R.Ramakrishnan TabledLogicPrograms:Principles,PracticeandApplicationsC.R.Ramakrishnan

TabledLogicPrograms:Principles,PracticeandApplicationsC.R.Ramakrishnan - PDF document

tawny-fly
tawny-fly . @tawny-fly
Follow
394 views
Uploaded On 2016-08-11

TabledLogicPrograms:Principles,PracticeandApplicationsC.R.Ramakrishnan - PPT Presentation

OutlineMotivationWhyisTablingofGeneralInterestDe niteProgramsAlgorithmsTablingApplicationsNormalProgramsAlgorithmsTablingApplicationsImplementation2 MotivationSolvesinadequaciesofPrologSL ID: 441774

OutlineMotivation:WhyisTablingofGeneralInterest?De nitePrograms:{Algorithms{TablingApplicationsNormalPrograms{Algorithms{TablingApplicationsImplementation2 MotivationSolvesinadequaciesofProlog(SL

Share:

Link:

Embed:

Download Presentation from below link

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.


Presentation Transcript

TabledLogicPrograms:Principles,PracticeandApplicationsC.R.RamakrishnanI.V.RamakrishnanKonstantinosSagonasTerranceSwiftDavidS.WarrenAnnotatedversionofTutorialSlidespresentedatJointInternationalConferenceandSymposiumonLogicProgramming,Bonn,Germany1996.1 OutlineMotivation:WhyisTablingofGeneralInterest?De nitePrograms:{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.{Tablingasde nedbelowforWFShaspoly-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]{SoftwareVeri cation[100]{GraphicsandDataVisualization[46],[26]{DiagnosisSystems[32],[28]{Other[13],[77]SQL3Standardincludesrecursion.8 De niteProgramsManyformulationsoftablingaremoreorlessequiv-alentforde niteprograms.EarleyDeduction(1970)BackchainIteration(1981)OLDT(1986)AlexanderMethod(1986)SLD-AL(QSQR)(1986-1989)MagicTemplates(1986-88)ExtensionTables(1987)SLG(1993)LogicPushDownAutomata(1994)ATabledEvaluationcanbecharacterizedbyOperationsplusaSearchStrategy.9 De nitePrograms 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 De nitePrograms11 De nitePrograms12 De nitePrograms:TablingThesearchstrategyforthatprogramwasatuple-at-a-timestrategyresemblingProlog's[45].Onederivationpath(ortree)mayneedtocon-sumeanswersfromanotherderivationpath(ortree)Maybemorethanoneanswerforagiventabledsubgoal13 De nitePrograms:TablingFor nitecomputations,atabledevaluationcanbeseenasasequenceofforests.GivenaforestFanewforestisdeterminedbyoneofthefollowingoperations.De nition1newsubgoal.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 De nitePrograms:TablingWhatdoesCompletelyEvaluatedmean?Asubgoaliscompletelyevaluatedi ithasallofitspossibleanswers.AsubgoalSiscompletelyevaluatedwhenallpossibleoperationshavebeendoneonitsnodes,andthenodesoftreesuponwhichSdepends.Agroundsubgoaliscompletelyevaluatedwhenananswerisderivedforit.IncrementalCompletionisnecessaryforecientevaluationofprograms.16 De nitePrograms:Tabling17 De nitePrograms:TablingSubgoalDependencyGraph IncrementalCompletioncanbeperformedaSCCatatime,orasetofSCCsatatime.18 De nitePrograms: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 De nitePrograms:MagicSplitprogramupintoEDBandIDB.Adda ltertothebeginningofeachIDBclausetomakesurethatwhenevertheclauseisacti-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).Makesurethatthepropercalling ltersarede-rived.call(sg(Z,Z1)):-call(sg(X1,X)),p(X,Z).Addamagicseedtorepresenttheoriginalquery.call(sg(1,X)).Thisisonlyasimpleversionofmagic.20 De nitePrograms: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,thesetoffactsavailableattheendofiterationtconsistsofthe rsttdeltasetsforeachpredicate.Attimet,thesecondrulewilljoincalls rstproducedattimet1(delta call/1)withappropriatesg/2factsfromt2.21 Attimet,thethirdrulewilljoinallcallsproducedbytheendoft1withthesg/2facts rstproducedattimet1.22 De nitePrograms: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 De nitePrograms:GrammarsConsiderthegrammarexpr--�expr+termexpr--�termterm--�term*factorterm--�factorfactor--�(expr)factor--�integer(Int)24 De nitePrograms: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 De nitePrograms:GrammarsThesamegrammarusingtabling.:-tableexpr/2,term/2.expr--�expr,[+],term.expr--�term.term--�term,[*],factor.term--�factor.factor--�['('],expr,[')'].factor--�[Int],{integer(Int)}.Syntacticvariantoforiginalgrammar.Hasnoassociativityproblem26 De nitePrograms:GrammarsApplyingtablingtoaDCGgrammarcane ec-tivelygiveEarleyParsing[41]{SupplementaryTabling(SupplementaryMagic)canconvertthegrammartoChomskyNormalForm1.EarleyParsingofgrammarsinChomskyNormalFormtakesatmostO(N3)forambiguousgram-mars;atmostO(N2)forunambiguousgram-mars;andislinearforalargeclassofgrammars.AdditionaloptimizationssuchasLeftFactoringcanbeperformedbyCRAoptimizationsasde-scribedin[30]. 1ImplementingEarley'sDottedRules.27 De nitePrograms: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)o erusefulcom-plexityadvantagesforothergrammaticalformalismssuchascategorialgrammars[1].28 De nitePrograms:DynamicProgrammingTheminimumeditdistanceproblem: ndthemin-imumnumberofinsertions,deletions,orreplace-mentstoturnonestringintoanother.:-tablemed/3.med(0,0,0).med(0,M,M):-M�0.med(N,0,N):-N�0.med(N,M,C):-N�0,M�0,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 De nitePrograms:DynamicProgrammingSolutionstomed/3recursivelycreateaMNarray:30 De nitePrograms:DynamicProgrammingTheknap-sackproblem:Givennitems,eachofintegersizeki(1n),andaknap-sacksizeK.determinewhetherthereisasubsetoftheitemsthatsumstoK.Findsuchasubset.31 De nitePrograms:DynamicProgrammingAPrologsolutiontotheknapsackproblem.ks(0,0).ks(I,K):-I�0,I1isI-1,ks(I1,K).ks(I,K):-I�0,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 De nitePrograms:DynamicProgrammingAtablingsolutiontotheknapsackproblem.:-tableks/2.ks(0,0).ks(I,K):-I�0,I1isI-1,ks(I1,K).ks(I,K):-I�0,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 De nitePrograms:DynamicProgrammingButhowdoyou ndthesubset(s)?ksp(0,0,[]).ksp(I,K,P):-I�0,I1isI-1,ks(I1,K),ksp(I1,K,P).ksp(I,K,[I|P]):-I�0,item_size(I,Ki),K1isK-Ki,K1�=0,I1isI-1,ks(I1,K1),ksp(I1,K1,P).Notethatks/2doesnotrepeatcomputations.cf.[65]pg.110foranequivalentimperativesolution.34 De nitePrograms:DynamicProgrammingNotethatwiththegoal-orientationoftabling,incertainproblemsitmaynotbenecessarytobuildanentirearray.OnesuchcaseoccurswhentablingisusedintheUni cationFactoringcom-pileroptimization[29].[48]o ersotherapproachestodynamicprogram-mingusingtabling.35 De nitePrograms:ApplicationsProgramAnalysisExpoitstheabilityoftabledevaluationto ndminimalmodelsofde niteprogramsGeneralStrategy: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(\speci cation-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 De nitePrograms: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,whencombinedwithamodelcheckingalgorithmcanbeusedforveri cationofconcurrentsystems.Timeandspaceutilizationareroughlycompa-rablewithspecial-purposemodelcheckers43 De nitePrograms:TopicsinDe niteTablingRecallthatatabledevaluationcanbecharacter-izedbyoperationsplusscheduling.ChangesinScheduling:LocalandBreadth-FirstChangesinOperations:CheckingforVariancevs.Subsumption44 De nitePrograms:SchedulingTabledevaluationshavenewsubgoaloperationandanswerresolutionoperationwhichmustbescheduledalongwiththeprogramclauseresolutionstepofSLD.Canreturnanswersassoonastheyarederived,orpostponetheirreturn.Cancreateanewtreeassoonasthereisase-lectedliteralforit,orpostponethisoperation.Prolog'sstrategyisapproximatedbypostponingneitherthereturnofanswersorthecreationofnewtrees.PostponinganswerreturnoutofanSCCuntilanSCCiscompletelyevaluatedgiveslocaleval-uation[45].Postponingbothoperationsuntiltheendofaniteration,givesbreadth- rstevaluation,typi-45 calofsemi-naivemagicevaluations.(JointworkwithJ.Freire).46 De nitePrograms:TablingandMagicConsideratuple-at-a-timeevaluationofsame-generation47 De nitePrograms:TablingandMagicNowconsideraset-at-a-timeevaluationInparticular,thisishowasemi-naiveevaluationwouldevaluateamagic-rewrittensame-generationprogram.48 De nitePrograms: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 De nitePrograms:TablingandMagicTablingstartsfromresolutionandisaprogram-mer'sviewofcombiningtop-downandbottom-up.Magicstartsfromsemi-naiveevaluationandisadatabasequeryprocessor'sviewofcombiningtop-downandbottom-up.Tablingcapturesdisk-accessmethodsofmagicviaBreadth-FirstTabling.MagiccapturesthedynamicdependenciesoftablingviaOrderedSearch[79]Bothallowsubsumptionorvarianceofcallsoranswers.Re\rectionsinafun-housemirror?50 De nitePrograms:OperationsTheoperationsmentionedbeforeassumedavari-antcheckforsubgoalsandanswers.Alternatelyonecouldusesubgoalsubsumptionoranswersubsump-tion.Considertheprogramp(X):-p(f(X)).p(a).Minimalmodelisfp(a)g.Aspreviouslyde ned,thetablingevaluationofaquery?-p(X)wouldcreateanin nitenumberoftrees.p(X),p(f(X)),p(f(f(X))),...Subgoalsubsumptionaddressesthisproblem.51 De nitePrograms:SubgoalSubsumptionDe nition2newnon-subsumedsubgoal.GivenanodeNwithselectedtabledliteralB,whereBisnotsubsumedbyasubgoalinF,createanewtreewithrootB.Theorem1LetPbeaprogramwitha nitemodelinwhicheverypredicateistabled,andEbeanevaluationconsistingofnewnon-subsumedsubgoal,programclauseresolution,an-swerresolutionandcompletion.ThenEwillcorrectlyterminateaftera nitenumberofoperations.Originallystatedin[108]usingOLDTformal-ism.52 De nitePrograms: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 De nitePrograms: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 De nitePrograms:AnswerSubsumptionDe nition3(non-subsuming)answerresolution.GivenanactivenodeNwithselectedliteralB,resolveananswerAagainstBif{AthathasnotbeenpreviouslyusedbyN.{AisnotsubsumedbyanyotheranswerinthetreeforB.Thistendstobemostusefulwhensubsumptionisusedonapartialorderotherthanthatofterms.Inthe3-valuedinformationorderingtrueandfalsearegreaterthanunde ned.Therefore,trueanswerssubsumeunde nedanswers.Subsumptioncanbegeneralizedtoimplicationforbothsubgoalsandanswers.Inanappropriateconstraintdomainp(X):(X�2))p(X):(X�3)55 De nitePrograms: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-strati ednegation.Callvarianceinnon-\rounderingprogramsavoidsconstructivenega-tion.Answersubsumptionisusedtohandleun-certainanswers.CallSubsumptionisusefulforminimalmodelcomputationsofde niteorstrati edprograms.57 TablingProgramswithNegationRealisticprogramsusenegation,howisnegationcombinedwithtabling?CanthegreaterexpressivepoweroftablingalsobeusedasabasisforaLogicProgrammingim-plementationsofNon-MonotonicReasoning?Intuition:Thewell-foundedsemantics(WFS)treatsallpathswithin nitepositiverecursionasfailed,andallpathswithin niterecursionthroughnega-tionasunde ned.Thustheloop-checkingfeaturesoftablingcanbeusedtoevaluateWFS.58 NegationThefollowingprogamusesnegationinastraight-forwardway,butmaycausePrologtogointoanin niteloop.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),Rank1�Rank.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:TowardsWFSthroughstrati cation61 Negation:TowardsWFSthroughstrati cationLowerstrati cationclassesarecomputedbyDeterminingadependencygraph(DG)Determiningwhethercomponentsinthedepen-dencygraphcontaincyclesthroughnegationExamples:PredicateStrati cation[4]:singleDGforentireprogram,basedonpredicatedependencies.LocalStrati cation[75]:singleDGforentire(grounded)program,basedonatomdependen-cies.62 Negation:TowardsWFSthroughstrati cation63 Negation:TowardsWFSthroughstrati cationThebasicideaofformingadependencygraphandcheckingforloopsthroughnegationisperformedit-erativelyinthehigherstrati cationclassessuchasmodularstrati cation[89]andweakstrati cation[74].Weconsiderthehighestofthese,DynamicStrati cation[76,11]indetail.ThepowerofDynamicstrati cationcanbeseenfromthefollowingtheoremTheorem2[76]AprogramisDynamicallyStrati edi ithasatwo-valuedwell-foundedmodel.64 Negation:DynamicStrati cationDynamicstrati cationiteratively ndsaninter-pretationIforagroundprogram,andreducestherestoftheprogramwithrespecttoI.StartwithI0=;Ah:-A1;:::;Am;notAm+1;:::;notAnTodeterminepositivefacts ndtheleast xpointoftheoperator{TI(T)=fA:thereisaclauseB L1;:::;LninPandagroundsubstitutionsuchthatA=Bandforevery1neitherLiistrueinI,orLi2Tg;Todeterminenegativefacts, ndthegreatest xpointoftheoperator{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 NegationThe rstpartialmodel,I0is;sotheoperatorse ectivelyworkontheprogramp(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).Whose xpointgivesI1inwhichItrue1=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.Anyunde nedliteralsattheendofthisitera-tiveprocessmaybesaidtobeintheultimatestratum.69 NegationThemethodjustshownwaspurebottom-up.Tomakeitgoal-orientedrequiresanotionofrel-evance.Assumingaleft-to-rightcomputationrule:{InProlog,relevantliteralsforaselectedclausebelongtoafailingpre x.p(a):-t(a,b,a),notp(b),notp(a).{Togetthisdynamicstrati cationanevalua-tioncannotviewonlyapre x.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 NegationIsthisprogrammingorspeci cation?Left-to-rightdynamicstrati cationallowsonlyfail-ingpre xesFMi(F)=fA:foreveryclauseB L1;:::;LninPandagroundsubstitutionsuchthatA=Band(1)issome(1n),suchthatLiisfalseinMiorLi2F;(2)thereexistsafailingpre x:forallj(1j1),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.De ne: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)completionMechanismtohandleunde nedliteralsinaclause85 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]VanillaMagicusesastaticallyde nedcontrolstrategy.Orderedsearchusesadynamiccontrolstrategy[79]Issue:Howtohandleunknown/unde nedliteralsOneissueinvolvesdynamicallychangingthecom-putationruleAsecondissueinvolvesrepresentingatomsthatareneithertruenorfalse.XSBimplementsdelayandsimpli cation[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).Stillquadraticinthesizeofthe rstargumentifyoumustcopyfromexecutionareatotable.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 SummaryTablingandMagicareusuallydi erentformula-tionsofthesamealgorithms.Tablingthuspro-videsapotentialwaytopeformdiskaccesse-cientlyfromalogicprogram.TablingcanbetightlycoupledwithProlog,sothatitispossibletoprogramwithtablingTablingprovidesapropercomputationalbasisforcertainformsofNon-monotonicreasoning.Tablingaddspowertologicprogramminginad-dressingimportantapplicationareassuchaspro-gramveri cation,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.Negationbydefaultandunstrati ablelogicprograms.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.Queryevaluationofalternating xpointlogic.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.Principlesandpracticeofuni cationfactoring.ACMTransactionsonProgrammingLanguagesandSystems,September1996.[30]S.Dawson,C.R.Ramakrishnan,I.V.Ramakrishnan,andT.Swift.Optimizingclauseres-olution:Beyonduni cationfactoring.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,SUNYBu alo,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-downqueryevaluationprocedureforstrati eddatabases.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.Everylogicprogramhasanaturalstrati cationandaniteratedleast xedpointmodel.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]RaghuRamakrishnanandJe reyD.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.Modularstrati cationandmagicsetsfordatalogprogramswithnegation.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.Thelimitsof xed-ordercomputation.Technicalreport,SUNYatStonyBrook,1995.[95]K.Sagonas,T.Swift,andD.S.Warren.Anabstractmachineforcomputingthewell-foundedsemantics.InJointInternationalConferenceandSymposiumonLogicProgramming.,1996.[96]K.Sagonas,T.Swift,andD.S.Warren.Anabstractmachinefor xed-orderstrati edpro-grams.InProc.of13thConferenceonAutomatedDeduction.,1996.[97]H.Seki.OnthepowerofAlexandrertemplates.InProc.of8thPODS,pages150{159.ACM,1989.[98]H.SekiandH.Itoh.Aqueryevaluationmethodforstrati edprogramsundertheextendedCWA.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:de niteprograms.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.Thealternating xpointoflogicprogramswithnegation.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