Propagators: An Introduction George Wilson Data61/CSIRO - - PowerPoint PPT Presentation

propagators an introduction
SMART_READER_LITE
LIVE PREVIEW

Propagators: An Introduction George Wilson Data61/CSIRO - - PowerPoint PPT Presentation

Propagators: An Introduction George Wilson Data61/CSIRO george.wilson@data61.csiro.au 14th November 2017 What? Why? R 2 R 3 V 1 Beginnings as early as the 1970s at MIT R 1 Guy L. Steele Jr. Gerald J. Sussman Richard Stallman


slide-1
SLIDE 1

Propagators: An Introduction

George Wilson

Data61/CSIRO george.wilson@data61.csiro.au

14th November 2017

slide-2
SLIDE 2

What? Why?

slide-3
SLIDE 3

Beginnings as early as the 1970’s at MIT

  • Guy L. Steele Jr.
  • Gerald J. Sussman
  • Richard Stallman

More recently:

  • Alexey Radul

V 2 Vout V 1 R1 R1 Rgain R2 R3 R2 R3

slide-4
SLIDE 4

(define (map f xs) (cond ((null? xs) ’()) (else (cons (f (car xs)) (map f (cdr xs)))))))

slide-5
SLIDE 5

And then

  • Edward Kmett

{} {1} {2} {3} {4} {1,2} {1,3} {1,4} {2,3} {2,4} {3,4} {1,2,3} {1,2,4} {1,3,4} {2,3,4} {1,2,3,4}

x ≤ y = ⇒ f(x) ≤ f(y)

slide-6
SLIDE 6

They’re related to many areas of research, including:

  • Logic programming (particularly Datalog)
  • Constraint solvers
  • Conflict-Free Replicated Datatypes
  • LVars
  • Programming language theory
  • And spreadsheets!

They have advantages:

  • are extremely expressive
  • lend themselves to parallel and distributed evaluation
  • allow different strategies of problem-solving to cooperate
slide-7
SLIDE 7

Propagators

slide-8
SLIDE 8

The propagator model is a model of computation We model computations as propagator networks

slide-9
SLIDE 9

The propagator model is a model of computation We model computations as propagator networks A propagator network comprises

  • cells
  • propagators
  • connections between cells and propagators
slide-10
SLIDE 10
slide-11
SLIDE 11

3

slide-12
SLIDE 12

toUpper

slide-13
SLIDE 13

toUpper

slide-14
SLIDE 14

'q' toUpper

slide-15
SLIDE 15

'q' toUpper 'Q'

slide-16
SLIDE 16

+

slide-17
SLIDE 17

3 +

slide-18
SLIDE 18

3 + 4

slide-19
SLIDE 19

3 + 4 7

slide-20
SLIDE 20

z ← x + y

slide-21
SLIDE 21

z = x + y

slide-22
SLIDE 22

7 = x + 4

slide-23
SLIDE 23

7 = 3 + 4

slide-24
SLIDE 24

z = x + y

slide-25
SLIDE 25

z ← x + y x ← z − y y ← z − x

slide-26
SLIDE 26
  • +
slide-27
SLIDE 27
  • +

4

slide-28
SLIDE 28
  • +

7 4

slide-29
SLIDE 29

3

  • +

7 4

slide-30
SLIDE 30

Propagators let us express bidirectional relationships!

slide-31
SLIDE 31

°F = °C × 9

5 + 32

C × 9/5 + 32 F

slide-32
SLIDE 32

°F = °C × 9

5 + 32

24.0 C × 9/5 + 32 F

slide-33
SLIDE 33

°F = °C × 9

5 + 32

24.0 C × 9/5 43.2 + 32 F

slide-34
SLIDE 34

°F = °C × 9

5 + 32

24.0 C × 9/5 43.2 + 32 75.2 F

slide-35
SLIDE 35

°F = °C × 9

5 + 32

°C = (°F − 32) ÷ 9

5

÷

  • C

× 9/5 + 32 F

