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 HOPE @ ICFP 2018 Datalog Datafun + + semi-nave incremental -calculus evaluation 1 Datalog 3 Datafun + + 2 semi-nave 4 incremental -calculus


slide-1
SLIDE 1

Finding fixed points faster

Michael Arntzenius

University of Birmingham

HOPE @ ICFP 2018

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

Datalog

decidable logic programming predicates = finite sets

slide-5
SLIDE 5

Transitive closure of edge: path(x, z) ← edge(x, z) path(x, z) ← edge(x, y) ∧ path(y, z)

slide-6
SLIDE 6

Transitive closure of edge, naïvely: pathi+1(x, z) ← edge(x, z) pathi+1(x, z) ← edge(x, y) ∧ pathi(y, z)

slide-7
SLIDE 7

. . .

i = 3

path3(2, 4) ← edge(2, 3) ∧ path2(3, 4)

i = 4

path4(2, 4) ← edge(2, 3) ∧ path3(3, 4)

i = 5

path5(2, 4) ← edge(2, 3) ∧ path4(3, 4) . . . Wastefully re-deducing old facts makes me :(

slide-8
SLIDE 8

Transitive closure of edge, seminaïvely:

∆path0(x, z) ← edge(x, z) ∆pathi+1(x, z) ← edge(x, y) ∧ ∆pathi(y, z)

pathi+1(x, y) ← pathi(x, y) ∨ ∆pathi(x, y) Computes the changes between naïve iterations!

slide-9
SLIDE 9
  • ii. datafun
slide-10
SLIDE 10

path(x, z) ← edge(x, z) path(x, z) ← edge(x, y) ∧ path(y, z) path = edge ∪ {(x, z) | (x, y) ∈ edge, (y, z) ∈ path}

slide-11
SLIDE 11

Datalog path(x, z) ← edge(x, z) path(x, z) ← edge(x, y) ∧ path(y, z) Datafun path = edge ∪ {(x, z) | (x, y) ∈ edge, (y, z) ∈ path}

slide-12
SLIDE 12

Datafun

◮ Simply-typed λ-calculus ◮ finite sets & monadic set comprehensions ◮ monotone† iterative fixed points

For more, see Datafun: A functional Datalog [ICFP ’16]!

†Come to my poster presentation on Monday to learn about types for

monotonicity!

slide-13
SLIDE 13

path = edge ∪ {(x, z) | (x, y) ∈ edge, (y, z) ∈ path}

slide-14
SLIDE 14

step S = edge ∪ {(x, z) | (x, y) ∈ edge, (y, z) ∈ S} path = fix step

slide-15
SLIDE 15

step S = edge ∪ {(x, z) | (x, y) ∈ edge, (y, z) ∈ S} path = fix step How do we compute (fix f), naïvely?

x0 = ∅ xi+1 = f(xi)

Iterate until xi = xi+1.

slide-16
SLIDE 16

Incremental λ-Calculus

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

f : A → B δf : A → ∆A → ∆B

slide-17
SLIDE 17

f : Set A → Set A δf : Set A → Set A → Set A

slide-18
SLIDE 18

f : Set A → Set A δf : Set A → Set A → Set A x0 = ∅ dx0 = f ∅ xi+1 = xi ∪ dxi dxi+1 = δf xi dxi

Theorem: xi = fi x

slide-19
SLIDE 19
  • iii. details and complications

Pick your poison!

  • 1. Precise vs. cheap derivatives
  • 2. Monotonicity and ordering
  • 3. Sum types are tricky
  • 4. Sets of functions are inefficient
  • 5. Derivatives suck if you don’t optimise them
slide-20
SLIDE 20

For every type A

◮ a change type ∆A ◮ a zero function 0 : A → ∆A ◮ and an update function ⊕ : A → ∆A → A

For every term x : A ⊢ M : B,

◮ a derivative x : A, dx : ∆Γ ⊢ δM : ∆A ◮ such that M ⊕ δM = M[(x ⊕ dx)/x]

slide-21
SLIDE 21
  • 1. Precise vs cheap derivatives

δ(M ∪ N) = δM ∪ δN

vs

δ(M ∪ N) = (δM \ N) ∪ (δN \ M)

slide-22
SLIDE 22
  • 2. Monotonicity and ordering

A → B vs A

+

→ B ∆(A → B) = A → ∆A → ∆B ∆(A

+

→ B) = A → ∆A

+

→ ∆B (dx dy : ∆A ⇐ ⇒ (∀a) a ⊕ da a ⊕ db : A)?

Increasing changes only? What about incrementalizing Datafun? Why do discrete functions need derivatives if their arguments can’t change?

slide-23
SLIDE 23
  • 3. Sum types are tricky

∆(A + B) = ∆A × ∆B? = ∆A ∪ ∆B? = ∆A + ∆B δ(case M of in1 x → N1; in2 y → N2) = case (M, δM) of (in1 x, in1 dx) → δN1 (in2 y, in2 dy) → δN2 (in1 x, in2 dy) → ??? (in2 x, in1 dy) → ???

slide-24
SLIDE 24
  • 4. Sets of functions are inefficient

δ ((x ∈ M) N) = ((x ∈ δM) N) ∪ ((x ∈ M ∪ δM) let dx = 0 x in δN)

slide-25
SLIDE 25
  • 4. Sets of functions are inefficient

δ ((x ∈ M) N) = ((x ∈ δM) N) ∪ ((x ∈ M ∪ δM) let dx = 0 x in δN)

What is (0 f) for f : A → B? It’s the derivative of f.

slide-26
SLIDE 26
  • 5. Derivatives suck if you don’t optimise them

X ∩ Y = {x | x ∈ X, x ∈ Y} = (x ∈ X) (y ∈ Y) if x = y then {x} else ∅ δ ((x ∈ M) N) = ((x ∈ δM) N) ∪ ((x ∈ M ∪ δM) let dx = 0 x in δN) δ(X ∩ Y) = horrible!

slide-27
SLIDE 27

fin