aPrtcrightrecursive bPdtcdoublyrecursiveFig4ProvenancegraphswithannotationsforprolingPrtcandPdtcona5nodelineargraphPdtccausesmoreruleringsthanPrtcandalsoderivesfactsinmultiplewaysNumber ID: 381285
Download Pdf The PPT/PDF document "proceduraldebuggingtechniquesforProlog,b..." 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.
proceduraldebuggingtechniquesforProlog,basedontheboxmodel[19],arenotavailableinDatalog.Instead,newdebuggingtechniquesareneededthataresolelybasedonthedeclarativereadingofrules.Inthispaper,wedevelopsuchaframeworkfordeclarativedebuggingandlogicproling.LetM=P(I)bethemodelofPoninputI.BugsinP(orI)manifestthemselvesthroughunexpectedanswers(groundatoms)A2M,orexpectedbutmissingA=2M.ThekeyideaofourapproachistorewritePintoaprovenance-enrichedprogram^P,whichrecordsthederivationhistoryofM=P(I)inanextendedmodel^M=^P(I).AprovenancegraphGisthenextractedfrom^M,whichtheusercanexplorefurtherviapredenedviewsandad-hocqueries.UseCasesOverview.GivenanIDBatomA,ourapproachallowstoanswerquestionssuchasthefollowing:WhatisthedatalineageofA,i.e.,thesetofEDBfactsthatwereusedinaderivationofA,andwhatistherulelineage,i.e.,thesetofrulesusedtoderiveA?Whenchasingabugortryingtolocateasourceofineciency,ausercanexplorefurtherdetails:WhatisthegraphstructureGAofallderivationsofA?WhatisthelengthofA,i.e.,ofshortestderivations,andwhatistheweight,i.e.,numberofsimplederivations(prooftrees)ofA?Foranotherexample,assumetheuserencounterstwo\suspicous"atomsAandB.ItiseasytocomputethecommonlineageGAB=GA\GBsharedbyAandB,orthelowestcommonancestorsofAandB,i.e.,theruleringsandgroundatomsthatoccur\closest"toAandBinGAB,thustriangulatingpossiblesourcesoferror,somewhatsimilartoideasusedindeltadebugging[22].SincenodesinGAareassociatedwithrelationsymbolsandrules,ausermightalsowanttocomputeotheraggregates,i.e.,notonlyatthelevelofGA(groundatomsandrings),butatthelevelof(non-ground)rulesandrelationsymbols,respectively.Throughthisschema-levelproling,ausercanquicklyndthehot(cold)spotsinP,e.g.,ruleshavingthemost(least)numberofrings.RunningExample.Figure1givesanoverviewusingaverysimpleexample:(a)depictsaninputgraphe,while(b)showsitstransitiveclosuretc:=e+.Thestructureandnumberofdistinctderivationsoftcatomsfrombaseedgesinecanbeverydierent,e.g.,whencomparingtheright-recursivePtc(=Prtc)above,withleft-recursiveordoubly-recursivevariantsPltcorPdtc,respectively.TheprovenancegraphG(ortherelevantsubgraphGAG,givenagoalA)providescrucialinformationtoanswertheaboveusecases.Fig.1(c)showstheprovenancegraphforthecomputationoftcviaPrtcfromabove.Boxnodesrepresentrulerings,i.e.,individualapplicationsoftheimmediateconsequenceoperatorTP,andconnectallbodyatomstotheheadatomviaauniqueringnode.ForthedebuggoalA=tc(a;b)thesubgraphGA,capturingallpossiblederivationsofA,ishighlighted(throughllednodesandboldedges).OverviewandContributions.WepresentasimplemethodfordebuggingandlogicallyprolingaDatalogprogramPviaaprovenance-enrichedrewriting^P.Thekeyideaistoextractfromtheextendedmodel^MaprovenancegraphGwhichisthenqueried,analyzed,andvisualizedbytheuser.GivenadebuggoalA,relevantsubgraphsGAcanbeobtainedeasilyandfurtheranalyzedviaalibraryofcommondebugviewsandad-hocuserqueries.Atthecoreofourapproach (a)Prtc:right-recursive (b)Pdtc:doubly-recursiveFig.4.ProvenancegraphswithannotationsforprolingPrtcandPdtcona5-nodelineargraph.PdtccausesmoreruleringsthanPrtcandalsoderivesfactsinmultipleways.Numbersdenotelen(F)(inringnodes)andlen(A)(inatomnodes),respectively.length,i.e.,earliestpossiblederivationround.NotehowsomeatomnodesinthegraphforPdtcinFig.4(b)havemoreincomingedges(andderivations)thanthecorrespondingnodesinthePrtcvariantshowninFig.4(a).ComputingtheMaximumRound.Anothermeasureisthenumberofstates(TProunds),neededtoderiveallconclusions.FromtherewritingPS,wecansimplydeterminethenalstate:MaxRound(MR):MR=maxfS:g(S, , , )g.ThismeasureshowsanothercleardierencebetweenPrtcandPdtc:WhilePrtcrequires10roundstocomputealltransitiveedgesinoursamplegraph,Pdtconlyneeds6rounds.Generally,thedoubly-recursivevariantrequiressignicantlyfewerrounds,i.e.,logarithmicinthesizeofthelongestsimplepathinthegraphversuslinearfortheright-recursiveimplementation.CountingRederivations.Toanalyzethenumberofderivationsinmoredetail,wecanusetheStatelogrewritingPStoalsocapturetemporalsaspects.WitheachapplicationoftheTPoperator,somefactsmightberederived.Notethat,ifafactisderivedviadierentvariablebindingsinthebodyofarule(ordierent evaluationtechniquesspecictotheunderlyingDatalogengine.Indeed,parallelwiththedevelopmentofthemethod,wehaveimplementedtwoincarnationsofaGraph-basedProvenanceAnalyzerandDebugger,i.e.,prototypesGpad/dlvandGpad/lb,fordeclarativedebuggingwiththeDLV[12]andLogicBlox[14]engines,respectively.Bothprototypes\wrap"theunderlyingDatalogengine,andoutsourcesomeprocessingaspectstoahostlanguage.Forexample,Gpad/dlvusesSwi-Prolog[20]asa\glue"toautomate(1)rulerewritings,(2)invocationofDLV,followedby(3)resultpost-processing,and(4)resultvisualizationusingGraphviz.WeareactivelydevelopingGpadfurtherandplanapublicreleaseinthenearfuture.5RelatedWorkWorkondeclarativedebugging,inparticularintheformofalgorithmicdebugginggoesasfarbackasthe1980's[18,7].Algorithmicdebuggingisaninteractiveprocesswheretheuserisaskedtodierentiatebetweentheactualmodelofthe(presumeablybuggy)programandtheuser'sintendedmodel.Basedontheuser'sinput,thesystemthentriestolocatethefaultyrulesinaninteractiveses-sion.Ourapproachdiersinanumberofaspects.First,algorithmicdebuggingisusuallybasedonaspecicoperationalsemantics,i.e.,SLDNFresolution,atop-down,left-to-rightstrategywithbacktrackingandnegation-as-failure,whichdierssignicantlyfromthedeclarativeDatalogsemantics(cf.Section1).More-over,whileourapproachisapplicable,inprinciple,inaninteractiveway,thissuggestsatightercouplingbetweenthedebuggerandtheunderlyingruleen-gine.Incontrast,ourapproachanditsGpadimplementationsdonotrequiresuchtightcoupling,butinsteadtreattheruleengineasablackbox.Inthisway,debuggingbecomesapost-mortemanalysisoftheprovenance-enrichedmodel^M=^P(I)viasimpleyetpowerfulgraphqueriesandaggregations.Anotherapproach,morecloselyrelatedtoours,istheDatalogdebugger[3],developedfortheDESsystem.Unlikepriorwork,andsimilartoours,theydonotviewderivationsasSLDprooftrees,butratheruseacomputationgraph,similartoourlabeledprovenancegraph.Ourapproachdiersinanumberofways,e.g.,ourreicationofderivationsinalabeledgraphallowsustouseregularpathqueriestonavigatetheprovenancegraph,locate(least)commonancestorsofbuggyatoms,etc.AnotherdierenceisouruseofStatelogforkeepingtrackofderivationrounds,whichfacilitatesprolingofthemodelcomputationovertime(perringround,identifytherulesred,thenumberof(re-)derivationsperatomorrelation,etc.)RecentrelatedworkalsoincludesworkontracevisualizationforASP[4],step-by-stepexecutionofASPprograms[15],andanintegrateddebuggingenvironmentforDLV[16].DebuggingandProvenance.Chiticariuetal.[5]presentatoolfordebuggingdatabaseschemamappings.Theyfocusonthecomputationofderivationroutesfromsourcefactstoatarget.Themethodincludesthecomputationofminimalroutes,similartoshortestderivationsinourgraph.However,theirapproach seemslessconducivetoprolingsince,e.g.,provenanceinformationonringroundsisnotavailableintheirapproach.Thereisanintruiginglycloserelationshipbetweenprovenancesemirings,i.e.,provenancepolynomialsandformalpowerseries[8],andourlabeledprovenancegraphsG.ThesemiringprovenanceofatomAisrepresentedinthestructureofGA.Consider,e.g.,Figure2:thein-edgesofruleringscorrespondtoalogicalconjunction\^",ormoreabstractly,theproductoperator\ "ofthesemiring.Similarly,out-edgesrepresentadisjunction\_",i.e.,anabstractsumoperator\",mirroringthefactthatatomsingeneralhavemultiplederivations.ItiseasytoseethatafactAhasaninnitenumberofderivations(prooftrees)ithereisacycleinGA:e.g.,thederivationofA=tc(a;b)inFigures1and2involvesacyclethroughtc(b,b),tc(c,b),viatworingsofr2.ThisalsoexplainsProlog'snon-termination(Section1),which\nicely"mirrorsthefactthatthereareinnitelymanyprooftrees.Ontheotherhand,suchcyclesarenotproblematicintheoriginalDatalogevaluationofM=P(I)orinourextendedprovenancemodel^M=^P(I),bothofwhichcanbeshowntoconvergeinpolynomialtime.6ConclusionsWehavepresentedaframeworkfordeclarativedebuggingandprolingofData-logprograms.ThekeyideaistorewriteaprogramPinto^P,whichrecordsthederivationhistoryofM=P(I)inanextendedmodel^M=^P(I).^Pisobtainedfromthreesimplerewritingsfor(1)recordingrulerings,(2)reifyingthoseintoalabeledgraph,while(3)keepingtrackofderivationroundsinthestyleofStatelog.Aftertherewrittenprogramisevaluated,theresultingprovenancegraphcanbequeriedandvisualizedfordebuggingandprolingpurposes.Wehaveillustratedthedeclarativeprolingapproachbyanalyzingdierent,logicallyequivalentversionsofthetransitiveclosureprogramPtc.Themeasuresobtainedthroughlogicprolingcorrelatewithruntimemeasuresforalarge,real-worldexample.TwoprototypicalsystemsGpad/dlvandGpad/lbhavebeenimplemented,forDLVandLogicBlox,respectively;apublicreleaseisplannedforthenearfuture.WhilewehavepresentedourapproachforpositiveDatalogonly,itisnotdiculttoseehowitcanbeextended,e.g.,forwell-foundedDatalog.Indeed,theGpadprototypesalreadysupportthehandlingofwell-foundednegationthroughasimpleStatelogencoding[11,13].Acknowledgments.WorksupportedinpartbyNSFawardsOCI-0722079,IIS-1118088,andagiftfromLogicBlox,Inc.References[1]Abiteboul,S.,Hull,R.,Vianu,V.:FoundationsofDatabases.Addison-Wesley(1995)[2]Bancilhon,F.,Ramakrishnan,R.:AnAmateur'sIntroductiontoRecursiveQueryProcessingStrategies.In:ReadingsinDatabaseSystems.pp.507{555(1988)