unification
play

Unification Temur Kutsia RISC, Johannes Kepler University Linz, - PowerPoint PPT Presentation

Unification Temur Kutsia RISC, Johannes Kepler University Linz, Austria kutsia@risc.jku.at Improving the Recursive Descent Algorithm Improvement 1: Linear Space, Exponential Time Improvement 2. Linear Space, Quadratic Time


  1. RDA on Term Dags. Example 1 Algorithm run starts with Unify1 ( 1 , 7 ) and continues: Unify1 ( Find (2), Find (8)) Find ( 2 ) = ( 2 ) f ( 1 ) f ( 7 ) Find ( 8 ) = ( 8 ) Occur ( 2 , 8 ) = False x ( 2 ) g ( 3 ) g ( 4 ) g ( 8 ) g ( 9 ) a ( 5 ) z ( 6 ) y ( 10 )

  2. RDA on Term Dags. Example 1 Algorithm run starts with Unify1 ( 1 , 7 ) and continues: Unify1 ( Find (2), Find (8)) Find ( 2 ) = ( 2 ) f ( 1 ) f ( 7 ) Find ( 8 ) = ( 8 ) Occur ( 2 , 8 ) = False x ( 2 ) g ( 3 ) g ( 4 ) g ( 8 ) g ( 9 ) Union ( 2 , 8 ) a ( 5 ) z ( 6 ) y ( 10 )

  3. RDA on Term Dags. Example 1 Algorithm run starts with Unify1 ( 1 , 7 ) and continues: Unify1 ( Find (2), Find (8)) Find ( 2 ) = ( 2 ) f ( 1 ) f ( 7 ) Find ( 8 ) = ( 8 ) Occur ( 2 , 8 ) = False x ( 2 ) g ( 3 ) g ( 4 ) g ( 8 ) g ( 9 ) Union ( 2 , 8 ) Unify1 ( Find ( 3 ) , Find ( 9 )) a ( 5 ) z ( 6 ) y ( 10 )

  4. RDA on Term Dags. Example 1 Algorithm run starts with Unify1 ( 1 , 7 ) and continues: Unify1 ( Find (2), Find (8)) Find ( 2 ) = ( 2 ) f ( 1 ) f ( 7 ) Find ( 8 ) = ( 8 ) Occur ( 2 , 8 ) = False x ( 2 ) g ( 3 ) g ( 4 ) g ( 8 ) g ( 9 ) Union ( 2 , 8 ) Unify1 ( Find ( 3 ) , Find ( 9 )) a ( 5 ) z ( 6 ) y ( 10 ) Find ( 3 ) = ( 3 )

  5. RDA on Term Dags. Example 1 Algorithm run starts with Unify1 ( 1 , 7 ) and continues: Unify1 ( Find (2), Find (8)) Find ( 2 ) = ( 2 ) f ( 1 ) f ( 7 ) Find ( 8 ) = ( 8 ) Occur ( 2 , 8 ) = False x ( 2 ) g ( 3 ) g ( 4 ) g ( 8 ) g ( 9 ) Union ( 2 , 8 ) Unify1 ( Find ( 3 ) , Find ( 9 )) a ( 5 ) z ( 6 ) y ( 10 ) Find ( 3 ) = ( 3 ) Find ( 9 ) = ( 9 )

  6. RDA on Term Dags. Example 1 Algorithm run starts with Unify1 ( 1 , 7 ) and continues: Unify1 ( Find (2), Find (8)) Find ( 2 ) = ( 2 ) f ( 1 ) f ( 7 ) Find ( 8 ) = ( 8 ) Occur ( 2 , 8 ) = False x ( 2 ) g ( 3 ) g ( 4 ) g ( 8 ) g ( 9 ) Union ( 2 , 8 ) Unify1 ( Find ( 3 ) , Find ( 9 )) a ( 5 ) z ( 6 ) y ( 10 ) Find ( 3 ) = ( 3 ) Find ( 9 ) = ( 9 ) Unify1 ( Find ( 5 ) , Find ( 10 ))

  7. RDA on Term Dags. Example 1 Algorithm run starts with Unify1 ( 1 , 7 ) and continues: Unify1 ( Find (2), Find (8)) Find ( 2 ) = ( 2 ) f ( 1 ) f ( 7 ) Find ( 8 ) = ( 8 ) Occur ( 2 , 8 ) = False x ( 2 ) g ( 3 ) g ( 4 ) g ( 8 ) g ( 9 ) Union ( 2 , 8 ) Unify1 ( Find ( 3 ) , Find ( 9 )) a ( 5 ) z ( 6 ) y ( 10 ) Find ( 3 ) = ( 3 ) Find ( 9 ) = ( 9 ) Unify1 ( Find ( 5 ) , Find ( 10 )) Find ( 5 ) = 5

  8. RDA on Term Dags. Example 1 Algorithm run starts with Unify1 ( 1 , 7 ) and continues: Unify1 ( Find (2), Find (8)) Find ( 2 ) = ( 2 ) f ( 1 ) f ( 7 ) Find ( 8 ) = ( 8 ) Occur ( 2 , 8 ) = False x ( 2 ) g ( 3 ) g ( 4 ) g ( 8 ) g ( 9 ) Union ( 2 , 8 ) Unify1 ( Find ( 3 ) , Find ( 9 )) a ( 5 ) z ( 6 ) y ( 10 ) Find ( 3 ) = ( 3 ) Find ( 9 ) = ( 9 ) Unify1 ( Find ( 5 ) , Find ( 10 )) Find ( 5 ) = 5 Find ( 10 ) = 10

  9. RDA on Term Dags. Example 1 Algorithm run starts with Unify1 ( 1 , 7 ) and continues: Unify1 ( Find (2), Find (8)) Find ( 2 ) = ( 2 ) f ( 1 ) f ( 7 ) Find ( 8 ) = ( 8 ) Occur ( 2 , 8 ) = False x ( 2 ) g ( 3 ) g ( 4 ) g ( 8 ) g ( 9 ) Union ( 2 , 8 ) Unify1 ( Find ( 3 ) , Find ( 9 )) a ( 5 ) z ( 6 ) y ( 10 ) Find ( 3 ) = ( 3 ) Find ( 9 ) = ( 9 ) Unify1 ( Find ( 5 ) , Find ( 10 )) Find ( 5 ) = 5 Find ( 10 ) = 10 orient ( 10 , 5 )

  10. RDA on Term Dags. Example 1 Algorithm run starts with Unify1 ( 1 , 7 ) and continues: Unify1 ( Find (2), Find (8)) Find ( 2 ) = ( 2 ) f ( 1 ) f ( 7 ) Find ( 8 ) = ( 8 ) Occur ( 2 , 8 ) = False x ( 2 ) g ( 3 ) g ( 4 ) g ( 8 ) g ( 9 ) Union ( 2 , 8 ) Unify1 ( Find ( 3 ) , Find ( 9 )) a ( 5 ) z ( 6 ) y ( 10 ) Find ( 3 ) = ( 3 ) Find ( 9 ) = ( 9 ) Unify1 ( Find ( 5 ) , Find ( 10 )) Find ( 5 ) = 5 Find ( 10 ) = 10 orient ( 10 , 5 ) Occur ( 10 , 5 ) = False

  11. RDA on Term Dags. Example 1 Algorithm run starts with Unify1 ( 1 , 7 ) and continues: Unify1 ( Find (2), Find (8)) Find ( 2 ) = ( 2 ) f ( 1 ) f ( 7 ) Find ( 8 ) = ( 8 ) Occur ( 2 , 8 ) = False x ( 2 ) g ( 3 ) g ( 4 ) g ( 8 ) g ( 9 ) Union ( 2 , 8 ) Unify1 ( Find ( 3 ) , Find ( 9 )) a ( 5 ) z ( 6 ) y ( 10 ) Find ( 3 ) = ( 3 ) Find ( 9 ) = ( 9 ) Unify1 ( Find ( 5 ) , Find ( 10 )) Find ( 5 ) = 5 Find ( 10 ) = 10 orient ( 10 , 5 ) Occur ( 10 , 5 ) = False Union ( 10 , 5 )

  12. RDA on Term Dags. Example 1 Algorithm run starts with Unify1 ( 1 , 7 ) and continues: f ( 1 ) f ( 7 ) x ( 2 ) g ( 3 ) g ( 4 ) g ( 8 ) g ( 9 ) a ( 5 ) z ( 6 ) y ( 10 )

  13. RDA on Term Dags. Example 1 Algorithm run starts with Unify1 ( 1 , 7 ) and continues: Unify1 ( Find ( 4 ) , Find ( 2 )) f ( 1 ) f ( 7 ) x ( 2 ) g ( 3 ) g ( 4 ) g ( 8 ) g ( 9 ) a ( 5 ) z ( 6 ) y ( 10 )

  14. RDA on Term Dags. Example 1 Algorithm run starts with Unify1 ( 1 , 7 ) and continues: Unify1 ( Find ( 4 ) , Find ( 2 )) Find ( 4 ) = 4 f ( 1 ) f ( 7 ) x ( 2 ) g ( 3 ) g ( 4 ) g ( 8 ) g ( 9 ) a ( 5 ) z ( 6 ) y ( 10 )

  15. RDA on Term Dags. Example 1 Algorithm run starts with Unify1 ( 1 , 7 ) and continues: Unify1 ( Find ( 4 ) , Find ( 2 )) Find ( 4 ) = 4 f ( 1 ) f ( 7 ) Find ( 2 ) = 8 x ( 2 ) g ( 3 ) g ( 4 ) g ( 8 ) g ( 9 ) a ( 5 ) z ( 6 ) y ( 10 )

  16. RDA on Term Dags. Example 1 Algorithm run starts with Unify1 ( 1 , 7 ) and continues: Unify1 ( Find ( 4 ) , Find ( 2 )) Find ( 4 ) = 4 f ( 1 ) f ( 7 ) Find ( 2 ) = 8 Unify1 ( 4 , 8 ) x ( 2 ) g ( 3 ) g ( 4 ) g ( 8 ) g ( 9 ) a ( 5 ) z ( 6 ) y ( 10 )

  17. RDA on Term Dags. Example 1 Algorithm run starts with Unify1 ( 1 , 7 ) and continues: Unify1 ( Find ( 4 ) , Find ( 2 )) Find ( 4 ) = 4 f ( 1 ) f ( 7 ) Find ( 2 ) = 8 Unify1 ( 4 , 8 ) x ( 2 ) g ( 3 ) g ( 4 ) g ( 8 ) g ( 9 ) Unify1 ( Find ( 6 ) , Find ( 10 )) a ( 5 ) z ( 6 ) y ( 10 )

  18. RDA on Term Dags. Example 1 Algorithm run starts with Unify1 ( 1 , 7 ) and continues: Unify1 ( Find ( 4 ) , Find ( 2 )) Find ( 4 ) = 4 f ( 1 ) f ( 7 ) Find ( 2 ) = 8 Unify1 ( 4 , 8 ) x ( 2 ) g ( 3 ) g ( 4 ) g ( 8 ) g ( 9 ) Unify1 ( Find ( 6 ) , Find ( 10 )) Find ( 6 ) = 6 a ( 5 ) z ( 6 ) y ( 10 )

  19. RDA on Term Dags. Example 1 Algorithm run starts with Unify1 ( 1 , 7 ) and continues: Unify1 ( Find ( 4 ) , Find ( 2 )) Find ( 4 ) = 4 f ( 1 ) f ( 7 ) Find ( 2 ) = 8 Unify1 ( 4 , 8 ) x ( 2 ) g ( 3 ) g ( 4 ) g ( 8 ) g ( 9 ) Unify1 ( Find ( 6 ) , Find ( 10 )) Find ( 6 ) = 6 a ( 5 ) z ( 6 ) y ( 10 ) Find ( 10 ) = 5

  20. RDA on Term Dags. Example 1 Algorithm run starts with Unify1 ( 1 , 7 ) and continues: Unify1 ( Find ( 4 ) , Find ( 2 )) Find ( 4 ) = 4 f ( 1 ) f ( 7 ) Find ( 2 ) = 8 Unify1 ( 4 , 8 ) x ( 2 ) g ( 3 ) g ( 4 ) g ( 8 ) g ( 9 ) Unify1 ( Find ( 6 ) , Find ( 10 )) Find ( 6 ) = 6 a ( 5 ) z ( 6 ) y ( 10 ) Find ( 10 ) = 5 Occur ( 6 , 5 ) = False

  21. RDA on Term Dags. Example 1 Algorithm run starts with Unify1 ( 1 , 7 ) and continues: Unify1 ( Find ( 4 ) , Find ( 2 )) Find ( 4 ) = 4 f ( 1 ) f ( 7 ) Find ( 2 ) = 8 Unify1 ( 4 , 8 ) x ( 2 ) g ( 3 ) g ( 4 ) g ( 8 ) g ( 9 ) Unify1 ( Find ( 6 ) , Find ( 10 )) Find ( 6 ) = 6 a ( 5 ) z ( 6 ) y ( 10 ) Find ( 10 ) = 5 Occur ( 6 , 5 ) = False Union ( 6 , 5 )

  22. RDA on Term Dags. Example 1 Algorithm run starts with Unify1 ( 1 , 7 ) and continues: Unify1 ( Find ( 4 ) , Find ( 2 )) Find ( 4 ) = 4 f ( 1 ) f ( 7 ) Find ( 2 ) = 8 Unify1 ( 4 , 8 ) x ( 2 ) g ( 3 ) g ( 4 ) g ( 8 ) g ( 9 ) Unify1 ( Find ( 6 ) , Find ( 10 )) Find ( 6 ) = 6 a ( 5 ) z ( 6 ) y ( 10 ) Find ( 10 ) = 5 Occur ( 6 , 5 ) = False Union ( 6 , 5 ) True

  23. RDA on Term Dags. Example 1 (Cont.) f ( 1 ) f ( 7 ) x ( 2 ) g ( 3 ) g ( 4 ) g ( 8 ) g ( 9 ) a ( 5 ) z ( 6 ) y ( 10 ) ◮ From the final dag one can read off: ◮ The unified term f ( g ( a ) , g ( a ) , g ( a )) . ◮ The mgu in triangular form [ x �→ g ( y ); y �→ a ; z �→ a ] . ◮ The algorithm does not create new nodes. Only one extra pointer for each variable node. ◮ Needs linear space. ◮ Time is still exponential. See the next example.

  24. RDA on Term Dags. Example 2 Consider again the problem: s = h ( x 1 , x 2 , . . . , x n , f ( y 0 , y 0 ) , f ( y 1 , y 1 ) , . . . , f ( y n − 1 , y n − 1 ) , y n ) t = h ( f ( x 0 , x 0 ) , f ( x 1 , x 1 ) , . . . , f ( x n − 1 , x n − 1 ) , y 1 , y 2 , . . . , y n , x n ) A dag representation of the term bound to x n and y n : y n x n f f x n − 1 y n − 1 f f x 1 y 1 f f x 0 y 0 Exponential number of recursive calls.

  25. RDA on Term Dags. Example 2 Consider again the problem: s = h ( x 1 , x 2 , . . . , x n , f ( y 0 , y 0 ) , f ( y 1 , y 1 ) , . . . , f ( y n − 1 , y n − 1 ) , y n ) t = h ( f ( x 0 , x 0 ) , f ( x 1 , x 1 ) , . . . , f ( x n − 1 , x n − 1 ) , y 1 , y 2 , . . . , y n , x n ) A dag representation of the term bound to x n and y n : y n x n f f x n − 1 y n − 1 f f x 1 y 1 f f x 0 y 0 Exponential number of recursive calls.

  26. RDA on Term Dags. Example 2 Consider again the problem: s = h ( x 1 , x 2 , . . . , x n , f ( y 0 , y 0 ) , f ( y 1 , y 1 ) , . . . , f ( y n − 1 , y n − 1 ) , y n ) t = h ( f ( x 0 , x 0 ) , f ( x 1 , x 1 ) , . . . , f ( x n − 1 , x n − 1 ) , y 1 , y 2 , . . . , y n , x n ) A dag representation of the term bound to x n and y n : y n x n f f x n − 1 y n − 1 f f x 1 y 1 f f x 0 y 0 Exponential number of recursive calls.

  27. RDA on Term Dags. Example 2 Consider again the problem: s = h ( x 1 , x 2 , . . . , x n , f ( y 0 , y 0 ) , f ( y 1 , y 1 ) , . . . , f ( y n − 1 , y n − 1 ) , y n ) t = h ( f ( x 0 , x 0 ) , f ( x 1 , x 1 ) , . . . , f ( x n − 1 , x n − 1 ) , y 1 , y 2 , . . . , y n , x n ) A dag representation of the term bound to x n and y n : y n x n f f x n − 1 y n − 1 f f x 1 y 1 f f x 0 y 0 Exponential number of recursive calls.

  28. RDA on Term Dags. Example 2 Consider again the problem: s = h ( x 1 , x 2 , . . . , x n , f ( y 0 , y 0 ) , f ( y 1 , y 1 ) , . . . , f ( y n − 1 , y n − 1 ) , y n ) t = h ( f ( x 0 , x 0 ) , f ( x 1 , x 1 ) , . . . , f ( x n − 1 , x n − 1 ) , y 1 , y 2 , . . . , y n , x n ) A dag representation of the term bound to x n and y n : y n x n f f x n − 1 y n − 1 f f x 1 y 1 f f x 0 y 0 Exponential number of recursive calls.

  29. RDA on Term Dags. Example 2 Consider again the problem: s = h ( x 1 , x 2 , . . . , x n , f ( y 0 , y 0 ) , f ( y 1 , y 1 ) , . . . , f ( y n − 1 , y n − 1 ) , y n ) t = h ( f ( x 0 , x 0 ) , f ( x 1 , x 1 ) , . . . , f ( x n − 1 , x n − 1 ) , y 1 , y 2 , . . . , y n , x n ) A dag representation of the term bound to x n and y n : y n x n f f x n − 1 y n − 1 f f x 1 y 1 f f x 0 y 0 Exponential number of recursive calls.

  30. RDA on Term Dags. Example 2 Consider again the problem: s = h ( x 1 , x 2 , . . . , x n , f ( y 0 , y 0 ) , f ( y 1 , y 1 ) , . . . , f ( y n − 1 , y n − 1 ) , y n ) t = h ( f ( x 0 , x 0 ) , f ( x 1 , x 1 ) , . . . , f ( x n − 1 , x n − 1 ) , y 1 , y 2 , . . . , y n , x n ) A dag representation of the term bound to x n and y n : y n x n f f x n − 1 y n − 1 f f x 1 y 1 f f x 0 y 0 Exponential number of recursive calls.

  31. RDA on Term Dags. Example 2 Consider again the problem: s = h ( x 1 , x 2 , . . . , x n , f ( y 0 , y 0 ) , f ( y 1 , y 1 ) , . . . , f ( y n − 1 , y n − 1 ) , y n ) t = h ( f ( x 0 , x 0 ) , f ( x 1 , x 1 ) , . . . , f ( x n − 1 , x n − 1 ) , y 1 , y 2 , . . . , y n , x n ) A dag representation of the term bound to x n and y n : y n x n f f x n − 1 y n − 1 f f x 1 y 1 f f x 0 y 0 Exponential number of recursive calls.

  32. RDA on Term Dags. Example 2 Consider again the problem: s = h ( x 1 , x 2 , . . . , x n , f ( y 0 , y 0 ) , f ( y 1 , y 1 ) , . . . , f ( y n − 1 , y n − 1 ) , y n ) t = h ( f ( x 0 , x 0 ) , f ( x 1 , x 1 ) , . . . , f ( x n − 1 , x n − 1 ) , y 1 , y 2 , . . . , y n , x n ) A dag representation of the term bound to x n and y n : y n x n f f x n − 1 y n − 1 f f x 1 y 1 f f x 0 y 0 Exponential number of recursive calls.

  33. RDA on Term Dags. Example 2 Consider again the problem: s = h ( x 1 , x 2 , . . . , x n , f ( y 0 , y 0 ) , f ( y 1 , y 1 ) , . . . , f ( y n − 1 , y n − 1 ) , y n ) t = h ( f ( x 0 , x 0 ) , f ( x 1 , x 1 ) , . . . , f ( x n − 1 , x n − 1 ) , y 1 , y 2 , . . . , y n , x n ) A dag representation of the term bound to x n and y n : y n x n f f x n − 1 y n − 1 f f x 1 y 1 f f x 0 y 0 Exponential number of recursive calls.

  34. RDA on Term Dags. Example 2 Consider again the problem: s = h ( x 1 , x 2 , . . . , x n , f ( y 0 , y 0 ) , f ( y 1 , y 1 ) , . . . , f ( y n − 1 , y n − 1 ) , y n ) t = h ( f ( x 0 , x 0 ) , f ( x 1 , x 1 ) , . . . , f ( x n − 1 , x n − 1 ) , y 1 , y 2 , . . . , y n , x n ) A dag representation of the term bound to x n and y n : y n x n f f x n − 1 y n − 1 f f x 1 y 1 f f x 0 y 0 Exponential number of recursive calls.

  35. RDA on Term Dags. Example 2 Consider again the problem: s = h ( x 1 , x 2 , . . . , x n , f ( y 0 , y 0 ) , f ( y 1 , y 1 ) , . . . , f ( y n − 1 , y n − 1 ) , y n ) t = h ( f ( x 0 , x 0 ) , f ( x 1 , x 1 ) , . . . , f ( x n − 1 , x n − 1 ) , y 1 , y 2 , . . . , y n , x n ) A dag representation of the term bound to x n and y n : y n x n f f x n − 1 y n − 1 f f x 1 y 1 f f x 0 y 0 Exponential number of recursive calls.

  36. RDA on Term Dags. Example 2 Consider again the problem: s = h ( x 1 , x 2 , . . . , x n , f ( y 0 , y 0 ) , f ( y 1 , y 1 ) , . . . , f ( y n − 1 , y n − 1 ) , y n ) t = h ( f ( x 0 , x 0 ) , f ( x 1 , x 1 ) , . . . , f ( x n − 1 , x n − 1 ) , y 1 , y 2 , . . . , y n , x n ) A dag representation of the term bound to x n and y n : y n x n f f x n − 1 y n − 1 f f x 1 y 1 f f x 0 y 0 Exponential number of recursive calls.

  37. RDA on Term Dags. Example 2 Consider again the problem: s = h ( x 1 , x 2 , . . . , x n , f ( y 0 , y 0 ) , f ( y 1 , y 1 ) , . . . , f ( y n − 1 , y n − 1 ) , y n ) t = h ( f ( x 0 , x 0 ) , f ( x 1 , x 1 ) , . . . , f ( x n − 1 , x n − 1 ) , y 1 , y 2 , . . . , y n , x n ) A dag representation of the term bound to x n and y n : y n x n f f x n − 1 y n − 1 f f x 1 y 1 f f x 0 y 0 Exponential number of recursive calls.

  38. RDA on Term Dags. Example 2 Consider again the problem: s = h ( x 1 , x 2 , . . . , x n , f ( y 0 , y 0 ) , f ( y 1 , y 1 ) , . . . , f ( y n − 1 , y n − 1 ) , y n ) t = h ( f ( x 0 , x 0 ) , f ( x 1 , x 1 ) , . . . , f ( x n − 1 , x n − 1 ) , y 1 , y 2 , . . . , y n , x n ) A dag representation of the term bound to x n and y n : y n x n f f x n − 1 y n − 1 f f x 1 y 1 f f x 0 y 0 Exponential number of recursive calls.

  39. RDA on Term Dags. Example 2 Consider again the problem: s = h ( x 1 , x 2 , . . . , x n , f ( y 0 , y 0 ) , f ( y 1 , y 1 ) , . . . , f ( y n − 1 , y n − 1 ) , y n ) t = h ( f ( x 0 , x 0 ) , f ( x 1 , x 1 ) , . . . , f ( x n − 1 , x n − 1 ) , y 1 , y 2 , . . . , y n , x n ) A dag representation of the term bound to x n and y n : y n x n f f x n − 1 y n − 1 f f x 1 y 1 f f x 0 y 0 Exponential number of recursive calls.

  40. RDA on Term Dags. Example 2 Consider again the problem: s = h ( x 1 , x 2 , . . . , x n , f ( y 0 , y 0 ) , f ( y 1 , y 1 ) , . . . , f ( y n − 1 , y n − 1 ) , y n ) t = h ( f ( x 0 , x 0 ) , f ( x 1 , x 1 ) , . . . , f ( x n − 1 , x n − 1 ) , y 1 , y 2 , . . . , y n , x n ) A dag representation of the term bound to x n and y n : y n x n f f x n − 1 y n − 1 f f x 1 y 1 f f x 0 y 0 Exponential number of recursive calls.

  41. RDA on Term Dags. Example 2 Consider again the problem: s = h ( x 1 , x 2 , . . . , x n , f ( y 0 , y 0 ) , f ( y 1 , y 1 ) , . . . , f ( y n − 1 , y n − 1 ) , y n ) t = h ( f ( x 0 , x 0 ) , f ( x 1 , x 1 ) , . . . , f ( x n − 1 , x n − 1 ) , y 1 , y 2 , . . . , y n , x n ) A dag representation of the term bound to x n and y n : y n x n f f x n − 1 y n − 1 f f x 1 y 1 f f x 0 y 0 Exponential number of recursive calls.

  42. RDA on Term Dags. Example 2 Consider again the problem: s = h ( x 1 , x 2 , . . . , x n , f ( y 0 , y 0 ) , f ( y 1 , y 1 ) , . . . , f ( y n − 1 , y n − 1 ) , y n ) t = h ( f ( x 0 , x 0 ) , f ( x 1 , x 1 ) , . . . , f ( x n − 1 , x n − 1 ) , y 1 , y 2 , . . . , y n , x n ) A dag representation of the term bound to x n and y n : y n x n f f x n − 1 y n − 1 f f x 1 y 1 f f x 0 y 0 Exponential number of recursive calls.

  43. RDA on Term Dags. Example 2 Consider again the problem: s = h ( x 1 , x 2 , . . . , x n , f ( y 0 , y 0 ) , f ( y 1 , y 1 ) , . . . , f ( y n − 1 , y n − 1 ) , y n ) t = h ( f ( x 0 , x 0 ) , f ( x 1 , x 1 ) , . . . , f ( x n − 1 , x n − 1 ) , y 1 , y 2 , . . . , y n , x n ) A dag representation of the term bound to x n and y n : y n x n f f x n − 1 y n − 1 f f x 1 y 1 f f x 0 y 0 Exponential number of recursive calls.

  44. RDA on Term Dags. Example 2 Consider again the problem: s = h ( x 1 , x 2 , . . . , x n , f ( y 0 , y 0 ) , f ( y 1 , y 1 ) , . . . , f ( y n − 1 , y n − 1 ) , y n ) t = h ( f ( x 0 , x 0 ) , f ( x 1 , x 1 ) , . . . , f ( x n − 1 , x n − 1 ) , y 1 , y 2 , . . . , y n , x n ) A dag representation of the term bound to x n and y n : y n x n f f x n − 1 y n − 1 f f x 1 y 1 f f x 0 y 0 Exponential number of recursive calls.

  45. Correctness of RDA for Term Dags ◮ Proof is similar as for the RDA. These two algorithm differ only by the data structure they operate on.

  46. Complexity of RDA for Term Dags ◮ Linear space: terms are not duplicated anymore. ◮ Exponential time: Calls Unify1 recursively exponentially often.

  47. Complexity of RDA for Term Dags ◮ Linear space: terms are not duplicated anymore. ◮ Exponential time: Calls Unify1 recursively exponentially often. ◮ Fortunately, with an easy trick one can make the running time quadratic.

  48. Complexity of RDA for Term Dags ◮ Linear space: terms are not duplicated anymore. ◮ Exponential time: Calls Unify1 recursively exponentially often. ◮ Fortunately, with an easy trick one can make the running time quadratic. ◮ Idea: Keep from revisiting already-solved problems in the graph.

  49. Complexity of RDA for Term Dags ◮ Linear space: terms are not duplicated anymore. ◮ Exponential time: Calls Unify1 recursively exponentially often. ◮ Fortunately, with an easy trick one can make the running time quadratic. ◮ Idea: Keep from revisiting already-solved problems in the graph. ◮ The algorithm of Corbin and Bidoit: J. Corbin and M. Bidoit. A rehabilitation of Robinson’s unification algorithm. In R. Mason, editor, Information Processing 83 , pages 909–914. Elsevier Science, 1983.

  50. Quadratic Algorithm on Term Dags Input : A pair of nodes k 1 and k 2 in a dag Output : True if the terms corresponding to k 1 and k 2 are unifiable. False Otherwise. Side Effect : A pointer structure which allows to read off an mgu and the unified term. Unify2 ( k 1 , k 2 ) if k 1 = k 2 then return True ; /* Trivial */ else if function-node(k 2 ) then u := k 1 ; v := k 2 else u := k 2 ; v := k 1 ; /* Orient */ end Procedure Unify2 . Quadratic Algorithm. (No difference from Unify1 so far. Continues on the next slide)

  51. Quadratic Algorithm if variable-node(u) then if Occurs (u , v) ; /* Occur-check */ then return False else Union ( u , v ) ; /* Variable elimination */ return True end Procedure Unify2 . Quadratic Algorithm. Continued. (No difference from Unify1 so far. Continues on the next slide)

  52. Quadratic Algorithm else if function-symbol ( u ) � = function-symbol ( v ) then return False ; /* Symbol clash */ else n := arity ( function - symbol ( u )) ; ( u 1 , . . . , u n ) := succ - list ( u ) ; ( v 1 , . . . , v n ) := succ - list ( v ) ; i := 0 ; bool := True ; Union (u,v); while i ≤ n and bool do i := i + 1; bool := Unify2 ( Find ( u i ) , Find ( v i ) ); /* Decomposition */ end return bool Procedure Unify2 . Quadratic Algorithm. Finished. (The only difference from Unify1 is Union (u,v).)

  53. Quadratic Algorithm. Example The same example that revealed exponential behavior of RDA: y n x n f f x n − 1 y n − 1 f f x 1 y 1 f f x 0 y 0

  54. Quadratic Algorithm. Example The same example that revealed exponential behavior of RDA: y n x n f f x n − 1 y n − 1 f f x 1 y 1 f f x 0 y 0

  55. Quadratic Algorithm. Example The same example that revealed exponential behavior of RDA: y n x n f f x n − 1 y n − 1 f f x 1 y 1 f f x 0 y 0

  56. Quadratic Algorithm. Example The same example that revealed exponential behavior of RDA: y n x n f f x n − 1 y n − 1 f f x 1 y 1 f f x 0 y 0

  57. Quadratic Algorithm. Example The same example that revealed exponential behavior of RDA: y n x n f f x n − 1 y n − 1 f f x 1 y 1 f f x 0 y 0

  58. Quadratic Algorithm. Example The same example that revealed exponential behavior of RDA: y n x n f f x n − 1 y n − 1 f f x 1 y 1 f f x 0 y 0

  59. Quadratic Algorithm. Example The same example that revealed exponential behavior of RDA: y n x n f f x n − 1 y n − 1 f f x 1 y 1 f f x 0 y 0

  60. Quadratic Algorithm. Example The same example that revealed exponential behavior of RDA: y n x n f f x n − 1 y n − 1 f f x 1 y 1 f f x 0 y 0

  61. Quadratic Algorithm. Example The same example that revealed exponential behavior of RDA: y n x n f f x n − 1 y n − 1 f f x 1 y 1 f f x 0 y 0

  62. Quadratic Algorithm. Example The same example that revealed exponential behavior of RDA: y n x n f f x n − 1 y n − 1 f f x 1 y 1 f f x 0 y 0

  63. Quadratic Algorithm. Example The same example that revealed exponential behavior of RDA: y n x n f f x n − 1 y n − 1 f f x 1 y 1 f f x 0 y 0

  64. Quadratic Algorithm. Example The same example that revealed exponential behavior of RDA: y n x n f f x n − 1 y n − 1 f f x 1 y 1 f f x 0 y 0

  65. Quadratic Algorithm. Example The same example that revealed exponential behavior of RDA: y n x n f f x n − 1 y n − 1 f f x 1 y 1 f f x 0 y 0

  66. Properties of the Quadratic Algorithm ◮ Correctness can be shown in the similar way as for the RDA. ◮ The algorithm is quadratic in the number of symbols in original terms: ◮ Each call of Unify2 either returns immediately, or makes one more node unreachable for the Find operation. ◮ Therefore, there can be only linearly many calls of Unify2 . ◮ Quadratic complexity comes from the fact that Occur and Find operations are linear.

  67. Almost Linear Algorithm How to eliminate two sources of nonlinearity of Unify2 ? ◮ Occur : Just omit the occur check during the execution of the algorithm. ◮ Consequence: The data structure may contain cycles. ◮ Since the occur-check failures are not detected immediately, at the end an extra check has to be performed to find out whether the generated structure is cyclic or not. ◮ Detecting cycles in a directed graph can be done by linear search. ◮ Find : Use more efficient union-find algorithm from R. Tarjan. Efficiency of a good but not linear set union algorithm. J. ACM , 22(2):215–225, 1975.

  68. Auxiliary Procedures for the Almost Linear Algorithm ◮ Collapsing-find : ◮ Like Find it takes a node k of a dag as input, and follows the additional pointers until the node Find ( k ) is reached. ◮ In addition, Collapsing-find relocates the pointer of all the nodes reached during this process to Find ( k ) . Example f ( 1 ) f ( 4 ) x ( 2 ) a ( 3 ) y ( 5 )

  69. Auxiliary Procedures for the Almost Linear Algorithm ◮ Collapsing-find : ◮ Like Find it takes a node k of a dag as input, and follows the additional pointers until the node Find ( k ) is reached. ◮ In addition, Collapsing-find relocates the pointer of all the nodes reached during this process to Find ( k ) . Example f ( 1 ) f ( 4 ) ◮ CF (3)=(3) x ( 2 ) a ( 3 ) y ( 5 )

  70. Auxiliary Procedures for the Almost Linear Algorithm ◮ Collapsing-find : ◮ Like Find it takes a node k of a dag as input, and follows the additional pointers until the node Find ( k ) is reached. ◮ In addition, Collapsing-find relocates the pointer of all the nodes reached during this process to Find ( k ) . Example f ( 1 ) f ( 4 ) ◮ CF (3)=(3) x ( 2 ) a ( 3 ) y ( 5 ) ◮ CF (2)=

  71. Auxiliary Procedures for the Almost Linear Algorithm ◮ Collapsing-find : ◮ Like Find it takes a node k of a dag as input, and follows the additional pointers until the node Find ( k ) is reached. ◮ In addition, Collapsing-find relocates the pointer of all the nodes reached during this process to Find ( k ) . Example f ( 1 ) f ( 4 ) ◮ CF (3)=(3) x ( 2 ) a ( 3 ) y ( 5 ) ◮ CF (2)=

Recommend


More recommend