slide-36
SLIDE 36

°F = °C × 9

5 + 32

°C = (°F − 32) ÷ 9

5

÷

  • C

× 9/5 + 32 75.2 F

slide-37
SLIDE 37

°F = °C × 9

5 + 32

°C = (°F − 32) ÷ 9

5

÷

  • 43.2

C × 9/5 + 32 75.2 F

slide-38
SLIDE 38

°F = °C × 9

5 + 32

°C = (°F − 32) ÷ 9

5

÷ 24.0

  • 43.2

C × 9/5 + 32 75.2 F

slide-39
SLIDE 39

°F = °C × 9

5 + 32

°C = (°F − 32) ÷ 9

5

÷

  • C

× 9/5 + 32 F

slide-40
SLIDE 40

°F = °C × 9

5 + 32

°C = (°F − 32) ÷ 9

5

÷

  • 43.2

C × 9/5 + 32 F

slide-41
SLIDE 41

°F = °C × 9

5 + 32

°C = (°F − 32) ÷ 9

5

÷ 24.0

  • 43.2

C × 9/5 + 32 75.2 F

slide-42
SLIDE 42

÷

  • C

× 9/5

  • +

32 F 3.0 +

slide-43
SLIDE 43

÷

  • C

× 9/5

  • +

32 75.2 F 3.0 +

slide-44
SLIDE 44

÷

  • 43.2

C × 9/5

  • +

32 75.2 F 3.0 +

slide-45
SLIDE 45

÷ 24.0

  • 43.2

C × 9/5

  • +

32 75.2 F 3.0 +

slide-46
SLIDE 46

÷ 24.0

  • 43.2

C × 9/5

  • +

32 75.2 F 3.0 21.0 +

slide-47
SLIDE 47

We can combine networks into larger networks!

slide-48
SLIDE 48

?

slide-49
SLIDE 49

Cells accumulate information about a value

slide-50
SLIDE 50
slide-51
SLIDE 51
slide-52
SLIDE 52
slide-53
SLIDE 53
slide-54
SLIDE 54
slide-55
SLIDE 55
slide-56
SLIDE 56
slide-57
SLIDE 57
slide-58
SLIDE 58
slide-59
SLIDE 59
slide-60
SLIDE 60
slide-61
SLIDE 61
slide-62
SLIDE 62
slide-63
SLIDE 63

Cells accumulate information in a bounded join-semilattice

slide-64
SLIDE 64

Cells accumulate information in a bounded join-semilattice A bounded join-semilattice is:

  • A partially ordered set
  • with a least element
  • such that any subset of elements has a least upper bound
slide-65
SLIDE 65

Cells accumulate information in a bounded join-semilattice A bounded join-semilattice is:

  • A partially ordered set
  • with a least element
  • such that any subset of elements has a least upper bound

“Least upper bound” is denoted as ∨ and is usually pronounced “join”

slide-66
SLIDE 66

{} {1} {2} {3} {4} {1,2} {1,3} {1,4} {2,3} {2,4} {3,4} {1,2,3} {1,2,4} {1,3,4} {2,3,4} {1,2,3,4}

slide-67
SLIDE 67

{} {1} {2} {3} {4} {1,2} {1,3} {1,4} {2,3} {2,4} {3,4} {1,2,3} {1,2,4} {1,3,4} {2,3,4} {1,2,3,4}

More information Less information

slide-68
SLIDE 68

More information Less information

slide-69
SLIDE 69

More information Less information

slide-70
SLIDE 70

More information Less information

slide-71
SLIDE 71

More information Less information

slide-72
SLIDE 72

More information Less information

slide-73
SLIDE 73

More information Less information

slide-74
SLIDE 74

More information Less information

slide-75
SLIDE 75

More information Less information

slide-76
SLIDE 76

More information Less information

slide-77
SLIDE 77

More information Less information

slide-78
SLIDE 78

∨ has useful algebraic properties. It is:

  • A monoid
  • that’s commutative
  • and idempotent
