Typing Rank Polymorphism Justin Slepak In collaboration with Olin - - PowerPoint PPT Presentation

typing rank polymorphism
SMART_READER_LITE
LIVE PREVIEW

Typing Rank Polymorphism Justin Slepak In collaboration with Olin - - PowerPoint PPT Presentation

Typing Rank Polymorphism Justin Slepak In collaboration with Olin Shivers and Panagiotis Manolios 100 175 0.6 ( [(lo 0) (hi 0) ( 0)] (+ (* hi ) (* lo (- 1 )))) 100 175 0.6 (( [(lo 0) (hi 0) ( 0)] (+ (* hi ) (* lo (- 1


slide-1
SLIDE 1

Typing Rank Polymorphism

Justin Slepak In collaboration with Olin Shivers and Panagiotis Manolios

slide-2
SLIDE 2

100 175 0.6 (λ [(lo 0) (hi 0) (α 0)] (+ (* hi α) (* lo (- 1 α))))

slide-3
SLIDE 3

100 175 0.6 ((λ [(lo 0) (hi 0) (α 0)] (+ (* hi α) (* lo (- 1 α)))) 100 175 0.6)

slide-4
SLIDE 4

RGB RGB

(λ [(lo 0) (hi 0) (α 0)] (+ (* hi α) (* lo (- 1 α))))

slide-5
SLIDE 5

RGB RGB

((λ [(lo 0) (hi 0) (α 0)] (+ (* hi α) (* lo (- 1 α)))) rgb1 ; 3 channels rgb2 ; 3 channels 0.6) ; scalar

slide-6
SLIDE 6

Credit: Wikimedia user Sadalsuud

(λ [(lo 0) (hi 0) (α 0)] (+ (* hi α) (* lo (- 1 α))))

slide-7
SLIDE 7

Credit: Wikimedia user Sadalsuud

((λ [(lo 0) (hi 0) (α 0)] (+ (* hi α) (* lo (- 1 α)))) sky ; row × col × chan labels ; row × col × chan img-mask) ; row × col × chan

slide-8
SLIDE 8

(λ [(lo 0) (hi 0) (α 0)] (+ (* hi α) (* lo (- 1 α))))

slide-9
SLIDE 9

((λ [(lo 0) (hi 0) (α 0)] (+ (* hi α) (* lo (- 1 α)))) film ; time × row × col × chan audience ; time × row × col × chan vid-mask) ; time × row × col × chan

slide-10
SLIDE 10

Credit: Wikimedia user Thetawave

(λ [(lo 0) (hi 0) (α 0)] (+ (* hi α) (* lo (- 1 α))))

slide-11
SLIDE 11

Credit: Wikimedia user Thetawave

((λ [(lo 0) (hi 0) (α 0)] (+ (* hi α) (* lo (- 1 α)))) scene1 ; time × row × col × chan scene2 ; time × row × col × chan [0.0 ... 1.0]) ; time

slide-12
SLIDE 12
slide-13
SLIDE 13

(lerp dragonfly ; row × col × chan tint-color ; chan 0.6) ; scalar

slide-14
SLIDE 14

(~[1 1 0]lerp dragonfly ; row × col × chan tint-color ; chan 0.6) ; scalar

slide-15
SLIDE 15

(~[1 1 0]lerp dragonfly ; row × col × chan tint-color ; chan 0.6) ; scalar

slide-16
SLIDE 16

(~[1 1 0]lerp dragonfly ; row × col × chan tint-color ; chan 0.6) ; scalar

slide-17
SLIDE 17

(~[1 1 0]lerp dragonfly ; row × col × chan tint-color ; chan 0.6) ; scalar

slide-18
SLIDE 18

(~[1 1 0]lerp dragonfly ; row × col × chan tint-color ; chan 0.6) ; scalar

slide-19
SLIDE 19

(~[1 1 0]lerp dragonfly ; row × col × chan tint-color ; chan 0.6) ; scalar

slide-20
SLIDE 20

(~[1 1 0]lerp dragonfly ; row × col × chan tint-color ; chan 0.6) ; scalar

slide-21
SLIDE 21

(~[1 1 0]lerp dragonfly ; row × col × chan tint-color ; chan 0.6) ; scalar

slide-22
SLIDE 22

Rank manipulation

slide-23
SLIDE 23

(~[0 1]* [1 2 3] [10 20])

slide-24
SLIDE 24

(~[0 1]* [1 2 3] [10 20]) Cells:

slide-25
SLIDE 25

(~[0 1]* [1 2 3] [10 20]) Cells: ~[0 1]*

slide-26
SLIDE 26

(~[0 1]* [1 2 3] [10 20]) Cells: ~[0 1]* 1 2 3

slide-27
SLIDE 27

(~[0 1]* [1 2 3] [10 20]) Cells: ~[0 1]* 1 [10 20] 2 3

slide-28
SLIDE 28

(~[0 1]* [1 2 3] [10 20]) Cells: ~[0 1]* 1 [10 20] 2 3 Frame: [] [3] []

slide-29
SLIDE 29

(~[0 1]* [1 2 3] [10 20]) Cells: ~[0 1]* 1 [10 20] 2 3 Frame: [] [3] [] [(* 1 [10 20]) (* 2 [10 20]) (* 3 [10 20])]

slide-30
SLIDE 30

(~[0 1]* [1 2 3] [10 20]) Cells: ~[0 1]* 1 [10 20] 2 3 Frame: [] [3] [] [(* 1 [10 20]) (* 2 [10 20]) (* 3 [10 20])] [[10 20] [20 40] [30 60]]

slide-31
SLIDE 31

; M×N array for M points in N-space > (define points ...)

slide-32
SLIDE 32

; M×N array for M points in N-space > (define points ...) > (define (dist^2 (a 1) (b 1)) (reduce + 0 (sqr (- a b))))

slide-33
SLIDE 33

; M×N array for M points in N-space > (define points ...) > (define (dist^2 (a 1) (b 1)) (reduce + 0 (sqr (- a b)))) ; points[x,newDim,y] and points[newDim,x,y]?

slide-34
SLIDE 34

; M×N array for M points in N-space > (define points ...) > (define (dist^2 (a 1) (b 1)) (reduce + 0 (sqr (- a b)))) ; points[x,newDim,y] and points[newDim,x,y]? > (~[1 2]dist^2 points points) [[some ...] [symmetric ...] [matrix ...] ...]

slide-35
SLIDE 35

Non-rectangular data

slide-36
SLIDE 36

> (define ragged [(box [1]) (box [4 2 5]) (box [8 7 2 4 3]) (box [9 0])])

slide-37
SLIDE 37

> (define ragged [(box [1]) (box [4 2 5]) (box [8 7 2 4 3]) (box [9 0])]) > (shape-of ragged)

slide-38
SLIDE 38

> (define ragged [(box [1]) (box [4 2 5]) (box [8 7 2 4 3]) (box [9 0])]) > (shape-of ragged) [4]

slide-39
SLIDE 39

> (define ragged [(box [1]) (box [4 2 5]) (box [8 7 2 4 3]) (box [9 0])]) > (shape-of ragged) [4] > ((λ (b 0) (unbox contents b (shape-of contents))) ragged)

slide-40
SLIDE 40

> (define ragged [(box [1]) (box [4 2 5]) (box [8 7 2 4 3]) (box [9 0])]) > (shape-of ragged) [4] > ((λ (b 0) (unbox contents b (shape-of contents))) ragged) [[1] [3] [5] [2]]

slide-41
SLIDE 41

> (take 3 [1 2 3 4 5])

slide-42
SLIDE 42

> (take 3 [1 2 3 4 5]) [1 2 3]

slide-43
SLIDE 43

> (take 3 [1 2 3 4 5]) [1 2 3] > (take 2 [1 2 3 4 5])

slide-44
SLIDE 44

> (take 3 [1 2 3 4 5]) [1 2 3] > (take 2 [1 2 3 4 5]) [1 2]

slide-45
SLIDE 45

> (take 3 [1 2 3 4 5]) [1 2 3] > (take 2 [1 2 3 4 5]) [1 2] > (take [2 3] [1 2 3 4 5])

slide-46
SLIDE 46

> (take 3 [1 2 3 4 5]) [1 2 3] > (take 2 [1 2 3 4 5]) [1 2] > (take [2 3] [1 2 3 4 5]) Error: Result cells have mismatched shapes

slide-47
SLIDE 47

> (take 3 [1 2 3 4 5]) [1 2 3] > (take 2 [1 2 3 4 5]) [1 2] > (take [2 3] [1 2 3 4 5]) Error: Result cells have mismatched shapes Ragged results can arise from lifting non-ragged ops

slide-48
SLIDE 48

> (take* 3 [1 2 3 4 5])

slide-49
SLIDE 49

> (take* 3 [1 2 3 4 5]) (box [1 2 3])

slide-50
SLIDE 50

> (take* 3 [1 2 3 4 5]) (box [1 2 3]) > (take* [2 4] [1 2 3 4 5])

slide-51
SLIDE 51

> (take* 3 [1 2 3 4 5]) (box [1 2 3]) > (take* [2 4] [1 2 3 4 5]) [(box [1 2]) (box [1 2 3 4])]

slide-52
SLIDE 52

> (take* 3 [1 2 3 4 5]) (box [1 2 3]) > (take* [2 4] [1 2 3 4 5]) [(box [1 2]) (box [1 2 3 4])] > (take* (add1 (iota [5])) [1 2 3 4 5])

slide-53
SLIDE 53

> (take* 3 [1 2 3 4 5]) (box [1 2 3]) > (take* [2 4] [1 2 3 4 5]) [(box [1 2]) (box [1 2 3 4])] > (take* (add1 (iota [5])) [1 2 3 4 5]) [(box [1]) (box [1 2]) (box [1 2 3]) (box [1 2 3 4]) (box [1 2 3 4 5])]

slide-54
SLIDE 54

> (define (prefixes (v all)) ; Expect arg with at least one dimension (take* (add1 (iota [(length v)])) v))

slide-55
SLIDE 55

> (define (prefixes (v all)) ; Expect arg with at least one dimension (take* (add1 (iota [(length v)])) v)) > (define (multi-dist^2 (src 1) (dst-box 0)) (unbox dsts dst-box (box (dist^2 src dsts))))

slide-56
SLIDE 56

> (define (prefixes (v all)) ; Expect arg with at least one dimension (take* (add1 (iota [(length v)])) v)) > (define (multi-dist^2 (src 1) (dst-box 0)) (unbox dsts dst-box (box (dist^2 src dsts)))) > (multi-dist^2 points (prefixes points))

slide-57
SLIDE 57

> (define (prefixes (v all)) ; Expect arg with at least one dimension (take* (add1 (iota [(length v)])) v)) > (define (multi-dist^2 (src 1) (dst-box 0)) (unbox dsts dst-box (box (dist^2 src dsts)))) > (multi-dist^2 points (prefixes points)) [(box [p1->p1]) (box [p2->p1 p2->p2]) (box [p3->p1 p3->p2 p3->p3]) ...]

slide-58
SLIDE 58

Heterogeneous records

slide-59
SLIDE 59

> (define (champion (y 0) (c 0) (n 0)) {(year y) (city c) (name n)})

slide-60
SLIDE 60

> (define (champion (y 0) (c 0) (n 0)) {(year y) (city c) (name n)}) > (champion 2018 "Washington" "Capitals")

slide-61
SLIDE 61

> (define (champion (y 0) (c 0) (n 0)) {(year y) (city c) (name n)}) > (champion 2018 "Washington" "Capitals") {(year 2018) (city "Washington") (name "Capitals")}

slide-62
SLIDE 62

> (define (champion (y 0) (c 0) (n 0)) {(year y) (city c) (name n)}) > (champion 2018 "Washington" "Capitals") {(year 2018) (city "Washington") (name "Capitals")} > (define last-four (champion [2015 2016 2017 2018] ["Chicago" "Pittsburgh" "Pittsburgh" "Washington"] ["Blackhawks" "Penguins" "Penguins" "Capitals"]))

slide-63
SLIDE 63

> last-four

slide-64
SLIDE 64

> last-four [{(year 2015) (city "Chicago") (name "Blackhawks")} {(year 2016) (city "Pittsburgh") (name "Penguins")} {(year 2017) (city "Pittsburgh") (name "Penguins")} {(year 2018) (city "Washington") (name "Capitals")}]

slide-65
SLIDE 65

> last-four [{(year 2015) (city "Chicago") (name "Blackhawks")} {(year 2016) (city "Pittsburgh") (name "Penguins")} {(year 2017) (city "Pittsburgh") (name "Penguins")} {(year 2018) (city "Washington") (name "Capitals")}] > (shape-of last-four)

slide-66
SLIDE 66

> last-four [{(year 2015) (city "Chicago") (name "Blackhawks")} {(year 2016) (city "Pittsburgh") (name "Penguins")} {(year 2017) (city "Pittsburgh") (name "Penguins")} {(year 2018) (city "Washington") (name "Capitals")}] > (shape-of last-four) [4]

slide-67
SLIDE 67

> last-four [{(year 2015) (city "Chicago") (name "Blackhawks")} {(year 2016) (city "Pittsburgh") (name "Penguins")} {(year 2017) (city "Pittsburgh") (name "Penguins")} {(year 2018) (city "Washington") (name "Capitals")}] > (shape-of last-four) [4] > (head last-four)

slide-68
SLIDE 68

> last-four [{(year 2015) (city "Chicago") (name "Blackhawks")} {(year 2016) (city "Pittsburgh") (name "Penguins")} {(year 2017) (city "Pittsburgh") (name "Penguins")} {(year 2018) (city "Washington") (name "Capitals")}] > (shape-of last-four) [4] > (head last-four) {(year 2015) (city "Chicago") (name "Blackhawks")}

slide-69
SLIDE 69

> last-four [{(year 2015) (city "Chicago") (name "Blackhawks")} {(year 2016) (city "Pittsburgh") (name "Penguins")} {(year 2017) (city "Pittsburgh") (name "Penguins")} {(year 2018) (city "Washington") (name "Capitals")}] > (shape-of last-four) [4] > (head last-four) {(year 2015) (city "Chicago") (name "Blackhawks")} > (get city last-four)

slide-70
SLIDE 70

> last-four [{(year 2015) (city "Chicago") (name "Blackhawks")} {(year 2016) (city "Pittsburgh") (name "Penguins")} {(year 2017) (city "Pittsburgh") (name "Penguins")} {(year 2018) (city "Washington") (name "Capitals")}] > (shape-of last-four) [4] > (head last-four) {(year 2015) (city "Chicago") (name "Blackhawks")} > (get city last-four) ["Chicago" "Pittsburgh" "Pittsburgh" "Washington"]

slide-71
SLIDE 71

> last-four [{(year 2015) (city "Chicago") (name "Blackhawks")} {(year 2016) (city "Pittsburgh") (name "Penguins")} {(year 2017) (city "Pittsburgh") (name "Penguins")} {(year 2018) (city "Washington") (name "Capitals")}] > (shape-of last-four) [4] > (head last-four) {(year 2015) (city "Chicago") (name "Blackhawks")} > (get city last-four) ["Chicago" "Pittsburgh" "Pittsburgh" "Washington"] > (string=? "Pittsburgh" (get city last-four))

slide-72
SLIDE 72

> last-four [{(year 2015) (city "Chicago") (name "Blackhawks")} {(year 2016) (city "Pittsburgh") (name "Penguins")} {(year 2017) (city "Pittsburgh") (name "Penguins")} {(year 2018) (city "Washington") (name "Capitals")}] > (shape-of last-four) [4] > (head last-four) {(year 2015) (city "Chicago") (name "Blackhawks")} > (get city last-four) ["Chicago" "Pittsburgh" "Pittsburgh" "Washington"] > (string=? "Pittsburgh" (get city last-four)) [#f #t #t #f]

slide-73
SLIDE 73

Formalism

slide-74
SLIDE 74
slide-75
SLIDE 75
slide-76
SLIDE 76

Machine-friendly, fully-annotated syntax

slide-77
SLIDE 77

Machine-friendly, fully-annotated syntax Human-friendly shorthand (+ [1 2 3] [[10 20] [30 40] [50 60]])

slide-78
SLIDE 78
slide-79
SLIDE 79
slide-80
SLIDE 80
slide-81
SLIDE 81
slide-82
SLIDE 82

(+ [1 2 3] [[10 20] [30 40] [50 60]])

slide-83
SLIDE 83

(+ [1 2 3] [[10 20] [30 40] [50 60]])

: (Arr (-> ((Arr (Shp) Int) (Arr (Shp) Int)) (Arr (Shp) Int)) (Shp))

slide-84
SLIDE 84

(+ [1 2 3] [[10 20] [30 40] [50 60]])

: (Arr (-> ((Arr (Shp) Int) (Arr (Shp) Int)) (Arr (Shp) Int)) (Shp)) : (Arr (Shp 3) Int) : (Arr (Shp 3 2) Int)

slide-85
SLIDE 85

(+ [1 2 3] [[10 20] [30 40] [50 60]])

: (Arr (-> ((Arr (Shp) Int) (Arr (Shp) Int)) (Arr (Shp) Int)) (Shp)) : (Arr (Shp 3) Int) : (Arr (Shp 3 2) Int)

(Shp 3 2)

slide-86
SLIDE 86

(+ [1 2 3] [[10 20] [30 40] [50 60]]) : (Arr (Shp 3 2) Int)

: (Arr (-> ((Arr (Shp) Int) (Arr (Shp) Int)) (Arr (Shp) Int)) (Shp)) : (Arr (Shp 3) Int) : (Arr (Shp 3 2) Int)

(Shp 3 2)

slide-87
SLIDE 87
slide-88
SLIDE 88

Ensure ragged result data typed appropriately

slide-89
SLIDE 89
slide-90
SLIDE 90
slide-91
SLIDE 91

Canonicalize: fat append of bags-of-summands

slide-92
SLIDE 92

Cell-type polymorphism

slide-93
SLIDE 93

vec-norm : (-> ((Arr [3] Float)) Float)

slide-94
SLIDE 94

vec-norm : (-> ((Arr [2] Float)) Float)

slide-95
SLIDE 95

vec-norm : (-> ((Arr [L] Float)) Float)

slide-96
SLIDE 96

vec-norm : (Pi ((L Dim)) (-> ((Arr [L] Float)) Float))

slide-97
SLIDE 97

vec-norm : (Pi ((L Dim)) (-> ((Arr [L] Float)) Float)) n.b., shorthand for (Arr [] (Pi ((L Dim)) (Arr [] (-> ((Arr [L] Float)) (Arr [] Float)))))

slide-98
SLIDE 98

m*

slide-99
SLIDE 99

m* (Pi ((L Dim) (M Dim) (N Dim)) (-> ((Arr [L M] Float) (Arr [M N] Float)) (Arr [L N] Float)))

slide-100
SLIDE 100

m* (Pi ((L Dim) (M Dim) (N Dim)) (-> ((Arr [L M] Float) (Arr [M N] Float)) (Arr [L N] Float))) head

slide-101
SLIDE 101

m* (Pi ((L Dim) (M Dim) (N Dim)) (-> ((Arr [L M] Float) (Arr [M N] Float)) (Arr [L N] Float))) head (Pi ((L Dim)) (∀ ((T Atom)) (-> ((Arr [(+ L 1)] T)) (Arr [] T))))

slide-102
SLIDE 102

m* (Pi ((L Dim) (M Dim) (N Dim)) (-> ((Arr [L M] Float) (Arr [M N] Float)) (Arr [L N] Float))) head (Pi ((L Dim)) (∀ ((T Atom)) (-> ((Arr [(+ L 1)] T)) (Arr [] T)))) append

slide-103
SLIDE 103

m* (Pi ((L Dim) (M Dim) (N Dim)) (-> ((Arr [L M] Float) (Arr [M N] Float)) (Arr [L N] Float))) head (Pi ((L Dim)) (∀ ((T Atom)) (-> ((Arr [(+ L 1)] T)) (Arr [] T)))) append (Pi ((L1 Dim) (L2 Dim) (C Shape)) (∀ ((T Atom)) (-> ((Array (++ [L1] C) T) (Array (++ [L2] C) T)) (Array (++ [(+ L1 L2)] C) T))))

slide-104
SLIDE 104

Typing ragged data

slide-105
SLIDE 105

(box [1 2 3 4])

slide-106
SLIDE 106

(box [1 2 3 4]) (box 4 [1 2 3 4] (Sigma ((N Dim)) (Arr [N] Int)))

slide-107
SLIDE 107

(box [1 2 3 4]) (box 4 [1 2 3 4] (Sigma ((N Dim)) (Arr [N] Int))) (box 3 [1 2 3 4] (Sigma ((N Dim)) (Arr [(+ 1 N)] Int)))

slide-108
SLIDE 108

(box [1 2 3 4]) (box 4 [1 2 3 4] (Sigma ((N Dim)) (Arr [N] Int))) (box 3 [1 2 3 4] (Sigma ((N Dim)) (Arr [(+ 1 N)] Int))) (box [4] [1 2 3 4] (Sigma ((S Shape)) (Arr S Int)))

slide-109
SLIDE 109

(Sigma ((N Dim)) (Arr [N] Int))

slide-110
SLIDE 110

(Sigma ((N Dim)) (Arr [N] Int)) Vector, unknown length

slide-111
SLIDE 111

(Sigma ((N Dim)) (Arr [N] Int)) Vector, unknown length (Sigma ((N Dim)) (Arr [(+ 1 N)] Int))

slide-112
SLIDE 112

(Sigma ((N Dim)) (Arr [N] Int)) Vector, unknown length (Sigma ((N Dim)) (Arr [(+ 1 N)] Int)) Vector, nonempty

slide-113
SLIDE 113

(Sigma ((N Dim)) (Arr [N] Int)) Vector, unknown length (Sigma ((N Dim)) (Arr [(+ 1 N)] Int)) Vector, nonempty (Sigma ((M Dim) (N Dim)) (Arr [M N] Int))

slide-114
SLIDE 114

(Sigma ((N Dim)) (Arr [N] Int)) Vector, unknown length (Sigma ((N Dim)) (Arr [(+ 1 N)] Int)) Vector, nonempty (Sigma ((M Dim) (N Dim)) (Arr [M N] Int)) Matrix, unknown dimensions

slide-115
SLIDE 115

(Sigma ((N Dim)) (Arr [N] Int)) Vector, unknown length (Sigma ((N Dim)) (Arr [(+ 1 N)] Int)) Vector, nonempty (Sigma ((M Dim) (N Dim)) (Arr [M N] Int)) Matrix, unknown dimensions (Sigma ((S Shape)) (Arr S Int))

slide-116
SLIDE 116

(Sigma ((N Dim)) (Arr [N] Int)) Vector, unknown length (Sigma ((N Dim)) (Arr [(+ 1 N)] Int)) Vector, nonempty (Sigma ((M Dim) (N Dim)) (Arr [M N] Int)) Matrix, unknown dimensions (Sigma ((S Shape)) (Arr S Int)) Completely unknown shape

slide-117
SLIDE 117

(Sigma ((N Dim)) (Arr [N] Int)) Vector, unknown length (Sigma ((N Dim)) (Arr [(+ 1 N)] Int)) Vector, nonempty (Sigma ((M Dim) (N Dim)) (Arr [M N] Int)) Matrix, unknown dimensions (Sigma ((S Shape)) (Arr S Int)) Completely unknown shape (Sigma ((N Dim) (S Shape)) (Arr (++ [N] S) Int))

slide-118
SLIDE 118

(Sigma ((N Dim)) (Arr [N] Int)) Vector, unknown length (Sigma ((N Dim)) (Arr [(+ 1 N)] Int)) Vector, nonempty (Sigma ((M Dim) (N Dim)) (Arr [M N] Int)) Matrix, unknown dimensions (Sigma ((S Shape)) (Arr S Int)) Completely unknown shape (Sigma ((N Dim) (S Shape)) (Arr (++ [N] S) Int)) Rank at least one

slide-119
SLIDE 119

(Sigma ((N Dim)) (Arr [N] Int)) Vector, unknown length (Sigma ((N Dim)) (Arr [(+ 1 N)] Int)) Vector, nonempty (Sigma ((M Dim) (N Dim)) (Arr [M N] Int)) Matrix, unknown dimensions (Sigma ((S Shape)) (Arr S Int)) Completely unknown shape (Sigma ((N Dim) (S Shape)) (Arr (++ [N] S) Int)) Rank at least one But still all regular

slide-120
SLIDE 120

(Arr [4] (Sigma ((N Dim)) (Arr [N] Int)))

slide-121
SLIDE 121

(Arr [4] (Sigma ((N Dim)) (Arr [N] Int))) Four vectors, may vary in length

slide-122
SLIDE 122

(Arr [4] (Sigma ((N Dim)) (Arr [N] Int))) Four vectors, may vary in length (Sigma ((N Dim)) (Arr [4 N] Int))

slide-123
SLIDE 123

(Arr [4] (Sigma ((N Dim)) (Arr [N] Int))) Four vectors, may vary in length (Sigma ((N Dim)) (Arr [4 N] Int)) Four vectors, same unknown length

slide-124
SLIDE 124

(Arr [4] (Sigma ((N Dim)) (Arr [N] Int))) Four vectors, may vary in length (Sigma ((N Dim)) (Arr [4 N] Int)) Four vectors, same unknown length (Arr [4] (Sigma ((S Shape)) (Arr S Int)))

slide-125
SLIDE 125

(Arr [4] (Sigma ((N Dim)) (Arr [N] Int))) Four vectors, may vary in length (Sigma ((N Dim)) (Arr [4 N] Int)) Four vectors, same unknown length (Arr [4] (Sigma ((S Shape)) (Arr S Int))) Four arrays which may even differ in rank

slide-126
SLIDE 126

(Arr [4] (Sigma ((N Dim)) (Arr [N] Int))) Four vectors, may vary in length (Sigma ((N Dim)) (Arr [4 N] Int)) Four vectors, same unknown length (Arr [4] (Sigma ((S Shape)) (Arr S Int))) Four arrays which may even differ in rank (Sigma ((S Shape)) (Arr (++ [4] S) Int))

slide-127
SLIDE 127

(Arr [4] (Sigma ((N Dim)) (Arr [N] Int))) Four vectors, may vary in length (Sigma ((N Dim)) (Arr [4 N] Int)) Four vectors, same unknown length (Arr [4] (Sigma ((S Shape)) (Arr S Int))) Four arrays which may even differ in rank (Sigma ((S Shape)) (Arr (++ [4] S) Int)) Four arrays with same unknown shape

slide-128
SLIDE 128

(Arr [4] (Sigma ((N Dim)) (Arr [N] Int))) Four vectors, may vary in length (Sigma ((N Dim)) (Arr [4 N] Int)) Four vectors, same unknown length (Arr [4] (Sigma ((S Shape)) (Arr S Int))) Four arrays which may even differ in rank (Sigma ((S Shape)) (Arr (++ [4] S) Int)) Four arrays with same unknown shape Raggedness is frame structure around shape uncertainty

slide-129
SLIDE 129

filter : (Pi ((L Dim) (C Shape)) (∀ ((T Atom)) (-> ((Arr [L] Bool) (Arr (++ [L] C) T)) (Sigma ((N Dim)) (++ [N] C) T))))

slide-130
SLIDE 130

filter : (Pi ((L Dim) (C Shape)) (∀ ((T Atom)) (-> ((Arr [L] Bool) (Arr (++ [L] C) T)) (Sigma ((N Dim)) (++ [N] C) T)))) filter/p : (Pi ((L Dim) (C Shape)) (∀ ((T Atom)) (-> ((-> ((Arr C T)) Bool) (Arr (++ [L] C) T)) (Sigma ((N Dim)) (++ [N] C) T))))

slide-131
SLIDE 131

; Build a predicate to check ; membership in [lo,hi) in-range? : (-> (Int Int) (-> Int Bool))

slide-132
SLIDE 132

; Build a predicate to check ; membership in [lo,hi) in-range? : (-> (Int Int) (-> Int Bool)) (define binned-grades (filter/p (in-range? [ 0 60 70 80 90] [60 70 80 90 101]) grades))

slide-133
SLIDE 133

; Build a predicate to check ; membership in [lo,hi) in-range? : (-> (Int Int) (-> Int Bool)) (define binned-grades (filter/p (in-range? [ 0 60 70 80 90] [60 70 80 90 101]) grades)) binned-grades : (Arr [5] (Sigma ((N Dim)) (Arr [N] Int)))

slide-134
SLIDE 134

Type inference:

Identify index arguments elided by programmer

slide-135
SLIDE 135

Type inference:

Identify index arguments elided by programmer Function type (Pi (e ...) (-> ((Arr ι σ) ...) τ))

slide-136
SLIDE 136

Type inference:

Identify index arguments elided by programmer Function type Argument types (Pi (e ...) (-> ((Arr ι σ) ...) τ)) (Arr κ σ) ...

slide-137
SLIDE 137

Type inference:

Identify index arguments elided by programmer Function type Argument types (Pi (e ...) (-> ((Arr ι σ) ...) τ)) (Arr κ σ) ...

  • quantifiers for bound index vars
slide-138
SLIDE 138

Type inference:

Identify index arguments elided by programmer Function type Argument types (Pi (e ...) (-> ((Arr ι σ) ...) τ)) (Arr κ σ) ...

  • quantifiers for bound index vars
  • quantifiers for frames
slide-139
SLIDE 139

Type inference:

Identify index arguments elided by programmer Function type Argument types (Pi (e ...) (-> ((Arr ι σ) ...) τ)) (Arr κ σ) ...

  • quantifiers for bound index vars
  • quantifiers for frames
  • quantifiers for index arguments
slide-140
SLIDE 140

Type inference:

Identify index arguments elided by programmer Function type Argument types (Pi (e ...) (-> ((Arr ι σ) ...) τ)) (Arr κ σ) ...

  • quantifiers for bound index vars
  • quantifiers for frames (eliminated before)
  • quantifiers for index arguments
slide-141
SLIDE 141

Type inference:

Identify index arguments elided by programmer Function type Argument types (Pi (e ...) (-> ((Arr ι σ) ...) τ)) (Arr κ σ) ...

  • quantifiers for bound index vars
  • quantifiers for frames (eliminated before)
  • quantifiers for index arguments (solving for these)
slide-142
SLIDE 142

Function type Argument types (Pi (e ...) (-> ((Arr ι σ) ...) τ)) (Arr κ σ) ...

slide-143
SLIDE 143

Function type Argument types (Pi (e ...) (-> ((Arr ι σ) ...) τ)) (Arr κ σ) ...

slide-144
SLIDE 144

Function type Argument types (Pi (e ...) (-> ((Arr ι σ) ...) τ)) (Arr κ σ) ...

slide-145
SLIDE 145

Function type Argument types (Pi (e ...) (-> ((Arr ι σ) ...) τ)) (Arr κ σ) ...

slide-146
SLIDE 146

Function type Argument types (Pi (e ...) (-> ((Arr ι σ) ...) τ)) (Arr κ σ) ... Pretend are additional generators

slide-147
SLIDE 147

Why can we treat like additional generators?

slide-148
SLIDE 148

Why can we treat like additional generators? Algorithm for existential fragment (Makanin, 1977)

slide-149
SLIDE 149

Why can we treat like additional generators? Algorithm for existential fragment (Makanin, 1977) "How might subsequences align with each other?"

slide-150
SLIDE 150

Why can we treat like additional generators? Algorithm for existential fragment (Makanin, 1977) "How might subsequences align with each other?" Equations about smaller sequences

slide-151
SLIDE 151

Why can we treat like additional generators? Algorithm for existential fragment (Makanin, 1977) "How might subsequences align with each other?" Equations about smaller sequences No boundaries inside a generator

slide-152
SLIDE 152

Why can we treat like additional generators? Algorithm for existential fragment (Makanin, 1977) "How might subsequences align with each other?" Equations about smaller sequences No boundaries inside a generator ... or a universal variable

slide-153
SLIDE 153

Why can we treat like additional generators? Algorithm for existential fragment (Makanin, 1977) "How might subsequences align with each other?" Equations about smaller sequences No boundaries inside a generator ... or a universal variable Caveat: only works in conjunctive fragment

slide-154
SLIDE 154
slide-155
SLIDE 155

Type inference

slide-156
SLIDE 156

Type inference Compilation

slide-157
SLIDE 157

Type inference

Implement sketched algorithm

Compilation

slide-158
SLIDE 158

Type inference

Implement sketched algorithm Codebase for evaluating inference

Compilation

slide-159
SLIDE 159

Type inference

Implement sketched algorithm Codebase for evaluating inference

Compilation

Possible targets?

slide-160
SLIDE 160

Type inference

Implement sketched algorithm Codebase for evaluating inference

Compilation

Possible targets? IRs for array manipulation

slide-161
SLIDE 161

Type inference

Implement sketched algorithm Codebase for evaluating inference

Compilation

Possible targets? IRs for array manipulation

Broad goal

How much can we accomplish by combining a few powerful features instead of building lots of purpose-specifc machinery?