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

finding fixed points faster
SMART_READER_LITE
LIVE PREVIEW

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


slide-1
SLIDE 1

Finding fixed points faster

Michael Arntzenius

University of Birmingham

S-REPLS 5, 2016

slide-2
SLIDE 2

Datalog + semi-na¨ ıve evaluation

Datafun + incremental λ-calculus

slide-3
SLIDE 3

1 Datalog

+

2 semi-na¨

ıve evaluation

3 Datafun

+

4 incremental

λ-calculus

slide-4
SLIDE 4

Finding fixed points faster by static incrementalization

slide-5
SLIDE 5

Datalog

decidable logic programming predicates = finite sets

slide-6
SLIDE 6

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

slide-7
SLIDE 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 ∅

slide-8
SLIDE 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!

slide-9
SLIDE 9

Semi-na¨ ıve implementation

small-step : Set (Node × Node) → Set (Node × Node) small-step new = {(x, z) | (x, y) ∈ edges, (y, z) ∈ new}

slide-10
SLIDE 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

slide-11
SLIDE 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

slide-12
SLIDE 12

fix : (α → α) → α → α

as iteration, not laziness

slide-13
SLIDE 13

Datafun

◮ Simply-typed λ-calculus ◮ with iterative fixed points ◮ and monotonicity typing

(and other stuff, see ICFP’16 paper)

slide-14
SLIDE 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}

slide-15
SLIDE 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?

slide-16
SLIDE 16

Incremental λ-Calculus

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

slide-17
SLIDE 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!

slide-18
SLIDE 18

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

slide-19
SLIDE 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}

slide-20
SLIDE 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!

slide-21
SLIDE 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.)

slide-22
SLIDE 22

Applying this to Datafun

◮ Monotonicity → increasing changes only! ∆(Set α) = Set α ◮ ∆(A) = 1? No! Zero-changes are not trivial! ◮ δ((x ∈ e1) e2)? In particular, if e1 : Set (A → B).