slide-79
SLIDE 79

Left identity ǫ ∨ x = x Right identity x ∨ ǫ = x Associativity (x ∨ y) ∨ z = x ∨ (y ∨ z) Commutative x ∨ y = y ∨ x Idempotent x ∨ x = x

slide-80
SLIDE 80

class BoundedJoinSemilattice a where bottom :: a (\/) :: a -> a -> a

slide-81
SLIDE 81

class BoundedJoinSemilattice a where bottom :: a (\/) :: a -> a -> a data SudokuVal = One | Two | Three | Four deriving (Eq, Ord, Show)

slide-82
SLIDE 82

class BoundedJoinSemilattice a where bottom :: a (\/) :: a -> a -> a data SudokuVal = One | Two | Three | Four deriving (Eq, Ord, Show) newtype SudokuSet = S (Set SudokuVal)

slide-83
SLIDE 83

class BoundedJoinSemilattice a where bottom :: a (\/) :: a -> a -> a data SudokuVal = One | Two | Three | Four deriving (Eq, Ord, Show) newtype SudokuSet = S (Set SudokuVal) instance BoundedJoinSemilattice SudokuSet where bottom = S (Set.fromList [One, Two, Three, Four]) S a \/ S b = S (Set.intersection a b)

slide-84
SLIDE 84

We don’t write values directly to cells Instead we join information in

slide-85
SLIDE 85

We don’t write values directly to cells Instead we join information in This makes our propagators monotone, meaning that as the input cells gain information, the

  • utput cells gain information (or don’t change)
slide-86
SLIDE 86

We don’t write values directly to cells Instead we join information in This makes our propagators monotone, meaning that as the input cells gain information, the

  • utput cells gain information (or don’t change)

A function f : A → B where A and B are partially ordered sets is monotone if and only if, for all x, y ∈ A. x ≤ y = ⇒ f(x) ≤ f(y)

slide-87
SLIDE 87

All our lattices so far have been fininte

{} {1} {2} {3} {4} {1,2} {1,3} {1,4} {2,3} {2,4} {3,4} {1,2,3} {1,2,4} {1,3,4} {2,3,4} {1,2,3,4}

slide-88
SLIDE 88

Thanks to these properties:

  • the bounded join-semilattice laws
  • the finiteness of our lattice
  • the monotonicity of our propagators
  • ur propagator networks will yield with a deterministic answer, in finite time, regardless of

parallelism and distribution

slide-89
SLIDE 89

Thanks to these properties:

  • the bounded join-semilattice laws
  • the finiteness of our lattice
  • the monotonicity of our propagators
  • ur propagator networks will yield with a deterministic answer, in finite time, regardless of

parallelism and distribution Bounded join-semilattices are already popular in the distributed systems world See: Conflict Free Replicated Datatypes

slide-90
SLIDE 90

Thanks to these properties:

  • the bounded join-semilattice laws
  • the finiteness of our lattice
  • the monotonicity of our propagators
  • ur propagator networks will yield with a deterministic answer, in finite time, regardless of

parallelism and distribution Bounded join-semilattices are already popular in the distributed systems world See: Conflict Free Replicated Datatypes We can relax these constraints in a few different directions

slide-91
SLIDE 91

Our lattices only need the ascending chain condition Contradiction ...

  • 2
  • 1

1 2 ... Unknown

slide-92
SLIDE 92

?

slide-93
SLIDE 93

3

  • +

4

slide-94
SLIDE 94

data Perhaps a = Unknown | Known a | Contradiction

slide-95
SLIDE 95

data Perhaps a = Unknown | Known a | Contradiction instance Eq a => BoundedJoinSemiLattice (Perhaps a) where bottom = Unknown (\/) Unknown x = x (\/) x Unknown = x (\/) Contradiction _ = Contradiction (\/) _ Contradiction = Contradiction (\/) (Known a) (Known b) = if a == b then Known a else Contradiction

slide-96
SLIDE 96

Contradiction ...

  • 2
  • 1

