没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
Certified Programming with Dependent Types
Adam Chlipala
November 21, 2014
A print version of this book is available from the MIT Press. For more information, see
the book’s home page:
http://adam.chlipala.net/cpdt/
Copyright Adam Chlipala 2008-2013.
This work is licensed under a Creative Commons Attribution-Noncommercial-No
Derivative Works 3.0 Unported License. The license text is available at:
http://creativecommons.org/licenses/by-nc-nd/3.0/
Contents
1 Introduction 6
1.1 Whence This Book? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
1.2 Why Coq? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
1.2.1 Based on a Higher-Order Functional Programming Language . . . . . 8
1.2.2 Dependent Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
1.2.3 An Easy-to-Check Kernel Proof Language . . . . . . . . . . . . . . . 9
1.2.4 Convenient Programmable Proof Automation . . . . . . . . . . . . . 9
1.2.5 Proof by Reflection . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
1.3 Why Not a Different Dependently Typed Language? . . . . . . . . . . . . . 10
1.4 Engineering with a Proof Assistant . . . . . . . . . . . . . . . . . . . . . . . 11
1.5 Prerequisites . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
1.6 Using This Book . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
1.6.1 Reading This Book . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
1.6.2 On the Tactic Library . . . . . . . . . . . . . . . . . . . . . . . . . . 14
1.6.3 Installation and Emacs Set-Up . . . . . . . . . . . . . . . . . . . . . . 14
1.7 Chapter Source Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
2 Some Quick Examples 17
2.1 Arithmetic Expressions Over Natural Numbers . . . . . . . . . . . . . . . . . 17
2.1.1 Source Language . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
2.1.2 Target Language . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
2.1.3 Translation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
2.1.4 Translation Correctness . . . . . . . . . . . . . . . . . . . . . . . . . 22
2.2 Typed Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
2.2.1 Source Language . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
2.2.2 Target Language . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
2.2.3 Translation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
2.2.4 Translation Correctness . . . . . . . . . . . . . . . . . . . . . . . . . 36
I Basic Programming and Proving 39
3 Introducing Inductive Types 40
2
3.1 Proof Terms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
3.2 Enumerations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
3.3 Simple Recursive Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
3.4 Parameterized Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
3.5 Mutually Inductive Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
3.6 Reflexive Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
3.7 An Interlude on Induction Principles . . . . . . . . . . . . . . . . . . . . . . 56
3.8 Nested Inductive Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
3.9 Manual Proofs About Constructors . . . . . . . . . . . . . . . . . . . . . . . 65
4 Inductive Predicates 68
4.1 Propositional Logic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
4.2 What Does It Mean to Be Constructive? . . . . . . . . . . . . . . . . . . . . 74
4.3 First-Order Logic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
4.4 Predicates with Implicit Equality . . . . . . . . . . . . . . . . . . . . . . . . 76
4.5 Recursive Predicates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
5 Infinite Data and Proofs 86
5.1 Computing with Infinite Data . . . . . . . . . . . . . . . . . . . . . . . . . . 87
5.2 Infinite Proofs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
5.3 Simple Modeling of Non-Terminating Programs . . . . . . . . . . . . . . . . 98
II Programming with Dependent Types 102
6 Subset Types and Variations 103
6.1 Introducing Subset Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
6.2 Decidable Proposition Types . . . . . . . . . . . . . . . . . . . . . . . . . . . 110
6.3 Partial Subset Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113
6.4 Monadic Notations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115
6.5 A Type-Checking Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116
7 General Recursion 121
7.1 Well-Founded Recursion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122
7.2 A Non-Termination Monad Inspired by Domain Theory . . . . . . . . . . . . 128
7.3 Co-Inductive Non-Termination Monads . . . . . . . . . . . . . . . . . . . . . 133
7.4 Comparing the Alternatives . . . . . . . . . . . . . . . . . . . . . . . . . . . 137
8 More Dependent Types 139
8.1 Length-Indexed Lists . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139
8.2 The One Rule of Dependent Pattern Matching in Coq . . . . . . . . . . . . . 143
8.3 A Tagless Interpreter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144
8.4 Dependently Typed Red-Black Trees . . . . . . . . . . . . . . . . . . . . . . 150
8.5 A Certified Regular Expression Matcher . . . . . . . . . . . . . . . . . . . . 159
3
9 Dependent Data Structures 165
9.1 More Length-Indexed Lists . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165
9.2 Heterogeneous Lists . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 169
9.2.1 A Lambda Calculus Interpreter . . . . . . . . . . . . . . . . . . . . . 171
9.3 Recursive Type Definitions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173
9.4 Data Structures as Index Functions . . . . . . . . . . . . . . . . . . . . . . . 175
9.4.1 Another Interpreter Example . . . . . . . . . . . . . . . . . . . . . . 179
9.5 Choosing Between Representations . . . . . . . . . . . . . . . . . . . . . . . 183
10 Reasoning About Equality Proofs 185
10.1 The Definitional Equality . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185
10.2 Heterogeneous Lists Revisited . . . . . . . . . . . . . . . . . . . . . . . . . . 189
10.3 Type-Casts in Theorem Statements . . . . . . . . . . . . . . . . . . . . . . . 194
10.4 Heterogeneous Equality . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 199
10.5 Equivalence of Equality Axioms . . . . . . . . . . . . . . . . . . . . . . . . . 204
10.6 Equality of Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 205
11 Generic Programming 208
11.1 Reifying Datatype Definitions . . . . . . . . . . . . . . . . . . . . . . . . . . 208
11.2 Recursive Definitions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 210
11.2.1 Pretty-Printing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 213
11.2.2 Mapping . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 216
11.3 Proving Theorems about Recursive Definitions . . . . . . . . . . . . . . . . . 217
12 Universes and Axioms 224
12.1 The Type Hierarchy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 224
12.1.1 Inductive Definitions . . . . . . . . . . . . . . . . . . . . . . . . . . . 227
12.1.2 Deciphering Baffling Messages About Inability to Unify . . . . . . . . 231
12.2 The Prop Universe . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 233
12.3 Axioms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 236
12.3.1 The Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 237
12.3.2 Axioms of Choice . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 241
12.3.3 Axioms and Computation . . . . . . . . . . . . . . . . . . . . . . . . 243
12.3.4 Methods for Avoiding Axioms . . . . . . . . . . . . . . . . . . . . . . 244
III Proof Engineering 253
13 Proof Search by Logic Programming 254
13.1 Introducing Logic Programming . . . . . . . . . . . . . . . . . . . . . . . . . 254
13.2 Searching for Underconstrained Values . . . . . . . . . . . . . . . . . . . . . 261
13.3 Synthesizing Programs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 264
13.4 More on auto Hints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 268
4
剩余370页未读,继续阅读
资源评论
jiangdmdr
- 粉丝: 57
- 资源: 774
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 基于matlab实现的二进制相移键控仿真的源程序,用于对PSK信号进行仿真.rar
- top-hat.zip
- 基于matlab实现的图像增强与去噪.rar
- FEproject (1).ipynb
- 基于matlab实现的维纳滤波对图像去噪与最小二乘方滤波对图像去噪的比较.rar
- 基于matlab实现的维也纳大学的LTE链路级仿真平台,实现了LTE两路及仿真的整个个过程.rar
- 基于matlab实现的维也纳大学的LTE上行链路仿真平台 LTE-Link-Level-Uplink-1.0.rar
- morphological-gradient.zip
- 爱立信5G小包优化功能验证.docx
- 基于matlab实现的相移光纤光栅,均匀光栅,啁啾光栅源程序 在均匀光栅中间引入一个相移点,得到反射谱.rar
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功