260 likes | 385 Views
Optimal Divide & Query. David Insa Cabrera. Contents. Introduction. Declarative Debugging. Divide & Query. Limitations of Divide & Query. Optimal Divide & Query. Demonstration. DDJ. Conclusions. Declarative Debugging. Declarative Debugging [ Shapiro 82] Logic paradigm
E N D
Optimal Divide & Query David Insa Cabrera
Contents Introduction DeclarativeDebugging Divide & Query Limitations of Divide & Query Optimal Divide & Query Demonstration DDJ Conclusions
DeclarativeDebugging • DeclarativeDebugging[Shapiro 82]Logicparadigm • TWO PHASES: • Generatetheexecutiontree • Traversetheexecutiontreeaskingquestionsuntilitfindsthe bug If a symptom of an error isdetected thenthe AD willfindthe bug main = 4 WhatisanExecutionTree? listSum [1,2] = 4 Example: main = listSum [1,2] listSum [] = 1 listSum (x:xs) = x + (listSumxs) 1+3 = 4 listSum [2] = 3 2+1 = 3 listSum [] = 1
DeclarativeDebugging • Traversingtheexecutiontree • GOLD RULE:When a wrongnode has notanywrongchildrenthen • thisnodeis a buggynode. main = 4 listSum [1,2] = 4 Example: main = listSum [1,2] listSum [] = 1 listSum (x:xs) = x + (listSumxs) 1+3 = 4 listSum [2] = 3 2+1 = 3 listSum [] = 1
DeclarativeDebugging • Traversingtheexecutiontree • GOLD RULE:When a wrongnode has notanywrongchildrenthen • thisnodeis a buggynode. main = 5 listSum [1,2] = 5 Example: main = listSum [1,2] listSum [] = 0 listSum (x:xs) = x + (listSumxs) + 1 1+3+1 = 5 listSum [2] = 3 2+0+1 = 3 listSum [] = 0
DeclarativeDebugging • do • node = selectNode(T) • answer = askNode(node) • if (answer = NO) • then M(node) = Wrong • buggyNode = node • N = {n ∈ N | (node n) ∈ E*} • elseN = N \ {n ∈N | (noden) ∈E*} • while (∃n ∈N, M(n) = Undefined) • returnbuggyNode
Contents Introduction DeclarativeDebugging • Strategies of AD Divide & Query • Debuggingsession Limitations of Divide & Query Optimal Divide & Query Demonstration DDJ Conclusions
Strategies of DeclarativeDebugging Strategies Single Stepping Single Stepping Divide & Query Top Down Top Down - Left to Right Top Down - Heaviest First Top Down - More Rules First Divide & Query (by Shapiro) Divide & Query (by Hirunkitti) Divide by Rules & Query Hat Delta Hat Delta - More Wrongs Hat Delta - Less Rights Hat Delta - Best Division
Debuggingsession Debuggingsession main = sqrTest[1,2] sqrTestx = test (squares (listSumx)) test (x,y,z) = (x==y) && (y==z) listSum[] = 0 listSum(x:xs) = x + (listSumxs) squares x = ((square1 x),(square2 x),(square3 x)) square1 x = square x square x = x*x square2 x = listSum(list x x) list x y | y==0 = [] | otherwise = x:list x (y-1) square3 x = listSum(partialSumsx) partialSumsx = [(sum1 x),(sum2 x)] sum1 x = div (x * (incr x)) 2 sum2 x = div (x + (decr x)) 2 incr x = x + 1 decr x = x - 1
Debuggingsession DebuggingsessionusingDivide & Query(byHirunkitti). main = False Startingthedebuggingsession… square2 3 = 9? YES square3 3 = 8? NO partialSums 3 = [6,2]? NO sum1 3 = 6? YES sum2 3 = 2? NO decr 3 = 2? YES Bug found in rule: sum2 x = div (x + (decr x)) 2 sqrTest [1,2] = False test (9,9,8) = False squares 3 = (9,9,8) listSum [1,2] = 3 listSum [2] = 2 squares1 3 = 9 squares2 3 = 9 squares3 3 = 8 listSum [] = 0 square 3 = 9 listSum [3,3,3] = 9 list 3 3 = [3,3,3] partialSums 3 = [6,2] listSum [6,2] = 8 listSum [3,3] = 6 list 3 2 = [3,3] listSum [2] = 2 sum1 3 = 6 sum2 3 = 2 decr 3 = 2 listSum [3] = 3 list 3 1 = [3] listSum [] = 0 incr 3 = 4 listSum [] = 0 list 3 0 = []
Contents Introduction DeclarativeDebugging Divide & Query Limitations of Divide & Query Optimal Divide & Query Demonstration DDJ Conclusions
Counterexample 1 3 2 8 1 3 3 3 3 3 2 5 1 1 1 1 1 2 2 2 2 2 2 4 1 1 1 1 1 1 2 1 1 1 1 1 1 9 8
Counterexample 2 3 2 5 5 3 2 4 4 3 3 2 1 2 1 2 3 3 3 1 1 2 3 16 16
Limitations 6 6,5 6 6,5 3 2 3,5 2 3 2 3,5 2 1 1 1 1 2 2,5 2 2,5 1 1 1 1
Contents Introduction DeclarativeDebugging Divide & Query Limitations of Divide & Query Optimal Divide & Query Demonstration DDJ Conclusions
Up and Down Up(n’) = Down(n’) |un’ – dn’| < |un’’- dn’’| 8 6 2 x/2 * x/2 4 1 1 0 * x d u 0 x x/2 2 1 1 Equation 1: wn = Up(n’) + Down(n’) + win’ Equation 2: wn’ = Down(n’) + win’
Equation 8 6 2 4 1 1 2 1 1
Path 7 7 7 7 5 2 5 2 5 2 5 2 1 1 1 1 4 4 4 4 3 3 3 3 1 1 1 1 1 1 1 1 Case 2 Case 4 Case 1 Case 3
Algorithm Candidate = root do Best = Candidate Children = {m | (Best→m) ∈E} if (Children =∅) thenreturn Best Candidate = n‘ | ∀n’’ with n’, n’’ ∈ Children, wn’ ≥ wn’’ while (wCandidate > wroot/2) if (M(Best) = Wrong) thenreturnCandidate if(wroot ≥ wBest + wCandidate – wiroot) thenreturnBest elsereturnCandidate
Algorithm Candidate = root do Best = Candidate Children = {m | (Best→m) ∈E} if (Children =∅) thenreturn Best Candidate = n‘ | ∀n’’ with n’, n’’ ∈ Children, wn’ ≥ wn’’ while (wCandidate > wroot/2) if (M(Best) = Wrong) thenreturnCandidate if(wroot ≥ wBest + wCandidate – wiroot) thenreturnBest elsereturnCandidate 20 8 5 2 12 1 3 11 12 8 3 4 1 1 5 7 2 5 1 1 2 1 1 1 4 1 1 1
General Algorithm Candidate = root do Best = Candidate Children = {m | (Best→m) ∈E} if (Children =∅) thenreturn Best Candidate = n′ |∀n′′ withn′ , n′′ ∈Children, wn’ ≥ wn′′ while (wCandidate− wiCandidate/2 > wroot/2) Candidate = n‘ ∈ Children | ∀n’’ ∈ Children, wn′ − win′/2 ≥ wn′′ − win′′/2 if (M(Best) = Wrong) thenreturnCandidate if (wroot ≥ wBest + wCandidate – wiBest/2 – wiCandidate/2) thenreturnBest elsereturnCandidate
Contents Introduction DeclarativeDebugging Divide & Query Limitations of Divide & Query Optimal Divide & Query Demonstration DDJ Conclusions
Contents Introduction DeclarativeDebugging Divide & Query Limitations of Divide & Query Optimal Divide & Query Demonstration DDJ Conclusions
Conclusions WehaveadaptedDivide & Querytothree new situations Rootmarked as Undefined Variable individual weights 6 6,5 6 6,5 Analgorithmforeachkind of tree Completeness 3 2 3,5 2 3 2 3,5 2 1 1 1 1 2 2,5 2 2,5 1 1 1 1