1 2 ... Unknown

slide-97
SLIDE 97

Contradiction ...

  • 2
  • 1

1 2 ... Unknown More information Less information

slide-98
SLIDE 98

Known 3

  • +

Unknown Known 4

slide-99
SLIDE 99

Known 3

  • +

Known 7 Known 4

slide-100
SLIDE 100

Known 3 + Known 4 Unknown + Known 6 Known 6

slide-101
SLIDE 101

Known 3 + Known 4 Known 12 \/ Unknown + Known 6 Known 6

slide-102
SLIDE 102

Known 3 + Known 4 Known 7 \/ Known 12 \/ Unknown + Known 6 Known 6

slide-103
SLIDE 103

Known 3 + Known 4 Known 7 \/ Known 12 + Known 6 Known 6

slide-104
SLIDE 104

Known 3 + Known 4 Contradiction + Known 6 Known 6

slide-105
SLIDE 105

There are loads of other bounded join-semilattices too!

slide-106
SLIDE 106

[1, 5]

slide-107
SLIDE 107

[1, 5] ∩ [2, 7] = [2, 5]

slide-108
SLIDE 108

[1, 5] ∩ [2, 7] = [2, 5] [2, 5] + [9, 10] = [11, 15]

slide-109
SLIDE 109

[2,5] + [9,10] [-∞,∞]

slide-110
SLIDE 110

[2,5] + [9,10] [11,15]

slide-111
SLIDE 111

We can use this to combine multiple imprecise measurements

slide-112
SLIDE 112

What other bounded join-semilattices are there?

slide-113
SLIDE 113

{} {1} {2} {3} {4} {1,2} {1,3} {1,4} {2,3} {2,4} {3,4} {1,2,3} {1,2,4} {1,3,4} {2,3,4} {1,2,3,4}

slide-114
SLIDE 114

{} {1} {2} {3} {4} {1,2} {1,3} {1,4} {2,3} {2,4} {3,4} {1,2,3} {1,2,4} {1,3,4} {2,3,4} {1,2,3,4}

slide-115
SLIDE 115
  • Set intersection or union
  • Interval intersection
  • Perhaps

And so many more!

slide-116
SLIDE 116
  • Set intersection or union
  • Interval intersection
  • Perhaps

And so many more!

?

slide-117
SLIDE 117

What happens when we hit contradiction?

slide-118
SLIDE 118

What happens when we hit contradiction?

