synquid: synthesizing programs from liquid typesnpolikarpova/talks/strangeloop18.pdf ·...
TRANSCRIPT
![Page 1: Synquid: Synthesizing Programs from Liquid Typesnpolikarpova/talks/strangeloop18.pdf · next_element: cmp dword [ebx + next], 0 je found_last mov ebx, [ebx + next] jmp next_element](https://reader033.vdocuments.mx/reader033/viewer/2022051917/6008fbe7af0f6456bc412765/html5/thumbnails/1.jpg)
type-driven program synthesis
Nadia Polikarpova
![Page 2: Synquid: Synthesizing Programs from Liquid Typesnpolikarpova/talks/strangeloop18.pdf · next_element: cmp dword [ebx + next], 0 je found_last mov ebx, [ebx + next] jmp next_element](https://reader033.vdocuments.mx/reader033/viewer/2022051917/6008fbe7af0f6456bc412765/html5/thumbnails/2.jpg)
2
my goal: automate programming
![Page 3: Synquid: Synthesizing Programs from Liquid Typesnpolikarpova/talks/strangeloop18.pdf · next_element: cmp dword [ebx + next], 0 je found_last mov ebx, [ebx + next] jmp next_element](https://reader033.vdocuments.mx/reader033/viewer/2022051917/6008fbe7af0f6456bc412765/html5/thumbnails/3.jpg)
example: insert into a sorted list
Input:
Output:
3
1 2 7 8
5
xs
x
1 2 7 85ys
![Page 4: Synquid: Synthesizing Programs from Liquid Typesnpolikarpova/talks/strangeloop18.pdf · next_element: cmp dword [ebx + next], 0 je found_last mov ebx, [ebx + next] jmp next_element](https://reader033.vdocuments.mx/reader033/viewer/2022051917/6008fbe7af0f6456bc412765/html5/thumbnails/4.jpg)
insert in a functional language
4
insert x xs =match xs with
Nil →Cons x Nil
Cons h t →if x ≤ h
then Cons x xselse Cons h (insert x t)
5
875 9
5
![Page 5: Synquid: Synthesizing Programs from Liquid Typesnpolikarpova/talks/strangeloop18.pdf · next_element: cmp dword [ebx + next], 0 je found_last mov ebx, [ebx + next] jmp next_element](https://reader033.vdocuments.mx/reader033/viewer/2022051917/6008fbe7af0f6456bc412765/html5/thumbnails/5.jpg)
5
insert x xs =match xs with
Nil →Cons x Nil
Cons h t →if x ≤ h
then Cons x xselse Cons h (insert x t)
void insert(node *xs, int x) {node *new;node *temp;node *prev;
new = (node *)malloc(sizeof(node));if(new == NULL) {printf("Insufficient memory.");return;
}new->val = x;new->next = NULL;if (xs == NULL) {xs = new;
} else if(x < xs->val) {new->next = xs;xs = new;
} else { prev = xs;temp = xs->next;while(temp != NULL && x > temp->val) {
prev = temp;temp = temp->next;
}if(temp == NULL) {
prev->next = new;} else {
new->next = temp;prev->next = new;
}}
}
automatespointer manipulation &memory management
C Haskell
![Page 6: Synquid: Synthesizing Programs from Liquid Typesnpolikarpova/talks/strangeloop18.pdf · next_element: cmp dword [ebx + next], 0 je found_last mov ebx, [ebx + next] jmp next_element](https://reader033.vdocuments.mx/reader033/viewer/2022051917/6008fbe7af0f6456bc412765/html5/thumbnails/6.jpg)
what’s next?
6
void insert(node *xs, int x) {node *new;node *temp;node *prev;
new = (node *)malloc(sizeof(node)); if(new == NULL) {printf("Insufficient memory.");return;
} new->val = x;new->next = NULL;if (xs == NULL) {xs = new;
} else if(x < xs->val) {new->next = xs;xs = new;
} else { prev = xs;temp = xs->next;while(temp != NULL && x > temp->val) {prev = temp;temp = temp->next;
}if(temp == NULL) {prev->next = new;
} else {new->next = temp;prev->next = new;
}}
}
insert x xs =match xs withNil → Cons x NilCons h t →if x ≤ hthen Cons x xselse Cons h (insert x t)
append:push ebpmov ebp, esppush eaxpush ebxpush lencall mallocmov ebx, [ebp + 12]mov [eax + info], ebxmov dword [eax + next], 0mov ebx, [ebp + 8]cmp dword [ebx], 0je null_pointermov ebx, [ebx]
next_element:cmp dword [ebx + next], 0je found_lastmov ebx, [ebx + next]jmp next_element
found_last:push eaxpush addMescall putsadd esp, 4pop eaxmov [ebx + next], eax
go_out:pop ebxpop eaxmov esp, ebppop ebpret 8
null_pointer:push eaxpush nullMescall putsadd esp, 4pop eaxmov [ebx], eaxjmp go_out
Assembly C Haskell
?future
automatesargument passing& memory access
![Page 7: Synquid: Synthesizing Programs from Liquid Typesnpolikarpova/talks/strangeloop18.pdf · next_element: cmp dword [ebx + next], 0 je found_last mov ebx, [ebx + next] jmp next_element](https://reader033.vdocuments.mx/reader033/viewer/2022051917/6008fbe7af0f6456bc412765/html5/thumbnails/7.jpg)
this talk
I. specificationsare the new cool language feature
II. program synthesisis the way to make it happen
III. synthesis-aided programmingis the the future
7
![Page 8: Synquid: Synthesizing Programs from Liquid Typesnpolikarpova/talks/strangeloop18.pdf · next_element: cmp dword [ebx + next], 0 je found_last mov ebx, [ebx + next] jmp next_element](https://reader033.vdocuments.mx/reader033/viewer/2022051917/6008fbe7af0f6456bc412765/html5/thumbnails/8.jpg)
this talk
I. specifications
II. program synthesis
III. synthesis-aided programming
8
![Page 9: Synquid: Synthesizing Programs from Liquid Typesnpolikarpova/talks/strangeloop18.pdf · next_element: cmp dword [ebx + next], 0 je found_last mov ebx, [ebx + next] jmp next_element](https://reader033.vdocuments.mx/reader033/viewer/2022051917/6008fbe7af0f6456bc412765/html5/thumbnails/9.jpg)
this talk
I. specifications
9
how do I tell the machine what I want?
![Page 10: Synquid: Synthesizing Programs from Liquid Typesnpolikarpova/talks/strangeloop18.pdf · next_element: cmp dword [ebx + next], 0 je found_last mov ebx, [ebx + next] jmp next_element](https://reader033.vdocuments.mx/reader033/viewer/2022051917/6008fbe7af0f6456bc412765/html5/thumbnails/10.jpg)
specification for insert
10
Input:
x
xs: sorted list
Output:
ys: sorted list
elems ys = elems xs ∪ {x}
easy to write ☺
hard to execute
![Page 11: Synquid: Synthesizing Programs from Liquid Typesnpolikarpova/talks/strangeloop18.pdf · next_element: cmp dword [ebx + next], 0 je found_last mov ebx, [ebx + next] jmp next_element](https://reader033.vdocuments.mx/reader033/viewer/2022051917/6008fbe7af0f6456bc412765/html5/thumbnails/11.jpg)
specification code
program synthesis
11
match xs withNil → Cons x NilCons h t →if x ≤ hthen Cons x xselse Cons h (insert x t)
in: x, sorted xsout: sorted ys
elems ys = elemsxs ∪ {x}
![Page 12: Synquid: Synthesizing Programs from Liquid Typesnpolikarpova/talks/strangeloop18.pdf · next_element: cmp dword [ebx + next], 0 je found_last mov ebx, [ebx + next] jmp next_element](https://reader033.vdocuments.mx/reader033/viewer/2022051917/6008fbe7af0f6456bc412765/html5/thumbnails/12.jpg)
Synquidspecification code
program synthesis
12
match xs withNil → Cons x NilCons h t →if x ≤ hthen Cons x xselse Cons h (insert x t)
in: x, sorted xsout: sorted ys
elems ys = elemsxs ∪ {x}
Synquid
![Page 13: Synquid: Synthesizing Programs from Liquid Typesnpolikarpova/talks/strangeloop18.pdf · next_element: cmp dword [ebx + next], 0 je found_last mov ebx, [ebx + next] jmp next_element](https://reader033.vdocuments.mx/reader033/viewer/2022051917/6008fbe7af0f6456bc412765/html5/thumbnails/13.jpg)
Synquidspecification code
program synthesis
13
match xs withNil → Cons x NilCons h t →if x ≤ hthen Cons x xselse Cons h (insert x t)
in: x, sorted xsout: sorted ys
elems ys = elemsxs ∪ {x}
formalize this
![Page 14: Synquid: Synthesizing Programs from Liquid Typesnpolikarpova/talks/strangeloop18.pdf · next_element: cmp dword [ebx + next], 0 je found_last mov ebx, [ebx + next] jmp next_element](https://reader033.vdocuments.mx/reader033/viewer/2022051917/6008fbe7af0f6456bc412765/html5/thumbnails/14.jpg)
types are specifications
14
insert :: a → List a → List a
![Page 15: Synquid: Synthesizing Programs from Liquid Typesnpolikarpova/talks/strangeloop18.pdf · next_element: cmp dword [ebx + next], 0 je found_last mov ebx, [ebx + next] jmp next_element](https://reader033.vdocuments.mx/reader033/viewer/2022051917/6008fbe7af0f6456bc412765/html5/thumbnails/15.jpg)
types are specifications
15
insert :: a → List a → List a
ordinary types are insufficient!
![Page 16: Synquid: Synthesizing Programs from Liquid Typesnpolikarpova/talks/strangeloop18.pdf · next_element: cmp dword [ebx + next], 0 je found_last mov ebx, [ebx + next] jmp next_element](https://reader033.vdocuments.mx/reader033/viewer/2022051917/6008fbe7af0f6456bc412765/html5/thumbnails/16.jpg)
refinement types
16
{ v:Int | 0 ≤ v }
shape refinement
![Page 17: Synquid: Synthesizing Programs from Liquid Typesnpolikarpova/talks/strangeloop18.pdf · next_element: cmp dword [ebx + next], 0 je found_last mov ebx, [ebx + next] jmp next_element](https://reader033.vdocuments.mx/reader033/viewer/2022051917/6008fbe7af0f6456bc412765/html5/thumbnails/17.jpg)
data SList a whereNil :: SList aCons :: h:a →
t:SList {v:a | h ≤ v} →SList a
from lists to sorted lists
17
List aList a
List aSList a →List a →
![Page 18: Synquid: Synthesizing Programs from Liquid Typesnpolikarpova/talks/strangeloop18.pdf · next_element: cmp dword [ebx + next], 0 je found_last mov ebx, [ebx + next] jmp next_element](https://reader033.vdocuments.mx/reader033/viewer/2022051917/6008fbe7af0f6456bc412765/html5/thumbnails/18.jpg)
data SList a whereNil :: SList aCons :: h:a →
t:SList {v:a | h ≤ v} →SList a
from lists to sorted lists
18
7 82
all you need is one simple predicate!
![Page 19: Synquid: Synthesizing Programs from Liquid Typesnpolikarpova/talks/strangeloop18.pdf · next_element: cmp dword [ebx + next], 0 je found_last mov ebx, [ebx + next] jmp next_element](https://reader033.vdocuments.mx/reader033/viewer/2022051917/6008fbe7af0f6456bc412765/html5/thumbnails/19.jpg)
insert :: x:a → xs:SList a →{v:SList a | elems v = elems xs ∪ {x}}
insert in Synquid
19
Synquid generates correct code in under a second!
![Page 20: Synquid: Synthesizing Programs from Liquid Typesnpolikarpova/talks/strangeloop18.pdf · next_element: cmp dword [ebx + next], 0 je found_last mov ebx, [ebx + next] jmp next_element](https://reader033.vdocuments.mx/reader033/viewer/2022051917/6008fbe7af0f6456bc412765/html5/thumbnails/20.jpg)
this talk
20
I. specifications
II.program synthesis
III. synthesis-aided programming
![Page 21: Synquid: Synthesizing Programs from Liquid Typesnpolikarpova/talks/strangeloop18.pdf · next_element: cmp dword [ebx + next], 0 je found_last mov ebx, [ebx + next] jmp next_element](https://reader033.vdocuments.mx/reader033/viewer/2022051917/6008fbe7af0f6456bc412765/html5/thumbnails/21.jpg)
this talk
21
I. specifications
II.program synthesis
how do we get from specification to code?
![Page 22: Synquid: Synthesizing Programs from Liquid Typesnpolikarpova/talks/strangeloop18.pdf · next_element: cmp dword [ebx + next], 0 je found_last mov ebx, [ebx + next] jmp next_element](https://reader033.vdocuments.mx/reader033/viewer/2022051917/6008fbe7af0f6456bc412765/html5/thumbnails/22.jpg)
type-driven program synthesis
22
match xs withNil → Cons x NilCons h t →if x ≤ hthen Cons x xselse Cons h (insert x t)
? insert :: x:a →xs:SList a →{v:SList a | elems v =elems xs ∪ {x}}
specification code
![Page 23: Synquid: Synthesizing Programs from Liquid Typesnpolikarpova/talks/strangeloop18.pdf · next_element: cmp dword [ebx + next], 0 je found_last mov ebx, [ebx + next] jmp next_element](https://reader033.vdocuments.mx/reader033/viewer/2022051917/6008fbe7af0f6456bc412765/html5/thumbnails/23.jpg)
synthesis as search
23
...
insert :: x:a →xs:SList a →{v:SList a | elems v =elems xs ∪ {x}}
Nil, Cons, ≤, …
specification
components
code
![Page 24: Synquid: Synthesizing Programs from Liquid Typesnpolikarpova/talks/strangeloop18.pdf · next_element: cmp dword [ebx + next], 0 je found_last mov ebx, [ebx + next] jmp next_element](https://reader033.vdocuments.mx/reader033/viewer/2022051917/6008fbe7af0f6456bc412765/html5/thumbnails/24.jpg)
synthesis as search
24
...
too many270
insert :: x:a →xs:SList a →{v:SList a | elems v =elems xs ∪ {x}}
Nil, Cons, ≤, …
specification
components
code
![Page 25: Synquid: Synthesizing Programs from Liquid Typesnpolikarpova/talks/strangeloop18.pdf · next_element: cmp dword [ebx + next], 0 je found_last mov ebx, [ebx + next] jmp next_element](https://reader033.vdocuments.mx/reader033/viewer/2022051917/6008fbe7af0f6456bc412765/html5/thumbnails/25.jpg)
25
synthesis as search
![Page 26: Synquid: Synthesizing Programs from Liquid Typesnpolikarpova/talks/strangeloop18.pdf · next_element: cmp dword [ebx + next], 0 je found_last mov ebx, [ebx + next] jmp next_element](https://reader033.vdocuments.mx/reader033/viewer/2022051917/6008fbe7af0f6456bc412765/html5/thumbnails/26.jpg)
26
synthesis as search
![Page 27: Synquid: Synthesizing Programs from Liquid Typesnpolikarpova/talks/strangeloop18.pdf · next_element: cmp dword [ebx + next], 0 je found_last mov ebx, [ebx + next] jmp next_element](https://reader033.vdocuments.mx/reader033/viewer/2022051917/6008fbe7af0f6456bc412765/html5/thumbnails/27.jpg)
27
synthesis as search
![Page 28: Synquid: Synthesizing Programs from Liquid Typesnpolikarpova/talks/strangeloop18.pdf · next_element: cmp dword [ebx + next], 0 je found_last mov ebx, [ebx + next] jmp next_element](https://reader033.vdocuments.mx/reader033/viewer/2022051917/6008fbe7af0f6456bc412765/html5/thumbnails/28.jpg)
28
key idea: reject hopeless programs early
synthesis as search
![Page 29: Synquid: Synthesizing Programs from Liquid Typesnpolikarpova/talks/strangeloop18.pdf · next_element: cmp dword [ebx + next], 0 je found_last mov ebx, [ebx + next] jmp next_element](https://reader033.vdocuments.mx/reader033/viewer/2022051917/6008fbe7af0f6456bc412765/html5/thumbnails/29.jpg)
reject hopeless programs early
29
insert :: x:a →xs:SList a →{v:SList a | elems v =elems xs ∪ {x}}
specification
![Page 30: Synquid: Synthesizing Programs from Liquid Typesnpolikarpova/talks/strangeloop18.pdf · next_element: cmp dword [ebx + next], 0 je found_last mov ebx, [ebx + next] jmp next_element](https://reader033.vdocuments.mx/reader033/viewer/2022051917/6008fbe7af0f6456bc412765/html5/thumbnails/30.jpg)
reject hopeless programs early
30
insert :: x:a →xs:SList a →{v:SList a | elems v =elems xs ∪ {x}}
specification
![Page 31: Synquid: Synthesizing Programs from Liquid Typesnpolikarpova/talks/strangeloop18.pdf · next_element: cmp dword [ebx + next], 0 je found_last mov ebx, [ebx + next] jmp next_element](https://reader033.vdocuments.mx/reader033/viewer/2022051917/6008fbe7af0f6456bc412765/html5/thumbnails/31.jpg)
reject hopeless programs early
31
insert :: x:a →xs:SList a →{v:SList a | elems v =elems xs ∪ {x}}
specification
![Page 32: Synquid: Synthesizing Programs from Liquid Typesnpolikarpova/talks/strangeloop18.pdf · next_element: cmp dword [ebx + next], 0 je found_last mov ebx, [ebx + next] jmp next_element](https://reader033.vdocuments.mx/reader033/viewer/2022051917/6008fbe7af0f6456bc412765/html5/thumbnails/32.jpg)
x:a → xs:SList a →{v:SList a | elems v = elems xs ∪ {x}}
insert x xs =match xs with
Nil → NilCons h t → ??
reject hopeless programs early
32
![Page 33: Synquid: Synthesizing Programs from Liquid Typesnpolikarpova/talks/strangeloop18.pdf · next_element: cmp dword [ebx + next], 0 je found_last mov ebx, [ebx + next] jmp next_element](https://reader033.vdocuments.mx/reader033/viewer/2022051917/6008fbe7af0f6456bc412765/html5/thumbnails/33.jpg)
x:a → xs:SList a →{v:SList a | elems v = elems xs ∪ {x}}
insert x xs =match xs with
Nil → NilCons h t → ??
reject hopeless programs early
33
250
![Page 34: Synquid: Synthesizing Programs from Liquid Typesnpolikarpova/talks/strangeloop18.pdf · next_element: cmp dword [ebx + next], 0 je found_last mov ebx, [ebx + next] jmp next_element](https://reader033.vdocuments.mx/reader033/viewer/2022051917/6008fbe7af0f6456bc412765/html5/thumbnails/34.jpg)
x:a → xs:SList a →{v:SList a | elems v = elems xs ∪ {x}}
insert x xs =match xs with
Nil → NilCons h t → ??
insert x xs =match xs with
Nil → NilCons h t → ??
{v:SList a | elems v = elems xs ∪ {x}}
reject hopeless programs early
34
![Page 35: Synquid: Synthesizing Programs from Liquid Typesnpolikarpova/talks/strangeloop18.pdf · next_element: cmp dword [ebx + next], 0 je found_last mov ebx, [ebx + next] jmp next_element](https://reader033.vdocuments.mx/reader033/viewer/2022051917/6008fbe7af0f6456bc412765/html5/thumbnails/35.jpg)
x:a → xs:SList a →{v:SList a | elems v = elems xs ∪ {x}}
insert x xs =match xs with
Nil → NilCons h t → ??
insert x xs =match xs with
Nil → NilCons h t → ??
insert x xs =match xs with
Nil → NilCons h t → ??
{v:SList a | elems v = elems xs ∪ {x}}{v:SList a | elems v = {x}}
reject hopeless programs early
35
![Page 36: Synquid: Synthesizing Programs from Liquid Typesnpolikarpova/talks/strangeloop18.pdf · next_element: cmp dword [ebx + next], 0 je found_last mov ebx, [ebx + next] jmp next_element](https://reader033.vdocuments.mx/reader033/viewer/2022051917/6008fbe7af0f6456bc412765/html5/thumbnails/36.jpg)
x:a → xs:SList a →{v:SList a | elems v = elems xs ∪ {x}}
insert x xs =match xs with
Nil → NilCons h t → ??
insert x xs =match xs with
Nil → NilCons h t → ??
insert x xs =match xs with
Nil → NilCons h t → ??
{v:SList a | elems v = elems xs ∪ {x}}{v:SList a | elems v = {x}}
reject hopeless programs early
36
Expected {v:SList a | elems v = {x}}and got {v:SList a | elems v = {}}
![Page 37: Synquid: Synthesizing Programs from Liquid Typesnpolikarpova/talks/strangeloop18.pdf · next_element: cmp dword [ebx + next], 0 je found_last mov ebx, [ebx + next] jmp next_element](https://reader033.vdocuments.mx/reader033/viewer/2022051917/6008fbe7af0f6456bc412765/html5/thumbnails/37.jpg)
synquid
37
match xs withNil → Cons x NilCons h t →if x ≤ hthen Cons x xselse Cons h (insert x t)
insert :: x:a →xs:SList a →{v:SList a | elems v =elems xs ∪ {x}}
specification code
components
![Page 38: Synquid: Synthesizing Programs from Liquid Typesnpolikarpova/talks/strangeloop18.pdf · next_element: cmp dword [ebx + next], 0 je found_last mov ebx, [ebx + next] jmp next_element](https://reader033.vdocuments.mx/reader033/viewer/2022051917/6008fbe7af0f6456bc412765/html5/thumbnails/38.jpg)
experiments
38
0
10
20
30
40
50
60
70
Lis
t-N
ull
Lis
t-E
lem
Lis
t-S
tutt
er
Lis
t-R
ep
lica
teLis
t-A
pp
en
dLis
t-C
on
cat
Lis
t-Ta
keLis
t-D
rop
Lis
t-D
ele
teLis
t-M
ap
Lis
t-Z
ipLis
t-Z
ipW
ith
Lis
t-P
rod
uct
Lis
t-It
hLis
t-E
lem
Ind
ex
Lis
t-S
no
cLis
t-R
eve
rse
Lis
t-Fo
ldr
Lis
t-Fo
ld-L
en
gth
Lis
t-Fo
ld-A
pp
en
dU
niq
ue
Lis
t-In
sert
Un
iqu
eLis
t-D
ele
teLis
t-N
ub
Lis
t-C
om
pre
ssU
niq
ue
Lis
t-R
an
ge
Str
ictI
ncL
ist-
Inse
rtS
tric
tIn
cLis
t-D
ele
teS
tric
tIn
cLis
t-In
ters
ect
IncL
ist-
Inse
rtLis
t-In
sert
So
rtLis
t-Fo
ld-S
ort
Lis
t-E
xtra
ctM
inLis
t-S
ele
ctS
ort
Lis
t-S
plit
IncL
ist-
Me
rge
Lis
t-M
erg
eS
ort
Lis
t-P
art
itio
nIn
cLis
t-P
ivo
tAp
pe
nd
Lis
t-Q
uic
kSo
rtT
ree
-Ele
mT
ree
-Co
un
tT
ree
-To
Lis
tB
ST
-Me
mb
er
BS
T-I
nse
rtB
ST
-De
lete
BS
T-S
ort
AV
L-R
ota
teL
AV
L-R
ota
teR
AV
L-B
ala
nce
AV
L-I
nse
rtA
VL-E
xtr
act
Min
AV
L-D
ele
teR
BT
-Ba
lan
ceL
RB
T-B
ala
nce
RR
BT
-In
sert
Ru
nLe
n-E
nco
de
Ru
nLe
n-D
eco
de
AS
T-D
esu
ga
rBo
ol
AS
T-D
esu
ga
rBo
ol2
AS
T-N
NF
AS
T-N
NFL
itB
DD
-Ma
keB
DD
-An
dB
DD
-Or
sec
lists sorting BSTAVL /
red-blackcustom
data types
![Page 39: Synquid: Synthesizing Programs from Liquid Typesnpolikarpova/talks/strangeloop18.pdf · next_element: cmp dword [ebx + next], 0 je found_last mov ebx, [ebx + next] jmp next_element](https://reader033.vdocuments.mx/reader033/viewer/2022051917/6008fbe7af0f6456bc412765/html5/thumbnails/39.jpg)
¬(a ⇒ b ∨ c)¬(a ⇒ b ∨ c)¬(a ⇒ b ∨ c)
case study: negation normal form
39
1. only ¬, ∧, ∨
2. ¬ only at variables
![Page 40: Synquid: Synthesizing Programs from Liquid Typesnpolikarpova/talks/strangeloop18.pdf · next_element: cmp dword [ebx + next], 0 je found_last mov ebx, [ebx + next] jmp next_element](https://reader033.vdocuments.mx/reader033/viewer/2022051917/6008fbe7af0f6456bc412765/html5/thumbnails/40.jpg)
¬(a ⇒ b ∨ c)¬(a ⇒ b ∨ c)¬(a ⇒ b ∨ c)
case study: negation normal form
40
a ∧ (¬b ∨ ¬c)
1. only ¬, ∧, ∨
2. ¬ only at variables
¬(¬a ∨ (b ∨ c))
¬¬a ∧ ¬(b ∨ c)
a ∧ ¬(b ∨ c)
⇒ def.
De Morgan
double-neg
De Morgan
![Page 41: Synquid: Synthesizing Programs from Liquid Typesnpolikarpova/talks/strangeloop18.pdf · next_element: cmp dword [ebx + next], 0 je found_last mov ebx, [ebx + next] jmp next_element](https://reader033.vdocuments.mx/reader033/viewer/2022051917/6008fbe7af0f6456bc412765/html5/thumbnails/41.jpg)
nnf: data types
41
data Fml whereVar :: String → FmlNot :: Fml → FmlAnd :: Fml → Fml → FmlOr :: Fml → Fml → FmlImp :: Fml → Fml → Fml
data NNF whereNAtom :: String → Bool
→ NNFNAnd :: NNF → NNF → NNFNOr :: NNF → NNF → NNF
negated?
![Page 42: Synquid: Synthesizing Programs from Liquid Typesnpolikarpova/talks/strangeloop18.pdf · next_element: cmp dword [ebx + next], 0 je found_last mov ebx, [ebx + next] jmp next_element](https://reader033.vdocuments.mx/reader033/viewer/2022051917/6008fbe7af0f6456bc412765/html5/thumbnails/42.jpg)
nnf: specification
42
data Fml whereVar :: String → FmlNot :: Fml → FmlAnd :: Fml → Fml → FmlOr :: Fml → Fml → FmlImp :: Fml → Fml → Fml
data NNF whereNAtom :: String → Bool
→ NNFNAnd :: NNF → NNF → NNFNOr :: NNF → NNF → NNF
measure eval :: Fml → Bool whereVar v → env vNot f → !(eval f)And l r → eval l && eval rOr l r → eval l || eval rImp l r → eval l ==> eval r
measure nEval :: NNF → Bool whereNAtom neg v → if neg then env v
else !(env v)NAnd l r → nEval l && nEval rNOr l r → nEval l || nEval r
![Page 43: Synquid: Synthesizing Programs from Liquid Typesnpolikarpova/talks/strangeloop18.pdf · next_element: cmp dword [ebx + next], 0 je found_last mov ebx, [ebx + next] jmp next_element](https://reader033.vdocuments.mx/reader033/viewer/2022051917/6008fbe7af0f6456bc412765/html5/thumbnails/43.jpg)
nnf: specification
43
nnf :: f:Fml → {v:NNF | nEval v = eval f}
![Page 44: Synquid: Synthesizing Programs from Liquid Typesnpolikarpova/talks/strangeloop18.pdf · next_element: cmp dword [ebx + next], 0 je found_last mov ebx, [ebx + next] jmp next_element](https://reader033.vdocuments.mx/reader033/viewer/2022051917/6008fbe7af0f6456bc412765/html5/thumbnails/44.jpg)
nnf: synthesized code
44
nnf :: f:Fml → {v:NNF | nEval v = eval f}nnf p = match p with
BoolLiteral x2 → if x2then NOr (NAtom dummy x2) (NAtom dummy False)else NAnd (NAtom dummy x2) (NAtom dummy True)
Var x16 → NAtom x16 FalseNot x20 → match x20 withBoolLiteral x22 → if x22then nnf (BoolLiteral False)else nnf (BoolLiteral True)
Var x28 → NAtom x28 TrueNot x32 → nnf x32And x36 x37 → NOr (nnf (Not x36)) (nnf (Not x37))Or x46 x47 → NAnd (nnf (Not x46)) (nnf (Not x47))Implies x56 x57 → NAnd (nnf x56) (nnf (Not x57))
And x65 x66 → NAnd (nnf x65) (nnf x66)Or x73 x74 → NOr (nnf x73) (nnf x74)Imp x81 x82 → NOr (nnf x82) (nnf (Not x81)) ⇒ def.
double-neg
De Morgan
![Page 45: Synquid: Synthesizing Programs from Liquid Typesnpolikarpova/talks/strangeloop18.pdf · next_element: cmp dword [ebx + next], 0 je found_last mov ebx, [ebx + next] jmp next_element](https://reader033.vdocuments.mx/reader033/viewer/2022051917/6008fbe7af0f6456bc412765/html5/thumbnails/45.jpg)
this talk
45
I. specifications
II. program synthesis
III. synthesis-aided programming
![Page 46: Synquid: Synthesizing Programs from Liquid Typesnpolikarpova/talks/strangeloop18.pdf · next_element: cmp dword [ebx + next], 0 je found_last mov ebx, [ebx + next] jmp next_element](https://reader033.vdocuments.mx/reader033/viewer/2022051917/6008fbe7af0f6456bc412765/html5/thumbnails/46.jpg)
this talk
46
I. specifications
II. program synthesis
III. synthesis-aided programming
how can synthesis help us build software?
![Page 47: Synquid: Synthesizing Programs from Liquid Typesnpolikarpova/talks/strangeloop18.pdf · next_element: cmp dword [ebx + next], 0 je found_last mov ebx, [ebx + next] jmp next_element](https://reader033.vdocuments.mx/reader033/viewer/2022051917/6008fbe7af0f6456bc412765/html5/thumbnails/47.jpg)
the future of programming
47
Let there be Instagram!
![Page 48: Synquid: Synthesizing Programs from Liquid Typesnpolikarpova/talks/strangeloop18.pdf · next_element: cmp dword [ebx + next], 0 je found_last mov ebx, [ebx + next] jmp next_element](https://reader033.vdocuments.mx/reader033/viewer/2022051917/6008fbe7af0f6456bc412765/html5/thumbnails/48.jpg)
the future of programming
48
Let there be Instagram!
(not)
![Page 49: Synquid: Synthesizing Programs from Liquid Typesnpolikarpova/talks/strangeloop18.pdf · next_element: cmp dword [ebx + next], 0 je found_last mov ebx, [ebx + next] jmp next_element](https://reader033.vdocuments.mx/reader033/viewer/2022051917/6008fbe7af0f6456bc412765/html5/thumbnails/49.jpg)
orthogonal concerns
49
functional requirements
datainvariants
security policies
resource constraints
I worry about all concerns together
![Page 50: Synquid: Synthesizing Programs from Liquid Typesnpolikarpova/talks/strangeloop18.pdf · next_element: cmp dword [ebx + next], 0 je found_last mov ebx, [ebx + next] jmp next_element](https://reader033.vdocuments.mx/reader033/viewer/2022051917/6008fbe7af0f6456bc412765/html5/thumbnails/50.jpg)
synthesis-aided programming
50
functional requirements
datainvariants
security policies
resource constraints
I worry about one concern at a time ☺
specification
synthesis weaves them together
![Page 51: Synquid: Synthesizing Programs from Liquid Typesnpolikarpova/talks/strangeloop18.pdf · next_element: cmp dword [ebx + next], 0 je found_last mov ebx, [ebx + next] jmp next_element](https://reader033.vdocuments.mx/reader033/viewer/2022051917/6008fbe7af0f6456bc412765/html5/thumbnails/51.jpg)
synthesis-aided programming
51
functional requirements
security policies
specification
![Page 52: Synquid: Synthesizing Programs from Liquid Typesnpolikarpova/talks/strangeloop18.pdf · next_element: cmp dword [ebx + next], 0 je found_last mov ebx, [ebx + next] jmp next_element](https://reader033.vdocuments.mx/reader033/viewer/2022051917/6008fbe7af0f6456bc412765/html5/thumbnails/52.jpg)
information leaks
52
electronic health records social networks e-commerce
![Page 53: Synquid: Synthesizing Programs from Liquid Typesnpolikarpova/talks/strangeloop18.pdf · next_element: cmp dword [ebx + next], 0 je found_last mov ebx, [ebx + next] jmp next_element](https://reader033.vdocuments.mx/reader033/viewer/2022051917/6008fbe7af0f6456bc412765/html5/thumbnails/53.jpg)
information leaks
53
social networks
policy checks
![Page 54: Synquid: Synthesizing Programs from Liquid Typesnpolikarpova/talks/strangeloop18.pdf · next_element: cmp dword [ebx + next], 0 je found_last mov ebx, [ebx + next] jmp next_element](https://reader033.vdocuments.mx/reader033/viewer/2022051917/6008fbe7af0f6456bc412765/html5/thumbnails/54.jpg)
information leaks
54
social networks
James ComeyBrian Comey
Ashley Feinberg
![Page 55: Synquid: Synthesizing Programs from Liquid Typesnpolikarpova/talks/strangeloop18.pdf · next_element: cmp dword [ebx + next], 0 je found_last mov ebx, [ebx + next] jmp next_element](https://reader033.vdocuments.mx/reader033/viewer/2022051917/6008fbe7af0f6456bc412765/html5/thumbnails/55.jpg)
information security with Lifty
55
program with checks
securitypolicies
program
Lifty
![Page 56: Synquid: Synthesizing Programs from Liquid Typesnpolikarpova/talks/strangeloop18.pdf · next_element: cmp dword [ebx + next], 0 je found_last mov ebx, [ebx + next] jmp next_element](https://reader033.vdocuments.mx/reader033/viewer/2022051917/6008fbe7af0f6456bc412765/html5/thumbnails/56.jpg)
synthesis-aided programming
56
functional requirements
resource constraints
specification
![Page 57: Synquid: Synthesizing Programs from Liquid Typesnpolikarpova/talks/strangeloop18.pdf · next_element: cmp dword [ebx + next], 0 je found_last mov ebx, [ebx + next] jmp next_element](https://reader033.vdocuments.mx/reader033/viewer/2022051917/6008fbe7af0f6456bc412765/html5/thumbnails/57.jpg)
timing attacks
57
password
attempt
execution time reveals length!
Compare the lengths of two strings:
![Page 58: Synquid: Synthesizing Programs from Liquid Typesnpolikarpova/talks/strangeloop18.pdf · next_element: cmp dword [ebx + next], 0 je found_last mov ebx, [ebx + next] jmp next_element](https://reader033.vdocuments.mx/reader033/viewer/2022051917/6008fbe7af0f6456bc412765/html5/thumbnails/58.jpg)
resource-aware programming with ReSyn
58
password
attempt
compare :: pass:List a → att:List a →{v:Bool | v = (len key = len guess)}
unit resource per element
1 1 1 11
{a || 1} →
![Page 59: Synquid: Synthesizing Programs from Liquid Typesnpolikarpova/talks/strangeloop18.pdf · next_element: cmp dword [ebx + next], 0 je found_last mov ebx, [ebx + next] jmp next_element](https://reader033.vdocuments.mx/reader033/viewer/2022051917/6008fbe7af0f6456bc412765/html5/thumbnails/59.jpg)
synthesis-aided programming
59