finding fixed points faster
play

Finding fixed points faster Michael Arntzenius University of - PowerPoint PPT Presentation

Finding fixed points faster Michael Arntzenius University of Birmingham S-REPLS 5, 2016 Datalog Datafun + + semi-na ve incremental evaluation -calculus 1 Datalog 3 Datafun + + 2 semi-na 4 incremental ve evaluation


  1. Finding fixed points faster Michael Arntzenius University of Birmingham S-REPLS 5, 2016

  2. Datalog Datafun + + ⊆ semi-na¨ ıve incremental evaluation λ -calculus

  3. 1 Datalog 3 Datafun + + ⊆ 2 semi-na¨ 4 incremental ıve evaluation λ -calculus

  4. Finding fixed points faster by static incrementalization

  5. Datalog decidable logic programming predicates = finite sets

  6. % Transitive closure of ‘edge’. path(X,Y) :- edge(X,Y). path(X,Z) :- edge(X,Y), path(Y,Z).

  7. Na¨ ıve implementation step : Set ( Node × Node ) → Set ( Node × Node ) step path = { ( x , y ) | ( x , y ) ∈ edge } ∪ { ( x , z ) | ( x , y ) ∈ edge , ( y , z ) ∈ path } fix : ( α → α ) → α → α fix f current = let next = f current in if next = current then current else fix f next path : Set ( Node × Node ) path = fix step ∅

  8. Na¨ ıve implementation step : Set ( Node × Node ) → Set ( Node × Node ) step path = { ( x , y ) | ( x , y ) ∈ edge } ∪ { ( x , z ) | ( x , y ) ∈ edge , ( y , z ) ∈ path } fix : ( α → α ) → α → α fix f current = let next = f current in if next = current then current else fix f next path : Set ( Node × Node ) path = fix step ∅ Unnecessary recomputation!

  9. Semi-na¨ ıve implementation small-step : Set ( Node × Node ) → Set ( Node × Node ) small-step new = { ( x , z ) | ( x , y ) ∈ edges , ( y , z ) ∈ new }

  10. Semi-na¨ ıve implementation small-step : Set ( Node × Node ) → Set ( Node × Node ) small-step new = { ( x , z ) | ( x , y ) ∈ edges , ( y , z ) ∈ new } fix-faster : ( Set α → Set α → Set α ) → Set α → Set α → Set α fix-faster f current new = let to-add = f current new in if to-add ⊆ current then current else fix-faster f ( current ∪ to-add ) to-add

  11. Semi-na¨ ıve implementation small-step : Set ( Node × Node ) → Set ( Node × Node ) small-step new = { ( x , z ) | ( x , y ) ∈ edges , ( y , z ) ∈ new } fix-faster : ( Set α → Set α → Set α ) → Set α → Set α → Set α fix-faster f current new = let to-add = f current new in if to-add ⊆ current then current else fix-faster f ( current ∪ to-add ) to-add path : Set ( Node × Node ) path = fix-faster ( λ x dx . small-step dx ) edge edge

  12. fix : ( α → α ) → α → α as iteration, not laziness

  13. Datafun ◮ Simply-typed λ -calculus ◮ with iterative fixed points ◮ and monotonicity typing (and other stuff, see ICFP’16 paper)

  14. Datalog: path(X,Y) :- edge(X,Y). path(X,Z) :- edge(X,Y), path(Y,Z). Datafun: fix path is edge ∪ { ( x , z ) | ( x , y ) ∈ edge , ( y , z ) ∈ path }

  15. Na¨ ıve implementation strategy for fix path is edge ∪ { ( x , z ) | ( x , y ) ∈ edge , ( y , z ) ∈ path } is fix ( λ path . edge ∪ { ( x , z ) | ( x , y ) ∈ edge , ( y , z ) ∈ path } ) ∅ using our iterative ‘fix’ function from earlier. Is there an analogue of faster-fix ?

  16. Incremental λ -Calculus “A Theory of Changes for Higher-Order Languages”, PLDI’14 Yufei Cai, Paulo Giarrusso, Tillman Rendel, Klaus Ostermann

  17. For every type A ◮ a change type ∆ A ◮ and operator ⊕ : A → ∆ A → A . Given term f : A → B ◮ δ f : A → ∆ A → ∆ B ◮ such that f ( x ⊕ dx ) = f x ⊕ δ f x dx if one knows v = f x , often cheaper to compute RHS!

  18. ( λ x dx . small-step dx ) ≈ δ ( step ) !

  19. ( λ x dx . small-step dx ) ≈ δ ( step ) ! step path = { ( x , y ) | ( x , y ) ∈ edge } ∪ { ( x , z ) | ( x , y ) ∈ edge , ( y , z ) ∈ path } small-step : Set ( Node × Node ) → Set ( Node × Node ) small-step new = { ( x , z ) | ( x , y ) ∈ edges , ( y , z ) ∈ new }

  20. ( λ x dx . small-step dx ) ≈ δ ( step ) ! step path = { ( x , y ) | ( x , y ) ∈ edge } ∪ { ( x , z ) | ( x , y ) ∈ edge , ( y , z ) ∈ path } small-step : Set ( Node × Node ) → Set ( Node × Node ) small-step new = { ( x , z ) | ( x , y ) ∈ edges , ( y , z ) ∈ new } Find fixed points faster by static incrementalization!

  21. faster-fix : ( α → ∆α → ∆α ) → α → ∆α → α faster-fix df current change = let next = current ⊕ change in if next ≤ current then current else faster-fix df next ( df current change ) (I have a proof in my notes that this slide is too small to contain.)

  22. Applying this to Datafun ◮ Monotonicity → increasing changes only! ∆ ( Set α ) = Set α ◮ ∆ ( � A ) = 1? No! Zero-changes are not trivial! ◮ δ ( � ( x ∈ e 1 ) e 2 ) ? In particular, if e 1 : Set ( A → B ) .

Recommend


More recommend