-
Notifications
You must be signed in to change notification settings - Fork 0
/
02-refinements.html
781 lines (700 loc) · 37.7 KB
/
02-refinements.html
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
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="generator" content="rustdoc">
<title>Language-Integrated Verification</title>
<link href="./css/bootstrap.css" rel="stylesheet">
<link href="./css/bootstrap-theme.css" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="./css/rust-book-slides.css">
<link rel="stylesheet" type="text/css" href="./css/editor-slides.css">
<link rel="stylesheet" type="text/css" href="./css/code-format.css">
<link rel="stylesheet" type="text/css" href="./css/slideshow.css">
<style>
body {
text-align: center;
}
.mybreak {
line-height: 1em;
}
table {
margin-left: 150px;
margin-right: auto;
}
</style>
<!-- JQUERY MOBILE -->
<!-- Include jQuery Mobile stylesheets -->
<!-- Include the jQuery library -->
<!-- <script src="http://code.jquery.com/jquery-1.11.3.min.js"></script> -->
<script src="./js/jquery/jquery-1.11.3.min.js"></script>
<script src="./js/jquery/init-mobile.js"></script>
<!-- Include the jQuery Mobile library -->
<!-- <script src="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script> -->
<script src="./js/jquery/jquery.mobile-1.4.5.min.js"></script>
<!-- JQUERY LOCAL
<script type="text/javascript" src="./js/jquery/jquery-2.0.3.min.js"></script>
-->
<script type="text/javascript" src="./js/angular/angular.js"></script>
<script type="text/javascript" src="./js/bootstrap/bootstrap.js"></script>
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
TeX: {
extensions: ["color.js"],
Macros: {
True: "\\mathit{True}",
RR: "{\\bf R}",
Int: "\\mathtt{Int}",
Nat: "\\mathtt{Nat}",
Zero: "\\mathtt{Zero}",
foo: ["{\\bf Jhala FOO #1}", 1],
kvar: ["{\\color[rgb]{1,0,0}{K_{#1}({#2})}}", 2],
bindx: ["{{#1}\\!:\\!{#2}}", 2],
reft: ["\\{\\bindx{#1}{#2} \\mid {#3}\\}", 3],
ereft: ["\\bindx{#1}{\\{#2 \\mid #3\\}}", 3],
reftx: ["\\{{#1}\\mid{#2}\\}", 2],
inferrule: ["\\frac{#2}{#3}\\;{#1}", 3]
}
}
});
</script>
<!-- GITHUB
<script src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"></script>
-->
<!-- LOCAL -->
<script src="js/MathJax-2.6.0/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"></script>
</head>
<body class="rustdoc" data-spy="scroll" data-target=".bs-docs-sidebar" ng-app="liquidDemo" ng-controller="LiquidDemoCtrl">
<div id="nav">
<button class="btn btn-xs btn-link actbutton firstbutton" type="button" style="font-size:15px; color:black; z-index:1">
<span class="glyphicon glyphicon-backward"></span>
</button>
<button class="btn btn-xs btn-link actbutton prevbutton" type="button" style="font-size:15px; color:black; z-index:1">
<span class="glyphicon glyphicon-chevron-left"></span>
</button>
<button id="toggle-nav" class="toggle-nav">
<span class="sr-only">Toggle navigation</span>
<span class="bar"></span>
<span class="bar"></span>
</button>
<button class="btn btn-xs btn-link actbutton nextbutton" type="button" style="font-size:15px; color:black; z-index:1">
<span class="glyphicon glyphicon-chevron-right"></span>
</button>
<button class="btn btn-xs btn-link actbutton lastbutton" type="button" style="font-size:15px; color:black; z-index:1">
<span class="glyphicon glyphicon-forward"></span>
</button>
</div>
<div id='toc' class='mobile-hidden'>
<ul class='chapter'>
<li><a href='01-intro.html'><b>1.</b>Follow Along at This URL</a></li>
<ul class='section'>
<li><a href='01-intro.html#whats-this'><b>1.1.</b> Whats this?</a></li>
<li><a href='01-intro.html#the-first-bug'><b>1.2.</b> The First <em>Bug</em></a></li>
<li><a href='01-intro.html#fast-forward-to-present-day'><b>1.3.</b> Fast forward to Present Day</a></li>
<li><a href='01-intro.html#fast-forward-to-present-day-1'><b>1.4.</b> Fast forward to Present Day</a></li>
<li><a href='01-intro.html#fast-forward-to-present-day-2'><b>1.5.</b> Fast forward to Present Day</a></li>
<li><a href='01-intro.html#programming-languages-research'><b>1.6.</b> Programming Languages Research</a></li>
<li><a href='01-intro.html#modern-languages'><b>1.7.</b> Modern Languages</a></li>
<li><a href='01-intro.html#modern-languages-1'><b>1.8.</b> Modern Languages</a></li>
<li><a href='01-intro.html#modern-languages-2'><b>1.9.</b> Modern Languages</a></li>
<li><a href='01-intro.html#modern-languages-3'><b>1.10.</b> Modern Languages?</a></li>
<li><a href='01-intro.html#well-typed-programs-can-go-very-wrong'><b>1.11.</b> Well-typed programs can go very wrong!</a></li>
<li><a href='01-intro.html#well-typed-programs-can-go-very-wrong-1'><b>1.12.</b> Well-typed programs can go very wrong!</a></li>
<li><a href='01-intro.html#well-typed-programs-can-go-very-wrong-2'><b>1.13.</b> Well-typed programs can go very wrong!</a></li>
<li><a href='01-intro.html#goal-language-integrated-verification'><b>1.14.</b> Goal: Language-Integrated Verification</a></li>
<li><a href='01-intro.html#goal-language-integrated-verification-1'><b>1.15.</b> Goal: Language-Integrated Verification</a></li>
<li><a href='01-intro.html#outline'><b>1.16.</b> Outline</a></li>
<li><a href='01-intro.html#outline-1'><b>1.17.</b> Outline</a></li>
<li><a href='01-intro.html#outline-2'><b>1.18.</b> Outline</a></li>
<li><a href='01-intro.html#outline-3'><b>1.19.</b> Outline</a></li>
<li><a href='01-intro.html#outline-4'><b>1.20.</b> Outline</a></li>
<li><a href='01-intro.html#outline-5'><b>1.21.</b> Outline</a></li>
</ul>
<li><a href='02-refinements.html'><b>2.</b>Simple Refinement Types</a></li>
<ul class='section'>
<li><a href='02-refinements.html#types'><b>2.1.</b> Types</a></li>
<li><a href='02-refinements.html#predicates'><b>2.2.</b> Predicates</a></li>
<li><a href='02-refinements.html#predicates-1'><b>2.3.</b> Predicates</a></li>
<li><a href='02-refinements.html#predicates-2'><b>2.4.</b> Predicates</a></li>
<li><a href='02-refinements.html#predicates-3'><b>2.5.</b> Predicates</a></li>
<li><a href='02-refinements.html#predicates-4'><b>2.6.</b> Predicates</a></li>
<li><a href='02-refinements.html#example-singletons'><b>2.7.</b> Example: Singletons</a></li>
<li><a href='02-refinements.html#example-natural-numbers'><b>2.8.</b> Example: Natural Numbers</a></li>
<li><a href='02-refinements.html#a-term-can-have-many-types'><b>2.9.</b> A Term Can Have <em>Many</em> Types</a></li>
<li><a href='02-refinements.html#predicate-subtyping-nuprl-pvs'><b>2.10.</b> 1. Predicate Subtyping <a href="http://pvs.csl.sri.com/papers/subtypes98/tse98.pdf">[NUPRL, PVS]</a></a></li>
<li><a href='02-refinements.html#predicate-subtyping-nuprl-pvs-1'><b>2.11.</b> 1. Predicate Subtyping <a href="http://pvs.csl.sri.com/papers/subtypes98/tse98.pdf">[NUPRL, PVS]</a></a></li>
<li><a href='02-refinements.html#predicate-subtyping-nuprl-pvs-2'><b>2.12.</b> 1. Predicate Subtyping <a href="http://pvs.csl.sri.com/papers/subtypes98/tse98.pdf">[NUPRL, PVS]</a></a></li>
<li><a href='02-refinements.html#example-natural-numbers-1'><b>2.13.</b> Example: Natural Numbers</a></li>
<li><a href='02-refinements.html#example-natural-numbers-2'><b>2.14.</b> Example: Natural Numbers</a></li>
<li><a href='02-refinements.html#typing-applications-function-calls'><b>2.15.</b> 2. Typing Applications (Function Calls)</a></li>
<li><a href='02-refinements.html#typing-applications-function-calls-1'><b>2.16.</b> 2. Typing Applications (Function Calls)</a></li>
<li><a href='02-refinements.html#typing-applications-function-calls-2'><b>2.17.</b> 2. Typing Applications (Function Calls)</a></li>
<li><a href='02-refinements.html#typing-applications-function-calls-3'><b>2.18.</b> 2. Typing Applications (Function Calls)</a></li>
<li><a href='02-refinements.html#recap-refinement-types-101'><b>2.19.</b> Recap: Refinement Types 101</a></li>
<li><a href='02-refinements.html#recap-refinement-types-101-1'><b>2.20.</b> Recap: Refinement Types 101</a></li>
<li><a href='02-refinements.html#recap-refinement-types-101-2'><b>2.21.</b> Recap: Refinement Types 101</a></li>
<li><a href='02-refinements.html#outline'><b>2.22.</b> Outline</a></li>
<li><a href='02-refinements.html#outline-1'><b>2.23.</b> Outline</a></li>
</ul>
<li><a href='03-examples.html'><b>3.</b>Refinement Types by Example</a></li>
<ul class='section'>
<li><a href='03-examples.html#refinement-types-by-example-1'><b>3.1.</b> Refinement Types by Example</a></li>
<li><a href='03-examples.html#refinement-types-by-example-2'><b>3.2.</b> Refinement Types by Example</a></li>
<li><a href='03-examples.html#refinement-types-by-example-3'><b>3.3.</b> Refinement Types by Example</a></li>
<li><a href='03-examples.html#specifications-pre-conditions'><b>3.4.</b> Specifications: Pre-Conditions</a></li>
<li><a href='03-examples.html#specifications-post-conditions'><b>3.5.</b> Specifications: Post-Conditions</a></li>
<li><a href='03-examples.html#refinement-types-by-example-4'><b>3.6.</b> Refinement Types by Example</a></li>
<li><a href='03-examples.html#verification-vector-sum'><b>3.7.</b> Verification: Vector Sum</a></li>
<li><a href='03-examples.html#verification-vector-sum-1'><b>3.8.</b> Verification: Vector Sum</a></li>
<li><a href='03-examples.html#verification-vector-sum-2'><b>3.9.</b> Verification: Vector Sum</a></li>
<li><a href='03-examples.html#refinement-types-by-example-5'><b>3.10.</b> Refinement Types by Example</a></li>
<li><a href='03-examples.html#inference'><b>3.11.</b> Inference</a></li>
<li><a href='03-examples.html#inference-vector-sum'><b>3.12.</b> Inference: Vector Sum</a></li>
<li><a href='03-examples.html#inference-vector-sum-1'><b>3.13.</b> Inference: Vector Sum</a></li>
<li><a href='03-examples.html#inference-vector-sum-2'><b>3.14.</b> Inference: Vector Sum</a></li>
<li><a href='03-examples.html#inference-vector-sum-3'><b>3.15.</b> Inference: Vector Sum</a></li>
<li><a href='03-examples.html#inference-vector-sum-4'><b>3.16.</b> Inference: Vector Sum</a></li>
<li><a href='03-examples.html#inference-vector-sum-5'><b>3.17.</b> Inference: Vector Sum</a></li>
<li><a href='03-examples.html#refinement-types-by-example-6'><b>3.18.</b> Refinement Types by Example</a></li>
<li><a href='03-examples.html#collections-higher-order-functions'><b>3.19.</b> Collections & Higher-Order Functions</a></li>
<li><a href='03-examples.html#collections-higher-order-functions-1'><b>3.20.</b> Collections & Higher-Order Functions</a></li>
<li><a href='03-examples.html#collections-higher-order-functions-2'><b>3.21.</b> Collections & Higher-Order Functions</a></li>
<li><a href='03-examples.html#collections-higher-order-functions-3'><b>3.22.</b> Collections & Higher-Order Functions</a></li>
<li><a href='03-examples.html#refinement-types-by-example-7'><b>3.23.</b> Refinement Types by Example</a></li>
<li><a href='03-examples.html#example-list-average'><b>3.24.</b> Example: List <code>average</code></a></li>
<li><a href='03-examples.html#refinements-for-datatypes'><b>3.25.</b> Refinements for Datatypes</a></li>
<li><a href='03-examples.html#measures-yield-refined-constructors'><b>3.26.</b> Measures Yield Refined Constructors</a></li>
<li><a href='03-examples.html#example-map-over-lists'><b>3.27.</b> Example: <code>map</code> over Lists</a></li>
<li><a href='03-examples.html#refinements-for-datatypes-1'><b>3.28.</b> Refinements for Datatypes</a></li>
<li><a href='03-examples.html#refinements-for-datatypes-2'><b>3.29.</b> Refinements for Datatypes</a></li>
<li><a href='03-examples.html#refinements-for-datatypes-3'><b>3.30.</b> Refinements for Datatypes</a></li>
<li><a href='03-examples.html#refinement-types-by-example-8'><b>3.31.</b> Refinement Types by Example</a></li>
<li><a href='03-examples.html#outline'><b>3.32.</b> Outline</a></li>
<li><a href='03-examples.html#outline-1'><b>3.33.</b> Outline</a></li>
</ul>
<li><a href='04-abstracting.html'><b>4.</b>Invariants In Constructors</a></li>
<ul class='section'>
<li><a href='04-abstracting.html#invariants-in-constructors-1'><b>4.1.</b> Invariants In Constructors</a></li>
<li><a href='04-abstracting.html#invariants-in-constructors-2'><b>4.2.</b> Invariants In Constructors</a></li>
<li><a href='04-abstracting.html#invariants-in-constructors-3'><b>4.3.</b> Invariants In Constructors</a></li>
<li><a href='04-abstracting.html#abstracting-refinements'><b>4.4.</b> Abstracting Refinements</a></li>
<li><a href='04-abstracting.html#abstracting-refinements-1'><b>4.5.</b> Abstracting Refinements</a></li>
<li><a href='04-abstracting.html#abstracting-refinements-2'><b>4.6.</b> Abstracting Refinements</a></li>
<li><a href='04-abstracting.html#using-abstract-refinements'><b>4.7.</b> Using Abstract Refinements</a></li>
<li><a href='04-abstracting.html#recap'><b>4.8.</b> Recap</a></li>
<li><a href='04-abstracting.html#recap-1'><b>4.9.</b> Recap</a></li>
<li><a href='04-abstracting.html#bounded-refinements-induction-as-a-type'><b>4.10.</b> Bounded Refinements: Induction as a Type</a></li>
<li><a href='04-abstracting.html#bounded-refinements-induction-as-a-type-1'><b>4.11.</b> Bounded Refinements: Induction as a Type</a></li>
<li><a href='04-abstracting.html#bounded-refinements-induction-as-a-type-2'><b>4.12.</b> Bounded Refinements: Induction as a Type</a></li>
<li><a href='04-abstracting.html#bounded-refinements-induction-as-a-type-3'><b>4.13.</b> Bounded Refinements: Induction as a Type</a></li>
</ul>
<li><a href='04-termination.html'><b>5.</b>Avoiding Infinite Loops</a></li>
<ul class='section'>
<li><a href='04-termination.html#example-proving-termination-of-sum'><b>5.1.</b> Example: Proving Termination of <code>sum</code></a></li>
<li><a href='04-termination.html#proving-termination'><b>5.2.</b> Proving Termination</a></li>
<li><a href='04-termination.html#proving-termination-1'><b>5.3.</b> Proving Termination</a></li>
<li><a href='04-termination.html#proving-termination-2'><b>5.4.</b> Proving Termination</a></li>
<li><a href='04-termination.html#proving-termination-3'><b>5.5.</b> Proving Termination</a></li>
<li><a href='04-termination.html#example-proving-termination-of-sum-1'><b>5.6.</b> Example: Proving Termination of <code>sum</code></a></li>
<li><a href='04-termination.html#user-specified-termination-metrics'><b>5.7.</b> User Specified Termination Metrics</a></li>
<li><a href='04-termination.html#user-specified-termination-metrics-1'><b>5.8.</b> User Specified Termination Metrics</a></li>
<li><a href='04-termination.html#user-specified-termination-metrics-2'><b>5.9.</b> User Specified Termination Metrics</a></li>
<li><a href='04-termination.html#proving-termination-4'><b>5.10.</b> Proving Termination</a></li>
<li><a href='04-termination.html#lexicographic-termination'><b>5.11.</b> Lexicographic Termination</a></li>
<li><a href='04-termination.html#how-about-data-types'><b>5.12.</b> How About Data Types?</a></li>
<li><a href='04-termination.html#user-specified-metrics-on-data-types'><b>5.13.</b> User specified metrics on Data Types</a></li>
<li><a href='04-termination.html#termination-can-be-tricky'><b>5.14.</b> Termination Can be Tricky</a></li>
<li><a href='04-termination.html#avoiding-infinite-loops-1'><b>5.15.</b> Avoiding Infinite Loops</a></li>
<li><a href='04-termination.html#avoiding-infinite-loops-2'><b>5.16.</b> Avoiding Infinite Loops</a></li>
<li><a href='04-termination.html#avoiding-infinite-loops-3'><b>5.17.</b> Avoiding Infinite Loops</a></li>
<li><a href='04-termination.html#avoiding-infinite-loops-4'><b>5.18.</b> Avoiding Infinite Loops</a></li>
<li><a href='04-termination.html#avoiding-infinite-loops-is-easy-in-practice'><b>5.19.</b> Avoiding Infinite Loops is Easy (in Practice)</a></li>
<li><a href='04-termination.html#avoiding-infinite-loops-is-easy-in-practice-1'><b>5.20.</b> Avoiding Infinite Loops is Easy (in Practice)</a></li>
<li><a href='04-termination.html#avoiding-infinite-loops-is-easy-in-practice-2'><b>5.21.</b> Avoiding Infinite Loops is Easy (in Practice)</a></li>
<li><a href='04-termination.html#avoiding-infinite-loops-is-easy-in-practice-3'><b>5.22.</b> Avoiding Infinite Loops is Easy (in Practice)</a></li>
<li><a href='04-termination.html#outline'><b>5.23.</b> Outline</a></li>
<li><a href='04-termination.html#outline-1'><b>5.24.</b> Outline</a></li>
</ul>
<li><a href='05-reflection.html'><b>6.</b>Types as Theorems, Programs as Proofs</a></li>
<ul class='section'>
<li><a href='05-reflection.html#types-as-theorems'><b>6.1.</b> Types As Theorems</a></li>
<li><a href='05-reflection.html#types-as-theorems-example'><b>6.2.</b> Types as Theorems: Example</a></li>
<li><a href='05-reflection.html#programs-as-proofs-example'><b>6.3.</b> Programs As Proofs: Example</a></li>
<li><a href='05-reflection.html#types-as-theorems-1'><b>6.4.</b> Types As Theorems</a></li>
<li><a href='05-reflection.html#types-as-theorems-example-1'><b>6.5.</b> Types as Theorems: Example</a></li>
<li><a href='05-reflection.html#programs-as-proofs-example-1'><b>6.6.</b> Programs As Proofs: Example</a></li>
<li><a href='05-reflection.html#types-as-theorems-programs-as-proofs-1'><b>6.7.</b> Types as Theorems, Programs as Proofs</a></li>
<li><a href='05-reflection.html#those-proofs-were-boring'><b>6.8.</b> Those Proofs were Boring</a></li>
<li><a href='05-reflection.html#those-proofs-were-boring-1'><b>6.9.</b> Those Proofs were Boring</a></li>
<li><a href='05-reflection.html#theorems-about-functions'><b>6.10.</b> Theorems about Functions</a></li>
<li><a href='05-reflection.html#refinement-reflection'><b>6.11.</b> Refinement Reflection</a></li>
<li><a href='05-reflection.html#reflect-function-into-output-type'><b>6.12.</b> Reflect Function into Output Type</a></li>
<li><a href='05-reflection.html#reflect-function-into-output-type-1'><b>6.13.</b> Reflect Function into Output Type</a></li>
<li><a href='05-reflection.html#reflection-at-result-type'><b>6.14.</b> Reflection at Result Type</a></li>
<li><a href='05-reflection.html#structuring-proofs-as-calculations'><b>6.15.</b> Structuring Proofs as Calculations</a></li>
<li><a href='05-reflection.html#types-as-theorems-programs-as-proofs-2'><b>6.16.</b> Types as Theorems, Programs as Proofs</a></li>
<li><a href='05-reflection.html#reusing-proofs-functions-as-lemmas'><b>6.17.</b> Reusing Proofs: Functions as Lemmas</a></li>
<li><a href='05-reflection.html#reusing-proofs-functions-as-lemmas-1'><b>6.18.</b> Reusing Proofs: Functions as Lemmas</a></li>
<li><a href='05-reflection.html#reusing-proofs-functions-as-lemmas-2'><b>6.19.</b> Reusing Proofs: Functions as Lemmas</a></li>
<li><a href='05-reflection.html#types-as-theorems-programs-as-proofs-3'><b>6.20.</b> Types as Theorems, Programs as Proofs</a></li>
<li><a href='05-reflection.html#types-as-theorems-programs-as-proofs-4'><b>6.21.</b> Types as Theorems, Programs as Proofs</a></li>
<li><a href='05-reflection.html#proof-by-logical-evaluation'><b>6.22.</b> Proof by Logical Evaluation</a></li>
<li><a href='05-reflection.html#proof-by-logical-evaluation-1'><b>6.23.</b> Proof by Logical Evaluation</a></li>
<li><a href='05-reflection.html#proof-by-logical-evaluation-2'><b>6.24.</b> Proof by Logical Evaluation</a></li>
<li><a href='05-reflection.html#proof-by-induction'><b>6.25.</b> Proof by Induction</a></li>
<li><a href='05-reflection.html#proof-by-induction-1'><b>6.26.</b> Proof by Induction</a></li>
<li><a href='05-reflection.html#proof-by-induction-2'><b>6.27.</b> Proof by Induction</a></li>
<li><a href='05-reflection.html#types-as-theorems-programs-as-proofs-5'><b>6.28.</b> Types as Theorems, Programs as Proofs</a></li>
<li><a href='05-reflection.html#types-as-theorems-programs-as-proofs-6'><b>6.29.</b> Types as Theorems, Programs as Proofs</a></li>
<li><a href='05-reflection.html#types-as-theorems-programs-as-proofs-7'><b>6.30.</b> Types as Theorems, Programs as Proofs</a></li>
<li><a href='05-reflection.html#theorems-about-data'><b>6.31.</b> Theorems about Data</a></li>
<li><a href='05-reflection.html#theorems-about-data-associativity-of-append'><b>6.32.</b> Theorems about Data: Associativity of <code>append</code></a></li>
<li><a href='05-reflection.html#case-study-mapreduce'><b>6.33.</b> Case Study: MapReduce</a></li>
<li><a href='05-reflection.html#case-study-mapreduce-1'><b>6.34.</b> Case Study: MapReduce</a></li>
<li><a href='05-reflection.html#reduce-theorem'><b>6.35.</b> Reduce Theorem</a></li>
<li><a href='05-reflection.html#types-as-theorems-programs-as-proofs-8'><b>6.36.</b> Types as Theorems, Programs as Proofs</a></li>
<li><a href='05-reflection.html#outline'><b>6.37.</b> Outline</a></li>
<li><a href='05-reflection.html#outline-1'><b>6.38.</b> Outline</a></li>
</ul>
<li><a href='06-concl.html'><b>7.</b>LiquidHaskell</a></li>
<ul class='section'>
<li><a href='06-concl.html#liquidhaskell-1'><b>7.1.</b> LiquidHaskell</a></li>
<li><a href='06-concl.html#liquidhaskell-2'><b>7.2.</b> LiquidHaskell</a></li>
<li><a href='06-concl.html#evaluation'><b>7.3.</b> Evaluation</a></li>
<li><a href='06-concl.html#recap-refinement-types'><b>7.4.</b> Recap: Refinement Types</a></li>
<li><a href='06-concl.html#recap-refinement-types-1'><b>7.5.</b> Recap: Refinement Types</a></li>
<li><a href='06-concl.html#recap-refinement-types-2'><b>7.6.</b> Recap: Refinement Types</a></li>
<li><a href='06-concl.html#recap-refinement-types-3'><b>7.7.</b> Recap: Refinement Types</a></li>
<li><a href='06-concl.html#many-friends-many-directions'><b>7.8.</b> Many Friends, Many Directions</a></li>
<li><a href='06-concl.html#thank-you'><b>7.9.</b> Thank You!</a></li>
</ul>
</ul>
</div>
<div id="checker-status">
<!-- Verifying ... -->
<button class="btn btn-xs btn-link actbutton" type="button" style="font-size:30px; z-index:1"
ng-show="isChecking" ng-click="verifySource()">
<span class="glyphicon glyphicon-hourglass"></span>
</button>
<!-- Safe -->
<button class="btn btn-xs btn-link actbutton" type="button" style="font-size:30px; color:green; z-index:1"
ng-show="isSafe">
<span class="glyphicon glyphicon-ok"></span>
</button>
<div class="dropdown" ng-show="isBad">
<button class="btn btn-xs btn-link dropdown-toggle"
type="button"
id="errorblockdropdown"
data-toggle="dropdown"
style="font-size:30px; color:red; z-index:1">
<span class="glyphicon glyphicon-remove" style="vertical-align:middle"></span><font size="4">{{errorBlocks.length}}</font>
</span>
</button>
<ul class="dropdown-menu" role="menu" aria-labelledby="dLabel">
<li ng-repeat="err in errorBlocks">
<a tabindex="-1" ng-click="jumpToProgPane(err)">{{err.index}}</a>
</li>
</ul>
</div>
</div>
<div id='page-wrapper'>
<div id='page'>
<div class="hidden">
<div id="program-pane-0" class="welleditor" style="background:#fff; position:relative">
<!-- Verify Source -->
<button class="btn btn-xs btn-link actbutton" type="button" style="z-index:1"
ng-show="isUnknown" ng-click="verifySource()">
<span class="glyphicon glyphicon-play"></span>
</button>
<div id="program-0" class="programbox">{-@ LIQUID "--no-termination" @-}
{-@ LIQUID "--diff" @-}
{-@ LIQUID "--short-names" @-}
module SimpleRefinements where
import Prelude hiding (abs, max)
zero, zero', zero'', four, four' :: Int
nats :: [Int]
-- zero' :: Int
-- safeDiv :: Int -> Int -> Int
-- size, size' :: [a] -> Int</div>
</div>
</div>
<div id="slide-0" class="slide">
<h2 id="simple-refinement-types">Simple Refinement Types</h2>
<p><br></p>
<p>Refinement Types = <strong>Types</strong> + <strong>Predicates</strong></p>
</div>
<div id="slide-1" class="slide">
<h2 id="types">Types</h2>
<hr style="height:5px; visibility:hidden;" />
<pre class="spec"><code>b := Int | Bool | ... -- primitives
| a, b, c -- type variables
</code></pre>
<pre class="spec"><code>t := {x:b | p} -- refined base
| x:t -> t -- refined function
</code></pre>
<p><code>p</code> is a predicate from a <strong>decidable logic</strong></p>
</div>
<div id="slide-2" class="slide">
<h2 id="predicates">Predicates</h2>
<p><strong>Quantifier-Free Logic of Uninterpreted Functions & Linear Arithmetic</strong></p>
</div>
<div id="slide-3" class="slide">
<h2 id="predicates-1">Predicates</h2>
<p><strong>Quantifier-Free Logic of Uninterpreted Functions & Linear Arithmetic</strong></p>
<pre class="spec"><code>e := x, y, z, ... -- variables
| 0, 1, 2, ... -- constants
| e + e | c * e | ... -- arithmetic
| f e1 ... en -- uninterpreted function
</code></pre>
</div>
<div id="slide-4" class="slide">
<h2 id="predicates-2">Predicates</h2>
<p><strong>Quantifier-Free Logic of Uninterpreted Functions & Linear Arithmetic</strong></p>
<pre class="spec"><code>e := x, y, z, ... -- variables
| 0, 1, 2, ... -- constants
| e + e | c * e | ... -- arithmetic
| f e1 ... en -- uninterpreted function
</code></pre>
<p><strong>Uninterpreted Functions</strong></p>
<p><span class="math display">\[\forall \overline{x}, \overline{y}.\ \overline{x} = \overline{y}\ \Rightarrow\ f(x) = f(y)\]</span></p>
</div>
<div id="slide-5" class="slide">
<h2 id="predicates-3">Predicates</h2>
<p><strong>Quantifier-Free Logic of Uninterpreted Functions & Linear Arithmetic</strong></p>
<pre class="spec"><code>e := x, y, z, ... -- variables
| 0, 1, 2, ... -- constants
| e + e | c * e | ... -- arithmetic
| f e1 ... en -- uninterpreted function
</code></pre>
<pre class="spec"><code>p := e <= e | ... -- atoms
| p && p | p || p | !p -- boolean combinations
</code></pre>
</div>
<div id="slide-6" class="slide">
<h2 id="predicates-4">Predicates</h2>
<p>Quantifier-Free Logic of Uninterpreted Functions & Linear Arithmetic</p>
<p><br></p>
<p>Given a <strong>Verification Condition</strong> (VC)</p>
<p><span class="math display">\[p_1 \Rightarrow p_2\]</span></p>
<p>SMT solvers can <strong>decide if VC is Valid</strong> ("always true")</p>
</div>
<div id="slide-7" class="slide">
<h2 id="example-singletons">Example: Singletons</h2>
<hr style="height:5px; visibility:hidden;" />
<div id="program-pane-1" class="welleditor" style="background:#fff; position:relative">
<!-- Verify Source -->
<button class="btn btn-xs btn-link actbutton" type="button" style="z-index:1"
ng-show="isUnknown" ng-click="verifySource()">
<span class="glyphicon glyphicon-play"></span>
</button>
<div id="program-1" class="programbox">{-@ type Zero = {v:Int | v == 0} @-}
{-@ zero :: Zero @-}
zero = 0</div>
</div>
<p>Refinement types via special comments <code>{-@ ... @-}</code></p>
</div>
<div id="slide-8" class="slide">
<h2 id="example-natural-numbers">Example: Natural Numbers</h2>
<hr style="height:5px; visibility:hidden;" />
<div id="program-pane-2" class="welleditor" style="background:#fff; position:relative">
<!-- Verify Source -->
<button class="btn btn-xs btn-link actbutton" type="button" style="z-index:1"
ng-show="isUnknown" ng-click="verifySource()">
<span class="glyphicon glyphicon-play"></span>
</button>
<div id="program-2" class="programbox">{-@ type Nat = {v:Int | 0 <= v} @-}
{-@ nats :: [Nat] @-}
nats = [0, 1, 2, 3]</div>
</div>
</div>
<div id="slide-9" class="slide">
<h2 id="a-term-can-have-many-types">A Term Can Have <em>Many</em> Types</h2>
<div class="mybreak">
<br>
</div>
<p>What <em>is</em> the type of <code>0</code> ?</p>
<div class="mybreak">
<br>
</div>
<div id="program-pane-3" class="welleditor" style="background:#fff; position:relative">
<!-- Verify Source -->
<button class="btn btn-xs btn-link actbutton" type="button" style="z-index:1"
ng-show="isUnknown" ng-click="verifySource()">
<span class="glyphicon glyphicon-play"></span>
</button>
<div id="program-3" class="programbox">{-@ zero' :: Nat @-}
zero' = zero</div>
</div>
</div>
<div id="slide-10" class="slide">
<h2 id="predicate-subtyping-nuprl-pvs">1. Predicate Subtyping <a href="http://pvs.csl.sri.com/papers/subtypes98/tse98.pdf">[NUPRL, PVS]</a></h2>
<div class="mybreak">
<br>
</div>
<p>In <strong>environment</strong> <span class="math inline">\(\Gamma\)</span> the type <span class="math inline">\(t_1\)</span> is a <strong>subtype</strong> of <span class="math inline">\(t_2\)</span></p>
<p><span class="math display">\[\boxed{\Gamma \vdash t_1 \preceq t_2}\]</span></p>
</div>
<div id="slide-11" class="slide">
<h2 id="predicate-subtyping-nuprl-pvs-1">1. Predicate Subtyping <a href="http://pvs.csl.sri.com/papers/subtypes98/tse98.pdf">[NUPRL, PVS]</a></h2>
<div class="mybreak">
<br>
</div>
<p>In <strong>environment</strong> <span class="math inline">\(\Gamma\)</span> the type <span class="math inline">\(t_1\)</span> is a <strong>subtype</strong> of <span class="math inline">\(t_2\)</span></p>
<p><span class="math display">\[\boxed{\Gamma \vdash t_1 \preceq t_2}\]</span></p>
<div class="mybreak">
<br>
</div>
<p>Where <strong>environment</strong> <span class="math inline">\(\Gamma\)</span> is a sequence of <em>in-scope binders</em></p>
<p><span class="math display">\[\Gamma \doteq \overline{\bindx{x_i}{P_i}}\]</span></p>
</div>
<div id="slide-12" class="slide">
<h2 id="predicate-subtyping-nuprl-pvs-2">1. Predicate Subtyping <a href="http://pvs.csl.sri.com/papers/subtypes98/tse98.pdf">[NUPRL, PVS]</a></h2>
<div class="mybreak">
<br>
</div>
<p>In <strong>environment</strong> <span class="math inline">\(\Gamma\)</span> the type <span class="math inline">\(t_1\)</span> is a <strong>subtype</strong> of <span class="math inline">\(t_2\)</span></p>
<p><span class="math display">\[\boxed{\Gamma \vdash t_1 \preceq t_2}\]</span></p>
<div class="mybreak">
<br>
</div>
<p><span class="math display">\[
\begin{array}{rll}
{\mathbf{If\ VC\ is\ Valid}} & \bigwedge_i p_i \Rightarrow q \Rightarrow r & (\mbox{By SMT}) \\
& & \\
{\mathbf{Then}} & \overline{\bindx{x_i}{p_i}} \vdash \reft{v}{b}{q} \preceq \reft{v}{b}{r} & \\
\end{array}
\]</span></p>
</div>
<div id="slide-13" class="slide">
<h2 id="example-natural-numbers-1">Example: Natural Numbers</h2>
<div class="mybreak">
<br>
</div>
<p><span class="math display">\[
\begin{array}{rcrccll}
\mathbf{VC\ is\ Valid:} & \True & \Rightarrow & v = 0 & \Rightarrow & 0 \leq v & \mbox{(by SMT)} \\
\mathbf{So:} & \emptyset & \vdash & \Zero & \preceq & \Nat & \\
\end{array}
\]</span></p>
</div>
<div id="slide-14" class="slide">
<h2 id="example-natural-numbers-2">Example: Natural Numbers</h2>
<div class="mybreak">
<br>
</div>
<p><span class="math display">\[
\begin{array}{rcrccll}
\mathbf{VC\ is\ Valid:} & \True & \Rightarrow & v = 0 & \Rightarrow & 0 \leq v & \mbox{(by SMT)} \\
\mathbf{So:} & \emptyset & \vdash & \Zero & \preceq & \Nat & \\
\end{array}
\]</span></p>
<div class="mybreak">
<br>
</div>
<p>And so, we can type:</p>
<div id="program-pane-4" class="welleditor" style="background:#fff; position:relative">
<!-- Verify Source -->
<button class="btn btn-xs btn-link actbutton" type="button" style="z-index:1"
ng-show="isUnknown" ng-click="verifySource()">
<span class="glyphicon glyphicon-play"></span>
</button>
<div id="program-4" class="programbox">{-@ zero'' :: Nat @-}
zero'' = 0 -- as |- Zero <: Nat</div>
</div>
</div>
<div id="slide-15" class="slide">
<h2 id="typing-applications-function-calls">2. Typing Applications (Function Calls)</h2>
<div class="mybreak">
<br>
</div>
<p>Terms built up by applications.</p>
<div class="mybreak">
<br>
</div>
<div id="program-pane-5" class="welleditor" style="background:#fff; position:relative">
<!-- Verify Source -->
<button class="btn btn-xs btn-link actbutton" type="button" style="z-index:1"
ng-show="isUnknown" ng-click="verifySource()">
<span class="glyphicon glyphicon-play"></span>
</button>
<div id="program-5" class="programbox">{-@ four :: Nat @-}
four = x + 1
where
x = 3</div>
</div>
<div class="mybreak">
<br>
</div>
<p><em>How to prove</em> <code>four :: Nat</code> ?</p>
</div>
<div id="slide-16" class="slide">
<h2 id="typing-applications-function-calls-1">2. Typing Applications (Function Calls)</h2>
<div class="mybreak">
<br>
</div>
<p><strong>Dependent Application</strong></p>
<div class="mybreak">
<br>
</div>
<p><span class="math display">\[\begin{array}{rl}
{\mathbf{If}} & \Gamma \vdash f :: \bindx{x}{s} \rightarrow t \\
& \Gamma \vdash y :: s \\
{\mathbf{Then}} & \Gamma \vdash f\ y :: t[x \mapsto y] \\
\end{array}\]</span></p>
<div class="mybreak">
<br>
</div>
<p>i.e. Output type with <em>formals substituted by actuals</em></p>
</div>
<div id="slide-17" class="slide">
<h2 id="typing-applications-function-calls-2">2. Typing Applications (Function Calls)</h2>
<div class="mybreak">
<br>
</div>
<p><strong>Dependent Application: Example</strong></p>
<div class="mybreak">
<br>
</div>
<p><span class="math display">\[
\begin{array}{rl}
{\mathbf{If}} & \Gamma \vdash (+) :: \bindx{a}{\Int} \rightarrow
\bindx{b}{\Int} \rightarrow
\reft{v}{\Int}{v = a + b} \\
& \Gamma \vdash x :: \Int \\
& \Gamma \vdash 1 :: \Int \\
& \\
{\mathbf{Then}} & \Gamma \vdash x + 1 :: \reft{v}{\Int}{v = x + 1}
\end{array}
\]</span></p>
</div>
<div id="slide-18" class="slide">
<h2 id="typing-applications-function-calls-3">2. Typing Applications (Function Calls)</h2>
<div class="mybreak">
<br>
</div>
<p>And so, we can type:</p>
<div class="mybreak">
<br>
</div>
<div id="program-pane-6" class="welleditor" style="background:#fff; position:relative">
<!-- Verify Source -->
<button class="btn btn-xs btn-link actbutton" type="button" style="z-index:1"
ng-show="isUnknown" ng-click="verifySource()">
<span class="glyphicon glyphicon-play"></span>
</button>
<div id="program-6" class="programbox">{-@ four' :: Nat @-}
four' = x + 1 -- x = 3 |- {v = x+1} <: Nat
where -- as
x = 3 -- x = 3 => v = x+1 => 0 <= v</div>
</div>
</div>
<div id="slide-19" class="slide">
<h2 id="recap-refinement-types-101">Recap: Refinement Types 101</h2>
<div class="mybreak">
<br>
</div>
<p><strong>Refinement Types</strong></p>
<p>Types + Predicates</p>
</div>
<div id="slide-20" class="slide">
<h2 id="recap-refinement-types-101-1">Recap: Refinement Types 101</h2>
<div class="mybreak">
<br>
</div>
<p><strong>Refinement Types</strong></p>
<p>Types + Predicates</p>
<div class="mybreak">
<br>
</div>
<p><strong>Refinement Checking</strong></p>
<p>Dependent Application + Predicate Subtyping</p>
</div>
<div id="slide-21" class="slide">
<h2 id="recap-refinement-types-101-2">Recap: Refinement Types 101</h2>
<div class="mybreak">
<br>
</div>
<p><strong>Refinement Types</strong></p>
<p>Types + Predicates</p>
<div class="mybreak">
<br>
</div>
<p><strong>Refinement Checking</strong></p>
<p>Dependent Application + Predicate Subtyping</p>
<div class="mybreak">
<br>
</div>
<p><strong><a href="03-examples.html">[Eliminates boring proofs & Makes Verification Practical]</a></strong></p>
</div>
<div id="slide-22" class="slide">
<h2 id="outline">Outline</h2>
<p><br></p>
<p><a href="01-intro.html">Motivation</a></p>
<p><a href="02-refinements.html">Refinements 101</a></p>
</div>
<div id="slide-23" class="slide">
<h2 id="outline-1">Outline</h2>
<p><br></p>
<p><a href="01-intro.html">Motivation</a></p>
<p><a href="02-refinements.html">Refinements 101</a></p>
<p><a href="03-examples.html">Refinements by Example</a></p>
</div>
</div>
</div>
<!--Site Meter
<div class="hidden">
<script type="text/javascript" src="http://s23.sitemeter.com/js/counter.js?site=s23liquidtypes"></script>
<noscript>
<a href="http://s23.sitemeter.com/stats.asp?site=s23liquidtypes"
target="_top">
<img src="http://s23.sitemeter.com/meter.asp?site=s23liquidtypes"
alt="Site Meter" border="0"/></a>
</noscript>
</div>
-->
<!-- JavaScript below! ============================================== -->
<script src="./js/ace/ace.js" type="text/javascript" charset="utf-8"></script>
<script src="./js/ace/theme-monokai.js" type="text/javascript" charset="utf-8"></script>
<script src="./js/ace/mode-haskell.js" type="text/javascript" charset="utf-8"></script>
<script src="./js/liquid/tooltip.js"></script>
<script src="./js/liquid/annot.js"></script>
<script src="./js/liquid/config.js"></script>
<script src="./js/liquid/slideshow.js"></script>
<script src="./js/liquid/liquid.js"></script>
<script type="text/javascript">
var queryServerURL = "http://goto.ucsd.edu:8090/" ;
</script>
<!-- rust nav JS -->
<script type="text/javascript">
window.playgroundUrl = "";
</script>
<script type="text/javascript">
document.addEventListener("DOMContentLoaded", function(event) {
document.getElementById("toggle-nav").onclick = toggleNav;
function toggleNav() {
var toc = document.getElementById("toc");
var pagewrapper = document.getElementById("page-wrapper");
var status = document.getElementById("checker-status");
toggleClass(toc, "mobile-hidden");
// toggleClass(status, "mobile-hidden");
toggleClass(pagewrapper, "mobile-hidden");
};
function toggleClass(el, className) {
// from http://youmightnotneedjquery.com/
if (el.classList) {
el.classList.toggle(className);
} else {
var classes = el.className.split(' ');
var existingIndex = classes.indexOf(className);
if (existingIndex >= 0) {
classes.splice(existingIndex, 1);
} else {
classes.push(className);
}
el.className = classes.join(' ');
}
}
});
</script>
</body>
</html>