-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlecture-6.tex
427 lines (394 loc) · 15.8 KB
/
lecture-6.tex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
\documentclass{tufte-handout}
\title{Discrete Probabilistic Programming Languages\thanks{CS7470 Fall 2023: Foundations of Probabilistic Programming.}}
\newcommand{\varset}[0]{\mathcal{V}}
\author[]{Steven Holtzen\\[email protected]}
%\date{28 March 2010} % without \date command, current date is supplied
%\geometry{showframe} % display margins for debugging page layout
\input{../header.tex}
\begin{document}
\maketitle% this prints the handout title, author, and date
\begin{itemize}
\item Goal for today: compile a simple discrete PPL to BDD
\end{itemize}
\section{Compositional compilation of BDDs}
\begin{itemize}
\item So far we have compiled by inducting on variables
\item \textbf{Problem}: this is not \emph{compositional}! A compilation
process is compositional if it works by compiling big programs out of
smaller sub-programs. I.e., it would have a rule that looks something like:
\begin{mathpar}
\inferrule{\alpha \compiles \alpha' \and \beta \compiles \beta'}{
\alpha \land \beta \compiles \alpha' \times \beta'
}
\end{mathpar}
\item Compositional compilation is great: gives us modular reasoning
about performance, ... (other reasons?)
\item \textbf{Goal}: Design a compositional process for compiling \prop$_S$ to
\bdd{}
\item How can we build big BDDs out of smaller ones? Define a way to compose together
BDDs, again using a type-directed step-relation $\Gamma \vdash \alpha_1 \land
\alpha_2 \Downarrow \beta$, shown in Figure~\ref{fig:bdd}.
\begin{theorem}[Correctness]
If $\Gamma \vdash \alpha_1$, $\Gamma \vdash \alpha_2$, and $\Gamma \vdash \alpha_1 \land \alpha_2 \Downarrow \beta$,
then $\dbracket{\alpha_1} \cap \dbracket{\alpha_2} = \dbracket{\beta}$.
\end{theorem}
\begin{proof}
By simultaneous structural induction on syntax of BDDs (note that we need to
perform simultaneous induction since there are two BDDs at play here). The
rules in Figure~\ref{fig:bdd} are exhaustive (i.e., every pair of syntactic BDDs matches
exactly one of these structural rules), so we can proceed by case analysis on each
of the compilation rules. The base cases are quite simple and we elide them here. The
interesting cases are the inductive cases.
We will show the case for \textsc{(SameVarNE)}. Assume that $\Gamma \vdash \alpha_1 \land
\alpha_3 \Downarrow \alpha_{13}$ and $\Gamma \vdash \alpha_2 \land \alpha_4 \Downarrow
\alpha_{24}$. As usual, our inductive hypothesis assumes that the theorem
holds for compiled subterms:
\begin{itemize}
\item $\dbracket{\Gamma \vdash \alpha_1} \cap \dbracket{\Gamma \vdash \alpha_3} = \dbracket{\Gamma \vdash \alpha_{13}}$
\item $\dbracket{\Gamma \vdash \alpha_2} \cap \dbracket{\Gamma \vdash \alpha_4} = \dbracket{\Gamma \vdash \alpha_{24}}$
\end{itemize}
We want to show that:
\begin{align*}
\dbracket{x :: \Gamma \vdash \begin{tikzpicture}
\node (x) [bddnode] {$x$};
\node (a1) at ($(x) + (-25bp, -20pt)$) [bddtriangle] {$\alpha_1$};
\node (a2) at ($(x) + (25bp, -20pt)$) [bddtriangle] {$\alpha_2$};
\begin{scope}[on background layer]
\draw [highedge] (x) -- (a1);
\draw [lowedge] (x) -- (a2);
\end{scope}
\end{tikzpicture}}
\bigcap
\dbracket{x :: \Gamma \vdash
\begin{tikzpicture}
\node (x) [bddnode] {$x$};
\node (a1) at ($(x) + (-25bp, -20pt)$) [bddtriangle] {$\alpha_3$};
\node (a2) at ($(x) + (25bp, -20pt)$) [bddtriangle] {$\alpha_4$};
\begin{scope}[on background layer]
\draw [highedge] (x) -- (a1);
\draw [lowedge] (x) -- (a2);
\end{scope}
\end{tikzpicture}
} =
\dbracket{x :: \Gamma \vdash
\begin{tikzpicture}
\node (x) [bddnode] {$x$};
\node (a1) at ($(x) + (-25bp, -20pt)$) [bddtriangle] {$\alpha_{13}$};
\node (a2) at ($(x) + (25bp, -20pt)$) [bddtriangle] {$\alpha_{24}$};
\begin{scope}[on background layer]
\draw [highedge] (x) -- (a1);
\draw [lowedge] (x) -- (a2);
\end{scope}
\end{tikzpicture}
}
\end{align*}
We reason forward:
{\footnotesize
\begin{align*}
\dbracket{x :: \Gamma \vdash
\begin{tikzpicture}
\node (x) [bddnode] {$x$};
\node (a1) at ($(x) + (-25bp, -20pt)$) [bddtriangle] {$\alpha_{13}$};
\node (a2) at ($(x) + (25bp, -20pt)$) [bddtriangle] {$\alpha_{24}$};
\begin{scope}[on background layer]
\draw [highedge] (x) -- (a1);
\draw [lowedge] (x) -- (a2);
\end{scope}
\end{tikzpicture}
} &=
[x \mapsto \true] \otimes \dbracket{\Gamma \vdash \alpha_{13}} ~\bigcup~ [x \mapsto \false] \otimes \dbracket{\Gamma \vdash \alpha_{24}} \\
&= [x \mapsto \true] \otimes \Big( \dbracket{\Gamma \vdash \alpha_1} \cap \dbracket{\Gamma \vdash \alpha_3} \Big)
~\bigcup~ [x \mapsto \false] \otimes \Big( \dbracket{\Gamma \vdash \alpha_2} \cap \dbracket{\Gamma \vdash \alpha_4} \Big)
& \text{By I.H.} \\
&= \Big( [x \mapsto \true] \dbracket{\Gamma \vdash \alpha_1} \cap [x \mapsto \true] \dbracket{\Gamma \vdash \alpha_3} \Big)
~\bigcup~ \Big([x \mapsto \false] \dbracket{\Gamma \vdash \alpha_2} \cap [x \mapsto \false]\dbracket{\Gamma \vdash \alpha_4} \Big)
& (\star)\\
&= \Big( [x \mapsto \true] \dbracket{\Gamma \vdash \alpha_1} \cup [x \mapsto \false] \dbracket{\Gamma \vdash \alpha_2} \Big)
~\bigcap~ \Big([x \mapsto \true] \dbracket{\Gamma \vdash \alpha_1} \cup [x \mapsto \false]\dbracket{\Gamma \vdash \alpha_4} \Big)
& (\dagger) \\
&= \dbracket{x :: \Gamma \vdash \begin{tikzpicture}
\node (x) [bddnode] {$x$};
\node (a1) at ($(x) + (-25bp, -20pt)$) [bddtriangle] {$\alpha_1$};
\node (a2) at ($(x) + (25bp, -20pt)$) [bddtriangle] {$\alpha_2$};
\begin{scope}[on background layer]
\draw [highedge] (x) -- (a1);
\draw [lowedge] (x) -- (a2);
\end{scope}
\end{tikzpicture}}
\bigcap
\dbracket{x :: \Gamma \vdash
\begin{tikzpicture}
\node (x) [bddnode] {$x$};
\node (a1) at ($(x) + (-25bp, -20pt)$) [bddtriangle] {$\alpha_3$};
\node (a2) at ($(x) + (25bp, -20pt)$) [bddtriangle] {$\alpha_4$};
\begin{scope}[on background layer]
\draw [highedge] (x) -- (a1);
\draw [lowedge] (x) -- (a2);
\end{scope}
\end{tikzpicture}
}
\end{align*}
}
where $(\star)$ follows from a simple lemma that $\otimes$ distributes over intersection
and $(\dagger)$ follows from distributivity properties of union and intersection,
in particular the fact that for any sets $A,B,C,D$ it is the case that $(A \cup B) \cap (C \cup D) =
(A \cap C) \cup (B \cap D)$.\sidenote{This set theory property has a nice
``proof by Venn-diagram''; draw the Venn-diagram of these sets to see this
fact clearly.}
\end{proof}
\item We would also like to ensure that our compilation rules produce reduced and ordered
BDDs. We can formalize this with a type-preservation theorem:
\begin{theorem}[Type preservation]
If $\Gamma \vdash \alpha_1$, $\Gamma \vdash \alpha_2$, and $\Gamma \vdash \alpha_1 \land \alpha_2 \Downarrow \alpha$,
then $\Gamma \vdash \alpha$.
\end{theorem}
\item These rules are called \emph{bottom-up BDD compilation}~\citep{darwiche2002knowledge,oztok2015top}.
\item There are several other compositional BDD operations we won't have time
to explain in lecture, but you can use in your lab, like disjunction, negation, substitution,
and existential quantification.
\item Why might one prefer one mode of compilation over the other? Do they
have different runtime cost? \emph{Yes!}
\item \textbf{Exercise}: Give example families of formulae where
top-down compilation is faster than bottom-up and vice-versa.
\end{itemize}
\begin{figure}
\begin{mathpar}
\inferrule{}{\Gamma \vdash \bddtrue{} \land \alpha \Downarrow \alpha} \and
\inferrule{}{\Gamma \vdash \alpha \land \bddtrue{} \Downarrow \alpha} \\
\inferrule{}{\Gamma \vdash \bddfalse{} \land \alpha \Downarrow \bddfalse{}} \and
\inferrule{}{\Gamma \vdash \alpha \land \bddfalse{} \Downarrow \bddfalse{}} \\
\inferrule*[Right={\textsc{(SameVarNE)}}]{\Gamma \vdash \alpha_1 \land \alpha_3 \compiles \alpha_{13} \and
\Gamma \vdash \alpha_2 \land \alpha_4 \compiles \alpha_{24} \and
\alpha_{13} \ne \alpha_{24}
}{x :: \Gamma \vdash
\begin{tikzpicture}
\node (x) [bddnode] {$x$};
\node (a1) at ($(x) + (-25bp, -20pt)$) [bddtriangle] {$\alpha_1$};
\node (a2) at ($(x) + (25bp, -20pt)$) [bddtriangle] {$\alpha_2$};
\begin{scope}[on background layer]
\draw [highedge] (x) -- (a1);
\draw [lowedge] (x) -- (a2);
\end{scope}
\end{tikzpicture}
\land
\begin{tikzpicture}
\node (x) [bddnode] {$x$};
\node (a1) at ($(x) + (-25bp, -20pt)$) [bddtriangle] {$\alpha_3$};
\node (a2) at ($(x) + (25bp, -20pt)$) [bddtriangle] {$\alpha_4$};
\begin{scope}[on background layer]
\draw [highedge] (x) -- (a1);
\draw [lowedge] (x) -- (a2);
\end{scope}
\end{tikzpicture}
\Downarrow
\begin{tikzpicture}
\node (x) [bddnode] {$x$};
\node (a1) at ($(x) + (-25bp, -20pt)$) [bddtriangle] {$\alpha_{13}$};
\node (a2) at ($(x) + (25bp, -20pt)$) [bddtriangle] {$\alpha_{24}$};
\begin{scope}[on background layer]
\draw [highedge] (x) -- (a1);
\draw [lowedge] (x) -- (a2);
\end{scope}
\end{tikzpicture}
}
\\
\inferrule*[Right={\textsc{(SameVarEQ)}}]{\Gamma \vdash \alpha_1 \land \alpha_3 \compiles \alpha_{13} \and
\Gamma \vdash \alpha_2 \land \alpha_4 \compiles \alpha_{24} \and
\alpha_{13} = \alpha_{24}
}{x :: \Gamma \vdash
\begin{tikzpicture}
\node (x) [bddnode] {$x$};
\node (a1) at ($(x) + (-25bp, -20pt)$) [bddtriangle] {$\alpha_1$};
\node (a2) at ($(x) + (25bp, -20pt)$) [bddtriangle] {$\alpha_2$};
\begin{scope}[on background layer]
\draw [highedge] (x) -- (a1);
\draw [lowedge] (x) -- (a2);
\end{scope}
\end{tikzpicture}
\land
\begin{tikzpicture}
\node (x) [bddnode] {$x$};
\node (a1) at ($(x) + (-25bp, -20pt)$) [bddtriangle] {$\alpha_3$};
\node (a2) at ($(x) + (25bp, -20pt)$) [bddtriangle] {$\alpha_4$};
\begin{scope}[on background layer]
\draw [highedge] (x) -- (a1);
\draw [lowedge] (x) -- (a2);
\end{scope}
\end{tikzpicture}
\Downarrow
\bddtriangle{$\alpha_{24}$}
}
\\
\inferrule*[Right=\textsc{(Weaken)}]{x \ne y \ne z \and
\Gamma \vdash
\begin{tikzpicture}
\node (x) [bddnode] {$y$};
\node (a1) at ($(x) + (-25bp, -20pt)$) [bddtriangle] {$\alpha_1$};
\node (a2) at ($(x) + (25bp, -20pt)$) [bddtriangle] {$\alpha_2$};
\begin{scope}[on background layer]
\draw [highedge] (x) -- (a1);
\draw [lowedge] (x) -- (a2);
\end{scope}
\end{tikzpicture}
\land
\begin{tikzpicture}
\node (x) [bddnode] {$z$};
\node (a1) at ($(x) + (-25bp, -20pt)$) [bddtriangle] {$\alpha_3$};
\node (a2) at ($(x) + (25bp, -20pt)$) [bddtriangle] {$\alpha_4$};
\begin{scope}[on background layer]
\draw [highedge] (x) -- (a1);
\draw [lowedge] (x) -- (a2);
\end{scope}
\end{tikzpicture}
\Downarrow
\bddtriangle{$\alpha$}
}{x :: \Gamma \vdash
\begin{tikzpicture}
\node (x) [bddnode] {$y$};
\node (a1) at ($(x) + (-25bp, -20pt)$) [bddtriangle] {$\alpha_1$};
\node (a2) at ($(x) + (25bp, -20pt)$) [bddtriangle] {$\alpha_2$};
\begin{scope}[on background layer]
\draw [highedge] (x) -- (a1);
\draw [lowedge] (x) -- (a2);
\end{scope}
\end{tikzpicture}
\land
\begin{tikzpicture}
\node (x) [bddnode] {$z$};
\node (a1) at ($(x) + (-25bp, -20pt)$) [bddtriangle] {$\alpha_3$};
\node (a2) at ($(x) + (25bp, -20pt)$) [bddtriangle] {$\alpha_4$};
\begin{scope}[on background layer]
\draw [highedge] (x) -- (a1);
\draw [lowedge] (x) -- (a2);
\end{scope}
\end{tikzpicture}
\Downarrow
\bddtriangle{$\alpha$}
}
\\
\inferrule*[Right=\textsc{(ParNE)}]{x \ne y \and
\Gamma \vdash
\begin{tikzpicture}
\node (x) [bddnode] {$y$};
\node (a1) at ($(x) + (-25bp, -20pt)$) [bddtriangle] {$\alpha_1$};
\node (a2) at ($(x) + (25bp, -20pt)$) [bddtriangle] {$\alpha_2$};
\begin{scope}[on background layer]
\draw [highedge] (x) -- (a1);
\draw [lowedge] (x) -- (a2);
\end{scope}
\end{tikzpicture}
\land
\bddtriangle{$\alpha_1$}
\Downarrow
\alpha_{y_1}
\and
\Gamma \vdash
\begin{tikzpicture}
\node (x) [bddnode] {$y$};
\node (a1) at ($(x) + (-25bp, -20pt)$) [bddtriangle] {$\alpha_1$};
\node (a2) at ($(x) + (25bp, -20pt)$) [bddtriangle] {$\alpha_2$};
\begin{scope}[on background layer]
\draw [highedge] (x) -- (a1);
\draw [lowedge] (x) -- (a2);
\end{scope}
\end{tikzpicture}
\land
\bddtriangle{$\alpha_2$}
\Downarrow
\alpha_{y_2}
\and
\alpha_{y_1} \ne \alpha_{y_2}
}{x :: \Gamma \vdash
\begin{tikzpicture}
\node (x) [bddnode] {$x$};
\node (a1) at ($(x) + (-25bp, -20pt)$) [bddtriangle] {$\alpha_1$};
\node (a2) at ($(x) + (25bp, -20pt)$) [bddtriangle] {$\alpha_2$};
\begin{scope}[on background layer]
\draw [highedge] (x) -- (a1);
\draw [lowedge] (x) -- (a2);
\end{scope}
\end{tikzpicture}
\land
\begin{tikzpicture}
\node (x) [bddnode] {$y$};
\node (a1) at ($(x) + (-25bp, -20pt)$) [bddtriangle] {$\alpha_3$};
\node (a2) at ($(x) + (25bp, -20pt)$) [bddtriangle] {$\alpha_4$};
\begin{scope}[on background layer]
\draw [highedge] (x) -- (a1);
\draw [lowedge] (x) -- (a2);
\end{scope}
\end{tikzpicture}
\Downarrow
\begin{tikzpicture}
\node (x) [bddnode] {$x$};
\node (a1) at ($(x) + (-25bp, -20pt)$) [bddtriangle] {$\alpha_{y_1}$};
\node (a2) at ($(x) + (25bp, -20pt)$) [bddtriangle] {$\alpha_{y_2}$};
\begin{scope}[on background layer]
\draw [highedge] (x) -- (a1);
\draw [lowedge] (x) -- (a2);
\end{scope}
\end{tikzpicture}
}
\\
\inferrule*[Right=\textsc{(ParEQ)}]{x \ne y \and
\Gamma \vdash
\begin{tikzpicture}
\node (x) [bddnode] {$y$};
\node (a1) at ($(x) + (-25bp, -20pt)$) [bddtriangle] {$\alpha_1$};
\node (a2) at ($(x) + (25bp, -20pt)$) [bddtriangle] {$\alpha_2$};
\begin{scope}[on background layer]
\draw [highedge] (x) -- (a1);
\draw [lowedge] (x) -- (a2);
\end{scope}
\end{tikzpicture}
\land
\bddtriangle{$\alpha_1$}
\Downarrow
\alpha_{y_1}
\and
\Gamma \vdash
\begin{tikzpicture}
\node (x) [bddnode] {$y$};
\node (a1) at ($(x) + (-25bp, -20pt)$) [bddtriangle] {$\alpha_1$};
\node (a2) at ($(x) + (25bp, -20pt)$) [bddtriangle] {$\alpha_2$};
\begin{scope}[on background layer]
\draw [highedge] (x) -- (a1);
\draw [lowedge] (x) -- (a2);
\end{scope}
\end{tikzpicture}
\land
\bddtriangle{$\alpha_2$}
\Downarrow
\alpha_{y_2}
\and
\alpha_{y_1} = \alpha_{y_2}
}{x :: \Gamma \vdash
\begin{tikzpicture}
\node (x) [bddnode] {$x$};
\node (a1) at ($(x) + (-25bp, -20pt)$) [bddtriangle] {$\alpha_1$};
\node (a2) at ($(x) + (25bp, -20pt)$) [bddtriangle] {$\alpha_2$};
\begin{scope}[on background layer]
\draw [highedge] (x) -- (a1);
\draw [lowedge] (x) -- (a2);
\end{scope}
\end{tikzpicture}
\land
\begin{tikzpicture}
\node (x) [bddnode] {$y$};
\node (a1) at ($(x) + (-25bp, -20pt)$) [bddtriangle] {$\alpha_3$};
\node (a2) at ($(x) + (25bp, -20pt)$) [bddtriangle] {$\alpha_4$};
\begin{scope}[on background layer]
\draw [highedge] (x) -- (a1);
\draw [lowedge] (x) -- (a2);
\end{scope}
\end{tikzpicture}
\Downarrow
\alpha_{y_2}
}
\end{mathpar}
\caption{Rules for compiling BDDs.}
\label{fig:bdd}
\end{figure}
\bibliographystyle{plainnat}
\bibliography{../bib}
\end{document}