:(

slide-119
SLIDE 119

If we track the provenance of information, we can help identify the source of contradiction

slide-120
SLIDE 120

If we track the provenance of information, we can help identify the source of contradiction Then we can keep track of which subsets of the information are consistent and which are inconsistent

slide-121
SLIDE 121

[2, 5] ∩ [3, 7] ∩ [6, 9] = []

slide-122
SLIDE 122

[2, 5] ∩ [3, 7] ∩ [6, 9] = [] [2, 5] ∩ [3, 7] = [3, 5]

slide-123
SLIDE 123

[2, 5] ∩ [3, 7] ∩ [6, 9] = [] [2, 5] ∩ [3, 7] = [3, 5] [3, 7] ∩ [6, 9] = [6, 7]

slide-124
SLIDE 124

[2, 5] ∩ [3, 7] ∩ [6, 9] = [] [2, 5] ∩ [3, 7] = [3, 5] [3, 7] ∩ [6, 9] = [6, 7] [2, 5] ∩ [6, 9] = []

slide-125
SLIDE 125

[2, 5] ∩ [3, 7] ∩ [6, 9] = [] [2, 5] ∩ [3, 7] = [3, 5] [3, 7] ∩ [6, 9] = [6, 7] [2, 5] ∩ [6, 9] = []

Consistent subsets: {} {[2, 5]} {[3, 7]} {[6, 9]} {[2, 5], [3, 7]} {[3, 7], [6, 9]}

slide-126
SLIDE 126

[2, 5] ∩ [3, 7] ∩ [6, 9] = [] [2, 5] ∩ [3, 7] = [3, 5] [3, 7] ∩ [6, 9] = [6, 7] [2, 5] ∩ [6, 9] = []

Consistent subsets: {} {[2, 5]} {[3, 7]} {[6, 9]} {[2, 5], [3, 7]} {[3, 7], [6, 9]} Maximal consistent subsets: {[2, 5], [3, 7]} {[3, 7], [6, 9]}

slide-127
SLIDE 127

[2, 5] ∩ [3, 7] ∩ [6, 9] = [] [2, 5] ∩ [3, 7] = [3, 5] [3, 7] ∩ [6, 9] = [6, 7] [2, 5] ∩ [6, 9] = []

Consistent subsets: {} {[2, 5]} {[3, 7]} {[6, 9]} {[2, 5], [3, 7]} {[3, 7], [6, 9]} Maximal consistent subsets: {[2, 5], [3, 7]} {[3, 7], [6, 9]} Inconsistent subsets: {[2, 5], [6, 9]} {[2, 5], [3, 7], [6, 9]}

slide-128
SLIDE 128

[2, 5] ∩ [3, 7] ∩ [6, 9] = [] [2, 5] ∩ [3, 7] = [3, 5] [3, 7] ∩ [6, 9] = [6, 7] [2, 5] ∩ [6, 9] = []

Consistent subsets: {} {[2, 5]} {[3, 7]} {[6, 9]} {[2, 5], [3, 7]} {[3, 7], [6, 9]} Maximal consistent subsets: {[2, 5], [3, 7]} {[3, 7], [6, 9]} Inconsistent subsets: {[2, 5], [6, 9]} {[2, 5], [3, 7], [6, 9]} Minimal inconsistent subsets: {[2, 5], [6, 9]}

slide-129
SLIDE 129

This concept is something called a Truth Management System

slide-130
SLIDE 130

Now that we can handle contradiction, we can make guesses!

slide-131
SLIDE 131

Now that we can handle contradiction, we can make guesses! This lets us encode search problems easily

slide-132
SLIDE 132

?

slide-133
SLIDE 133

We can relax some of our conditions in certain circumstances

slide-134
SLIDE 134

... ⊥

  • 2
  • 1

1 2 ...

slide-135
SLIDE 135

We can turn any expression tree into a propagator network There will only ever be one writer to a cell

(5 + 2) × (x + y)

5 + 2 × x + y

slide-136
SLIDE 136

Wrapping up

slide-137
SLIDE 137

Alexey Radul’s work on propagators:

  • Art of the Propagator

http://web.mit.edu/~axch/www/art.pdf

  • Propagation Networks: A Flexible and Expressive Substrate for Computation

http://web.mit.edu/~axch/www/phd-thesis.pdf

slide-138
SLIDE 138

Lindsey Kuper’s work on LVars is closely related, and works today:

  • Lattice-Based Data Structures for Deterministic Parallel and Distributed Programming

https://www.cs.indiana.edu/~lkuper/papers/ lindsey-kuper-dissertation.pdf

  • lvish library

https://hackage.haskell.org/package/lvish

slide-139
SLIDE 139

Edward Kmett has worked on:

  • Making propagators go fast
  • Scheduling strategies and garbage collection
  • Relaxing requirements (Eg. not requiring a full join-semilattice, admitting non-monotone

functions) Ed’s stuff:

  • http://github.com/ekmett/propagators
  • http://github.com/ekmett/concurrent
  • Lambda Jam talk (Normal mode):

https://www.youtube.com/watch?v=acZkF6Q2XKs

  • Boston Haskell talk (Hard mode):

https://www.youtube.com/watch?v=DyPzPeOPgUE

slide-140
SLIDE 140

In conclusion, propagator networks:

  • Admit any Haskell function you can write today . . .
  • . . . and more functions!
  • compute bidirectionally
  • give us constraint solving and search
  • mix all this stuff together
  • parallelise and distribute
slide-141
SLIDE 141

Thanks for listening!