Lambda Calculus

330
Lambda calculus From Wikipedia, the free encyclopedia

description

1. From Wikipedia, the free encyclopedia2. Lexicographical order

Transcript of Lambda Calculus

  • Lambda calculusFrom Wikipedia, the free encyclopedia

  • Contents

    1 Abstraction (computer science) 11.1 Rationale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11.2 Language features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2

    1.2.1 Programming languages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21.2.2 Specication methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21.2.3 Specication languages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3

    1.3 Control abstraction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31.3.1 Structured programming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3

    1.4 Data abstraction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41.5 Abstraction in object oriented programming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4

    1.5.1 Object-oriented design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51.6 Considerations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51.7 Levels of abstraction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6

    1.7.1 Database systems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61.7.2 Layered architecture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7

    1.8 See also . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71.9 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81.10 Further reading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81.11 External links . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8

    2 Algebraic normal form 92.1 Common uses . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92.2 Performing operations within algebraic normal form . . . . . . . . . . . . . . . . . . . . . . . . . 92.3 Converting to algebraic normal form . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102.4 Formal representation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10

    2.4.1 Recursively deriving multiargument Boolean functions . . . . . . . . . . . . . . . . . . . 112.5 See also . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112.6 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11

    3 Alonzo Church 123.1 Life . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123.2 Mathematical work . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123.3 Students . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13

    i

  • ii CONTENTS

    3.4 Books . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133.5 See also . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133.6 Notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133.7 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143.8 External links . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14

    4 Head normal form 154.1 Beta reduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154.2 Reduction strategies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154.3 See also . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164.4 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16

    5 Blake canonical form 175.1 See also . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 175.2 Notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17

    6 Change of variables 186.1 Simple example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 186.2 Formal introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 196.3 Other examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19

    6.3.1 Coordinate transformation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 196.3.2 Dierentiation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 206.3.3 Integration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 206.3.4 Dierential equations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 206.3.5 Scaling and shifting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 206.3.6 Momentum vs. velocity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 216.3.7 Lagrangian mechanics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21

    6.4 See also . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22

    7 ChurchTuring thesis 237.1 Statement in Churchs and Turings words . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 237.2 History . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24

    7.2.1 Circa 19301952 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 247.2.2 Later developments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 267.2.3 The thesis as a denition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27

    7.3 Success of the thesis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 277.4 Informal usage in proofs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 277.5 Variations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 287.6 Philosophical implications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 287.7 Non-computable functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 297.8 See also . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 297.9 Footnotes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 307.10 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32

  • CONTENTS iii

    7.11 External links . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34

    8 Combinatory logic 358.1 Combinatory logic in mathematics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 358.2 Combinatory logic in computing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 358.3 Summary of the lambda calculus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 368.4 Combinatory calculi . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37

    8.4.1 Combinatory terms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 378.4.2 Reduction in combinatory logic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 378.4.3 Examples of combinators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 378.4.4 Completeness of the S-K basis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 388.4.5 Simplications of the transformation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 408.4.6 Reverse conversion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42

    8.5 Undecidability of combinatorial calculus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 428.6 Applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44

    8.6.1 Compilation of functional languages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 448.6.2 Logic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44

    8.7 See also . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 458.8 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 458.9 Further reading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 458.10 External links . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46

    9 Computability 479.1 Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 479.2 Formal models of computation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 479.3 Power of automata . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49

    9.3.1 Power of nite state machines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 499.3.2 Power of pushdown automata . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 499.3.3 Power of Turing machines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50

    9.4 Concurrency-based models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 519.5 Stronger models of computation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51

    9.5.1 Innite execution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 519.5.2 Oracle machines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 519.5.3 Limits of hyper-computation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52

    9.6 See also . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 529.7 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52

    10 Computability theory 5310.1 Computable and uncomputable sets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5310.2 Turing computability . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5410.3 Areas of research . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54

    10.3.1 Relative computability and the Turing degrees . . . . . . . . . . . . . . . . . . . . . . . . 55

  • iv CONTENTS

    10.3.2 Other reducibilities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5610.3.3 Rices theorem and the arithmetical hierarchy . . . . . . . . . . . . . . . . . . . . . . . . 5610.3.4 Reverse mathematics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5710.3.5 Numberings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5710.3.6 The priority method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5710.3.7 The lattice of recursively enumerable sets . . . . . . . . . . . . . . . . . . . . . . . . . . . 5710.3.8 Automorphism problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5810.3.9 Kolmogorov complexity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5810.3.10 Frequency computation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5810.3.11 Inductive inference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5810.3.12 Generalizations of Turing computability . . . . . . . . . . . . . . . . . . . . . . . . . . . 5910.3.13 Continuous computability theory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59

    10.4 Relationships between denability, proof and computability . . . . . . . . . . . . . . . . . . . . . 5910.5 Name of the subject . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5910.6 Professional organizations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6010.7 See also . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6010.8 Notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6010.9 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6010.10External links . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62

    11 Computable function 6311.1 Denition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6311.2 Characteristics of computable functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6411.3 Computable sets and relations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6511.4 Formal languages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6511.5 Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6511.6 ChurchTuring thesis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6611.7 Uncomputable functions and unsolvable problems . . . . . . . . . . . . . . . . . . . . . . . . . . 6611.8 Extensions of computability . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67

    11.8.1 Relative computability . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6711.8.2 Higher recursion theory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6711.8.3 Hyper-computation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67

    11.9 See also . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6711.10References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68

    12 Conjunctive normal form 6912.1 Examples and Non-Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6912.2 Conversion into CNF . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7012.3 First-order logic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7012.4 Computational complexity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7012.5 Converting from rst-order logic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7112.6 Notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71

  • CONTENTS v

    12.7 See also . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7212.8 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7212.9 External links . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72

    13 Consistency 7313.1 Consistency and completeness in arithmetic and set theory . . . . . . . . . . . . . . . . . . . . . . 7313.2 First-order logic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74

    13.2.1 Notation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7413.2.2 Denition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7413.2.3 Basic results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7413.2.4 Henkins theorem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7513.2.5 Sketch of proof . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75

    13.3 See also . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7513.4 Footnotes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7513.5 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7613.6 External links . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76

    14 Constant (computer programming) 7714.1 Use . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7714.2 Comparison with literals and macros . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7714.3 Dynamically-valued constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7814.4 Constant function parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7914.5 Object-oriented constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79

    14.5.1 Java . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7914.5.2 C# . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80

    14.6 By paradigm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8014.7 Naming conventions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8114.8 See also . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8114.9 Notest . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8114.10References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81

    15 Currying 8215.1 Motivation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8215.2 Denition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8315.3 Mathematical view . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8315.4 Naming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8315.5 Contrast with partial function application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8415.6 See also . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8415.7 Notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8415.8 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8515.9 External links . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85

    16 CurryHoward correspondence 86

  • vi CONTENTS

    16.1 Origin, scope, and consequences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8716.2 General formulation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8816.3 Corresponding systems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88

    16.3.1 Hilbert-style deduction systems and combinatory logic . . . . . . . . . . . . . . . . . . . . 8816.3.2 Natural deduction and lambda calculus . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8916.3.3 Classical logic and control operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9016.3.4 Sequent calculus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90

    16.4 Related proofs-as-programs correspondences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9016.4.1 The role of de Bruijn . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9016.4.2 BHK interpretation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9016.4.3 Realizability . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9116.4.4 CurryHowardLambek correspondence . . . . . . . . . . . . . . . . . . . . . . . . . . . 91

    16.5 Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9216.6 Other applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9416.7 Generalizations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9416.8 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94

    16.8.1 Seminal references . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9516.8.2 Extensions of the correspondence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9516.8.3 Philosophical interpretations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9616.8.4 Synthetic papers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9616.8.5 Books . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96

    16.9 Further reading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9716.10External links . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97

    17 Data type 9817.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9817.2 Denition of a type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9917.3 Classes of data types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99

    17.3.1 Primitive data types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9917.3.2 Composite types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10017.3.3 Other types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10117.3.4 Abstract data types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10117.3.5 Utility types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102

    17.4 Type systems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10217.5 See also . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10217.6 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10217.7 Further reading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103

    18 De Bruijn index 10418.1 Formal denition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10418.2 Alternatives to De Bruijn indices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10518.3 See also . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106

  • CONTENTS vii

    18.4 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106

    19 Disjunctive normal form 10719.1 See also . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10819.2 External links . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108

    20 Domain of a function 10920.1 Formal denition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11020.2 Natural domain . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11020.3 Domain of a partial function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11020.4 Category theory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11020.5 Real and complex analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11020.6 More examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11120.7 See also . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11120.8 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111

    21 Eective method 11221.1 Denition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11221.2 Algorithms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11221.3 Computable functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11221.4 See also . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11321.5 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113

    22 Entscheidungsproblem 11422.1 History of the problem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11422.2 Negative answer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11422.3 Practical decision procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11522.4 See also . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11522.5 Notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11522.6 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11522.7 External links . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116

    23 Extensionality 11723.1 Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11723.2 In mathematics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11723.3 See also . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11823.4 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118

    24 First-class citizen 11924.1 History . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11924.2 Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11924.3 Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12024.4 Reection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12024.5 See also . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120

  • viii CONTENTS

    24.6 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120

    25 Formal system 12125.1 Related subjects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121

    25.1.1 Logical system . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12125.1.2 Deductive system . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12225.1.3 Formal proofs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12225.1.4 Formal language . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12225.1.5 Formal grammar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122

    25.2 See also . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12325.3 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12325.4 Further reading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12325.5 External links . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123

    26 Free variables and bound variables 12426.1 Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124

    26.1.1 Variable-binding operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12526.2 Formal explanation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125

    26.2.1 Function expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12726.3 Natural language . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12726.4 See also . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12826.5 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128

    27 Function application 12927.1 Representation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12927.2 As an operator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12927.3 Other instances . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13027.4 See also . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130

    28 Functional programming 13128.1 History . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13128.2 Concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132

    28.2.1 First-class and higher-order functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13228.2.2 Pure functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13328.2.3 Recursion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13328.2.4 Strict versus non-strict evaluation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13428.2.5 Type systems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13428.2.6 Functional programming in non-functional languages . . . . . . . . . . . . . . . . . . . . 134

    28.3 Comparison to imperative programming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13528.3.1 Simulating state . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13528.3.2 Eciency issues . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13528.3.3 Coding styles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136

    28.4 Use in industry . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138

  • CONTENTS ix

    28.5 In education . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13828.6 See also . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13828.7 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13828.8 Further reading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14128.9 External links . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141

    29 Haskell (programming language) 14229.1 History . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142

    29.1.1 Haskell 1.0 to 1.4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14229.1.2 Haskell 98 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14229.1.3 Haskell Prime . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14229.1.4 Haskell 2010 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143

    29.2 Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14329.3 Code examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14329.4 Implementations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14429.5 Applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14529.6 Industry . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14529.7 Web . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14529.8 Related languages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14529.9 Criticism . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14629.10Conferences and workshops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14729.11References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14729.12Further reading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14929.13External links . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150

    30 Head normal form 15130.1 Beta reduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15130.2 Reduction strategies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15130.3 See also . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15230.4 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152

    31 Herbrandization 15331.1 See also . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15331.2 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154

    32 Herbrandization 15532.1 See also . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15532.2 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 156

    33 Higher-order function 15733.1 General examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15733.2 Support in programming languages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157

    33.2.1 Direct support . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157

  • x CONTENTS

    33.2.2 Alternatives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15933.3 See also . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16033.4 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16033.5 External links . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 160

    34 Horn clause 16134.1 Denition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16134.2 Logic programming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16134.3 Notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16234.4 Bibliography . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162

    35 KleeneRosser paradox 16435.1 The paradox . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16435.2 See also . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16435.3 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164

    36 Lambda calculus 16536.1 Lambda calculus in history of mathematics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16536.2 Informal description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165

    36.2.1 Motivation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16536.2.2 The lambda calculus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 166

    36.3 Formal denition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16836.3.1 Denition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16836.3.2 Notation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16936.3.3 Free and bound variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 169

    36.4 Reduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16936.4.1 -conversion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17036.4.2 -reduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17036.4.3 -conversion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 170

    36.5 Normal forms and conuence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17136.6 Encoding datatypes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171

    36.6.1 Arithmetic in lambda calculus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17136.6.2 Logic and predicates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17236.6.3 Pairs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17336.6.4 Recursion and xed points . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17436.6.5 Standard terms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 175

    36.7 Typed lambda calculus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17636.8 Computable functions and lambda calculus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17636.9 Undecidability of equivalence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17636.10Lambda calculus and programming languages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 176

    36.10.1 Anonymous functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17636.10.2 Reduction strategies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 177

  • CONTENTS xi

    36.10.3 A note about complexity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17836.10.4 Parallelism and concurrency . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 178

    36.11Semantics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17836.12See also . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17836.13Further reading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17936.14External links . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18036.15References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181

    37 Logic 18237.1 The study of logic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 182

    37.1.1 Logical form . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18237.1.2 Deductive and inductive reasoning, and abductive inference . . . . . . . . . . . . . . . . . 18337.1.3 Consistency, validity, soundness, and completeness . . . . . . . . . . . . . . . . . . . . . . 18437.1.4 Rival conceptions of logic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 184

    37.2 History . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18437.3 Types of logic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 186

    37.3.1 Syllogistic logic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18637.3.2 Propositional logic (sentential logic) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18637.3.3 Predicate logic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18637.3.4 Modal logic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18737.3.5 Informal reasoning . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18737.3.6 Mathematical logic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18837.3.7 Philosophical logic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18837.3.8 Computational logic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18837.3.9 Bivalence and the law of the excluded middle; non-classical logics . . . . . . . . . . . . . 18937.3.10 Is logic empirical?" . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19037.3.11 Implication: strict or material? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19037.3.12 Tolerating the impossible . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19037.3.13 Rejection of logical truth . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 190

    37.4 See also . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19137.5 Notes and references . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19237.6 Bibliography . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19437.7 External links . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 194

    38 Mathematical logic 19638.1 Subelds and scope . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19638.2 History . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 197

    38.2.1 Early history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19738.2.2 19th century . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19738.2.3 20th century . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 198

    38.3 Formal logical systems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19938.3.1 First-order logic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 200

  • xii CONTENTS

    38.3.2 Other classical logics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20038.3.3 Nonclassical and modal logic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20138.3.4 Algebraic logic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 201

    38.4 Set theory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20138.5 Model theory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20238.6 Recursion theory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 202

    38.6.1 Algorithmically unsolvable problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20338.7 Proof theory and constructive mathematics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20338.8 Connections with computer science . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20338.9 Foundations of mathematics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20438.10See also . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20438.11Notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20538.12References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 205

    38.12.1 Undergraduate texts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20538.12.2 Graduate texts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20638.12.3 Research papers, monographs, texts, and surveys . . . . . . . . . . . . . . . . . . . . . . 20638.12.4 Classical papers, texts, and collections . . . . . . . . . . . . . . . . . . . . . . . . . . . . 207

    38.13External links . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 208

    39 Name binding 21039.1 Binding time . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21039.2 Rebinding and mutation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21039.3 Late static . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21139.4 See also . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21139.5 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 211

    40 Name resolution 21240.1 In computer systems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21240.2 In programming languages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 212

    40.2.1 Static versus dynamic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21340.2.2 Name masking . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21340.2.3 Alpha renaming to make name resolution trivial . . . . . . . . . . . . . . . . . . . . . . . 214

    40.3 In semantics and text extraction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21440.3.1 Name resolution in simple text . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21440.3.2 Name resolution across documents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 214

    40.4 See also . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21540.5 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 215

    41 Negation normal form 21641.1 Examples and counterexamples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21641.2 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21741.3 External links . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 217

  • CONTENTS xiii

    42 Normal form 21842.1 See also . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 218

    43 Normalization property (abstract rewriting) 21943.1 Lambda calculus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 219

    43.1.1 Untyped lambda calculus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21943.1.2 Typed lambda calculus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 219

    43.2 See also . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21943.3 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 220

    44 Operator associativity 22144.1 Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 221

    44.1.1 A detailed example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22244.2 Right-associativity of assignment operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22244.3 Non-associative operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22244.4 See also . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22344.5 Notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22344.6 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 223

    45 Prenex normal form 22445.1 Conversion to prenex form . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 224

    45.1.1 Conjunction and disjunction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22445.1.2 Negation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22545.1.3 Implication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22545.1.4 Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22545.1.5 Intuitionistic logic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 226

    45.2 Use of prenex form . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22645.3 See also . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22745.4 Notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22745.5 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 227

    46 Programming language theory 22846.1 History . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 229

    46.1.1 1950s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22946.1.2 1960s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22946.1.3 1970s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23046.1.4 1980s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23046.1.5 1990s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 230

    46.2 Sub-disciplines and related elds . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23046.2.1 Formal semantics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23146.2.2 Type theory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23146.2.3 Program analysis and transformation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23146.2.4 Comparative programming language analysis . . . . . . . . . . . . . . . . . . . . . . . . 231

  • xiv CONTENTS

    46.2.5 Generic and metaprogramming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23146.2.6 Domain-specic languages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23146.2.7 Compiler construction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23146.2.8 Run-time systems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 232

    46.3 Journals, publications, and conferences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23246.4 See also . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23246.5 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23246.6 Further reading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23246.7 External links . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 233

    47 Proof theory 23447.1 History . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23447.2 Formal and informal proof . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23447.3 Kinds of proof calculi . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23547.4 Consistency proofs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23547.5 Structural proof theory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23547.6 Proof-theoretic semantics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23647.7 Tableau systems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23647.8 Ordinal analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23647.9 Logics from proof analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23647.10See also . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23647.11Notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23647.12References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 237

    48 Recursive denition 23848.1 Form of recursive denitions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23948.2 Examples of recursive denitions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 239

    48.2.1 Elementary functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23948.2.2 Prime numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24048.2.3 Non-negative even numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24048.2.4 Well formed formulas . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 240

    48.3 See also . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24148.4 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 241

    49 Regular expression 24249.1 Patterns . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24349.2 History . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24349.3 Basic concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24449.4 Formal language theory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 245

    49.4.1 Formal denition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24549.4.2 Expressive power and compactness . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24549.4.3 Deciding equivalence of regular expressions . . . . . . . . . . . . . . . . . . . . . . . . . 246

  • CONTENTS xv

    49.5 Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24649.5.1 Delimiters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24749.5.2 Standards . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24749.5.3 Perl . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24849.5.4 Lazy quantication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 248

    49.6 Patterns for non-regular languages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24949.7 Fuzzy regular expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24949.8 Implementations and running times . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25049.9 Unicode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25049.10Uses . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25149.11Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25149.12See also . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25249.13Notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25249.14References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25349.15External links . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 254

    49.15.1 Standards . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25449.15.2 Language references . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25449.15.3 Links . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25449.15.4 Other . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 255

    50 Simply typed lambda calculus 25650.1 Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25650.2 Typing rules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25750.3 Semantics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 257

    50.3.1 Intrinsic vs. extrinsic interpretations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25750.3.2 Equational theory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25850.3.3 Operational semantics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25850.3.4 Categorical semantics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25850.3.5 Proof-theoretic semantics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 259

    50.4 Alternative syntaxes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25950.5 General observations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25950.6 Important results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26050.7 Notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26050.8 See also . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26050.9 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26050.10External links . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 261

    51 Skolem normal form 26251.1 How Skolemization works . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26251.2 Uses of Skolemization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26351.3 Skolem theories . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26351.4 See also . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 263

  • xvi CONTENTS

    51.5 Notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26451.6 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26451.7 External links . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 264

    52 Standard ML 26552.1 Language . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 265

    52.1.1 Type synonyms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26652.1.2 Algebraic datatypes and pattern matching . . . . . . . . . . . . . . . . . . . . . . . . . . 26652.1.3 Higher-order functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26752.1.4 Exceptions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26752.1.5 Module system . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 267

    52.2 Code examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26852.2.1 Hello world . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26852.2.2 Insertion sort . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26952.2.3 Mergesort . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26952.2.4 Quicksort . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27052.2.5 Expression language . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27052.2.6 Arbitrary-precision factorial function (libraries) . . . . . . . . . . . . . . . . . . . . . . . 27052.2.7 Numerical derivative (higher-order functions) . . . . . . . . . . . . . . . . . . . . . . . . 27052.2.8 Discrete wavelet transform (pattern matching) . . . . . . . . . . . . . . . . . . . . . . . . 271

    52.3 Implementations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27152.4 See also . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27252.5 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27252.6 External links . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 272

    53 Truth value 27453.1 Classical logic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27453.2 Intuitionistic and constructive logic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27453.3 Multi-valued logic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27553.4 Algebraic semantics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27553.5 In other theories . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27553.6 See also . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27553.7 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27553.8 External links . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 276

    54 Turing completeness 27754.1 Non-mathematical usage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27754.2 Formal denitions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27754.3 History . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27854.4 Computability theory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27854.5 Turing oracles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27954.6 Digital physics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 279

  • CONTENTS xvii

    54.7 Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27954.8 Non-Turing-complete languages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 280

    54.8.1 Data languages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28054.9 See also . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28054.10Notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28154.11References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28154.12Further reading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28154.13External links . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 281

    55 Turing machine 28255.1 Informal description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28255.2 Formal denition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28455.3 Additional details required to visualize or implement Turing machines . . . . . . . . . . . . . . . . 284

    55.3.1 Alternative denitions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28555.3.2 The state . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28555.3.3 Turing machine state diagrams . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 286

    55.4 Models equivalent to the Turing machine model . . . . . . . . . . . . . . . . . . . . . . . . . . . 28755.5 Choice c-machines, Oracle o-machines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28855.6 Universal Turing machines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28855.7 Comparison with real machines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 288

    55.7.1 Limitations of Turing machines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29155.8 History . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 291

    55.8.1 Historical background: computational machinery . . . . . . . . . . . . . . . . . . . . . . 29155.8.2 The Entscheidungsproblem (the decision problem): Hilberts tenth question of 1900 . . . 29255.8.3 Alan Turings a- (automatic-)machine . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29355.8.4 19371970: The digital computer, the birth of computer science . . . . . . . . . . . . 29455.8.5 1970present: the Turing machine as a model of computation . . . . . . . . . . . . . . . 294

    55.9 See also . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29555.10Notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29555.11References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 295

    55.11.1 Primary literature, reprints, and compilations . . . . . . . . . . . . . . . . . . . . . . . . 29555.11.2 Computability theory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29555.11.3 Churchs thesis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29655.11.4 Small Turing machines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29755.11.5 Other . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 297

    55.12External links . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 298

    56 Variable shadowing 29956.1 Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29956.2 See also . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29956.3 Text and image sources, contributors, and licenses . . . . . . . . . . . . . . . . . . . . . . . . . . 300

    56.3.1 Text . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 300

  • xviii CONTENTS

    56.3.2 Images . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30956.3.3 Content license . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 311

  • Chapter 1

    Abstraction (computer science)

    The essence of abstractions is preserving information that is relevant in a given context, and forgetting informationthat is irrelevant in that context. John V. Guttag[1]

    In computer science, abstraction is a technique for managing complexity of computer systems. It works by estab-lishing a level of complexity on which a person interacts with the system, suppressing the more complex details belowthe current level. The programmer works with an idealized interface (usually well dened) and can add additionallevels of functionality that would otherwise be too complex to handle. For example, a programmer writing code thatinvolves numerical operations may not be interested in the way numbers are represented in the underlying hardware(e.g. whether they're 16 bit or 32 bit integers), and where those details have been suppressed it can be said that theywere abstracted away, leaving simply numbers with which the programmer can work. In addition, a task of sendingan email message across continents would be extremely complex if you start with a piece of optic cable and basichardware components. By using layers of complexity that have been created to abstract away the physical cables,network layout and presenting the programmer with a virtual data channel, this task is manageable.Abstraction can apply to control or to data: Control abstraction is the abstraction of actions while data abstractionis that of data structures.

    Control abstraction involves the use of subprograms and related concepts control ows Data abstraction allows handling data bits in meaningful ways. For example, it is the basic motivation behind

    datatype.

    One can view the notion of an object as a way to combine abstractions of data and code.The same abstract denition can be used as a common interface for a family of objects with dierent implementationsand behaviors but which share the same meaning. The inheritance mechanism in object-oriented programming canbe used to dene an abstract class as the common interface.The recommendation that programmers use abstractions whenever suitable in order to avoid duplication (usually ofcode) is known as the abstraction principle. The requirement that a programming language provide suitable abstrac-tions is also called the abstraction principle.

    1.1 RationaleComputing mostly operates independently of the concrete world: The hardware implements a model of computa-tion that is interchangeable with others. The software is structured in architectures to enable humans to create theenormous systems by concentration on a few issues at a time. These architectures are made of specic choices ofabstractions. Greenspuns Tenth Rule is an aphorism on how such an architecture is both inevitable and complex.A central form of abstraction in computing is language abstraction: new articial languages are developed to expressspecic aspects of a system. Modeling languages help in planning. Computer languages can be processed with a

    1

  • 2 CHAPTER 1. ABSTRACTION (COMPUTER SCIENCE)

    computer. An example of this abstraction process is the generational development of programming languages fromthe machine language to the assembly language and the high-level language. Each stage can be used as a steppingstone for the next stage. The language abstraction continues for example in scripting languages and domain-specicprogramming languages.Within a programming language, some features let the programmer create new abstractions. These include thesubroutine, the module, and the software component. Some other abstractions such as software design patterns andarchitectural styles remain invisible to a programming language and operate only in the design of a system.Some abstractions try to limit the breadth of concepts a programmer needs by completely hiding the abstractionsthat in turn are built on. The software engineer and writer Joel Spolsky has criticised these eorts by claiming thatall abstractions are leaky that they can never completely hide the details below ; however this does not negate theusefulness of abstraction. Some abstractions are designed to interoperate with others, for example a programminglanguage may contain a foreign function interface for making calls to the lower-level language. Data abstraction isthe separation between the specication of data object and its implementation.

    1.2 Language features

    1.2.1 Programming languagesMain article: Programming language

    Dierent programming languages provide dierent types of abstraction, depending on the intended applications forthe language. For example:

    In object-oriented programming languages such as C++, Object Pascal, or Java, the concept of abstractionhas itself become a declarative statement - using the keywords virtual (in C++) or abstract[2] and interface[3](in Java). After such a declaration, it is the responsibility of the programmer to implement a class to instantiatethe object of the declaration.

    Functional programming languages commonly exhibit abstractions related to functions, such as lambda ab-stractions (making a term into a function of some variable), higher-order functions (parameters are functions),bracket abstraction (making a term into a function of a variable).

    Modern Lisps such as Clojure, Scheme and Common Lisp support macro systems to allow syntactic abstraction.This allows a Lisp programmer to eliminate boilerplate code, abstract away tedious function call sequences,implement new control ow structures, implement or even build Domain Specic Languages (DSLs), whichallow domain-specic concepts to be expressed in some optimised way. All of these, when used correctly,improve both the programmers eciency and the clarity of the code by making the intended purpose moreexplicit. A consequence of syntactic abstraction is also that any Lisp dialect and in fact almost any programminglanguage can, in principle, be implemented in any modern Lisp with signicantly reduced (but still non-trivialin some cases) eort when compared to more traditional programming languages such as Python, C or Java.

    1.2.2 Specication methodsMain article: Formal specication

    Analysts have developed various methods to formally specify software systems. Some known methods include:

    Abstract-model based method (VDM, Z); Algebraic techniques (Larch, CLEAR, OBJ, ACT ONE, CASL); Process-based techniques (LOTOS, SDL, Estelle); Trace-based techniques (SPECIAL, TAM); Knowledge-based techniques (Rene, Gist).

  • 1.3. CONTROL ABSTRACTION 3

    1.2.3 Specication languagesMain article: Specication language

    Specication languages generally rely on abstractions of one kind or another, since specications are typically denedearlier in a project, (and at a more abstract level) than an eventual implementation. The UML specication language,for example, allows the denition of abstract classes, which remain abstract during the architecture and specicationphase of the project.

    1.3 Control abstractionMain article: Control ow

    Programming languages oer control abstraction as one of the main purposes of their use. Computer machinesunderstand operations at the very low level such as moving some bits from one location of the memory to anotherlocation and producing the sum of two sequences of bits. Programming languages allow this to be done in the higherlevel. For example, consider this statement written in a Pascal-like fashion:

    a := (1 + 2) * 5

    To a human, this seems a fairly simple and obvious calculation (one plus two is three, times ve is fteen). However,the low-level steps necessary to carry out this evaluation, and return the value 15, and then assign that value to thevariable a, are actually quite subtle and complex. The values need to be converted to binary representation (often amuch more complicated task than one would think) and the calculations decomposed (by the compiler or interpreter)into assembly instructions (again, which are much less intuitive to the programmer: operations such as shifting abinary register left, or adding the binary complement of the contents of one register to another, are simply not howhumans think about the abstract arithmetical operations of addition or multiplication). Finally, assigning the resultingvalue of 15 to the variable labeled a, so that a can be used later, involves additional 'behind-the-scenes steps oflooking up a variables label and the resultant location in physical or virtual memory, storing the binary representationof 15 to that memory location, etc.Without control abstraction, a programmer would need to specify all the register/binary-level steps each time shesimply wanted to add or multiply a couple of numbers and assign the result to a variable. Such duplication of eorthas two serious negative consequences:

    1. it forces the programmer to constantly repeat fairly common tasks every time a similar operation is needed

    2. it forces the programmer to program for the particular hardware and instruction set

    1.3.1 Structured programmingMain article: Structured programming

    Structured programming involves the splitting of complex program tasks into smaller pieces with clear ow-controland interfaces between components, with reduction of the complexity potential for side-eects.In a simple program, this may aim to ensure that loops have single or obvious exit points and (where possible) to havesingle exit points from functions and procedures.In a larger system, it may involve breaking down complex tasks into many dierent modules. Consider a systemwhich handles payroll on ships and at shore oces:

    The uppermost level may feature a menu of typical end-user operations. Within that could be standalone executables or libraries for tasks such as signing on and o employees or

    printing checks.

  • 4 CHAPTER 1. ABSTRACTION (COMPUTER SCIENCE)

    Within each of those standalone components there could be many dierent source les, each containing theprogram code to handle a part of the problem, with only selected interfaces available to other parts of theprogram. A sign on program could have source les for each data entry screen and the database interface(which may itself be a standalone third party library or a statically linked set of library routines).

    Either the database or the payroll application also has to initiate the process of exchanging data with betweenship and shore, and that data transfer task will often contain many other components.

    These layers produce the eect of isolating the implementation details of one component and its assorted internalmethods from the others. Object-oriented programming embraces and extends this concept.

    1.4 Data abstractionMain article: Abstract data type

    Data abstraction enforces a clear separation between the abstract properties of a data type and the concrete details ofits implementation. The abstract properties are those that are visible to client code that makes use of the data typethe interface to the data typewhile the concrete implementation is kept entirely private, and indeed can change, forexample to incorporate eciency improvements over time. The idea is that such changes are not supposed to haveany impact on client code, since they involve no dierence in the abstract behaviour.For example, one could dene an abstract data type called lookup tablewhich uniquely associates keys with values, andin which values may be retrieved by specifying their corresponding keys. Such a lookup table may be implementedin various ways: as a hash table, a binary search tree, or even a simple linear list of (key:value) pairs. As far as clientcode is concerned, the abstract properties of the type are the same in each case.Of course, this all relies on getting the details of the interface right in the rst place, since any changes there can havemajor impacts on client code. As one way to look at this: the interface forms a contract on agreed behaviour betweenthe data type and client code; anything not spelled out in the contract is subject to change without notice.Languages that implement data abstraction include Ada and Modula-2. Object-oriented languages are commonlyclaimed to oer data abstraction; however, their inheritance concept tends to put information in the interface thatmore properly belongs in the implementation; thus, changes to such information ends up impacting client code,leading directly to the Fragile binary interface problem.

    1.5 Abstraction in object oriented programmingMain article: Object (computer science)

    In object-oriented programming theory, abstraction involves the facility to dene objects that represent abstractactors that can perform work, report on and change their state, and communicate with other objects in the system.The term encapsulation refers to the hiding of state details, but extending the concept of data type from earlierprogramming languages to associate behavior most strongly with the data, and standardizing the way that dierentdata types interact, is the beginning of abstraction. When abstraction proceeds into the operations dened, enablingobjects of dierent types to be substituted, it is called polymorphism. When it proceeds in the opposite direction,inside the types or classes, structuring them to simplify a complex set of relationships, it is called delegation orinheritance.Various object-oriented programming languages oer similar facilities for abstraction, all to support a general strategyof polymorphism in object-oriented programming, which includes the substitution of one type for another in the sameor similar role. Although not as generally supported, a conguration or image or package may predetermine a greatmany of these bindings at compile-time, link-time, or loadtime. This would leave only a minimum of such bindingsto change at run-time.Common Lisp Object System or Self, for example, feature less of a class-instance distinction and more use of del-egation for polymorphism. Individual objects and functions are abstracted more exibly to better t with a sharedfunctional heritage from Lisp.

  • 1.6. CONSIDERATIONS 5

    C++ exemplies another extreme: it relies heavily on templates and overloading and other static bindings at compile-time, which in turn has certain exibility problems.Although these examples oer alternate strategies for achieving the same abstraction, they do not fundamentally alterthe need to support abstract nouns in code - all programming relies on an ability to abstract verbs as functions, nounsas data structures, and either as processes.Consider for example a sample Java fragment to represent some common farm animals to a level of abstractionsuitable to model simple aspects of their hunger and feeding. It denes an Animal class to represent both the state ofthe animal and its functions:public class Animal extends LivingThing { private Location loc; private double energyReserves; public booleanisHungry() { return energyReserves < 2.5; } public void eat(Food food) { // Consume food energyReserves +=food.getCalories(); } public void moveTo(Location location) { // Move to new location this.loc = location; } }

    With the above denition, one could create objects of type Animal and call their methods like this:thePig = new Animal(); theCow = new Animal(); if (thePig.isHungry()) { thePig.eat(tableScraps); } if (theCow.isHungry()){ theCow.eat(grass); } theCow.moveTo(theBarn);

    In the above example, the class Animal is an abstraction used in place of an actual animal, LivingThing is a furtherabstraction (in this case a generalisation) of Animal.If one requires a more dierentiated hierarchy of animals to dierentiate, say, those who provide milk from thosewho provide nothing except meat at the end of their lives that is an intermediary level of abstraction, probablyDairyAnimal (cows, goats) who would eat foods suitable to giving good milk, and MeatAnimal (pigs, steers) whowould eat foods to give the best meat-quality.Such an abstraction could remove the need for the application coder to specify the type of food, so s/he could con-centrate instead on the feeding schedule. The two classes could be related using inheritance or stand alone, and theprogrammer could dene varying degrees of polymorphism between the two types. These facilities tend to varydrastically between languages, but in general each can achieve anything that is possible with any of the others. Agreat many operation overloads, data type by data type, can have the same eect at compile-time as any degree ofinheritance or other means to achieve polymorphism. The class notation is simply a coders convenience.

    1.5.1 Object-oriented designMain article: Object-oriented design

    Decisions regarding what to abstract and what to keep under the control of the coder become the major concern ofobject-oriented design and domain analysisactually determining the relevant relationships in the real world is theconcern of object-oriented analysis or legacy analysis.In general, to determine appropriate abstraction, one must make many small decisions about scope (domain analysis),determine what other systems one must cooperate with (legacy analysis), then perform a detailed object-orientedanalysis which is expressed within project time and budget constraints as an object-oriented design. In our simpleexample, the domain is the barnyard, the live pigs and cows and their eating habits are the legacy constraints, thedetailed analysis is that coders must have the exibility to feed the animals what is available and thus there is no reasonto code the type of food into the class itself, and the design is a single simple Animal class of which pigs and cowsare instances with the same functions. A decision to dierentiate DairyAnimal would change the detailed analysisbut the domain and legacy analysis would be unchangedthus it is entirely under the control of the programmer, andwe refer to abstraction in object-oriented programming as distinct from abstraction in domain or legacy analysis.

    1.6 ConsiderationsWhen discussing formal semantics of programming languages, formal methods or abstract interpretation, abstractionrefers to the act of considering a less detailed, but safe, denition of the observed program behaviors. For instance, onemay observe only the nal result of program executions instead of considering all the intermediate steps of executions.Abstraction is dened to a concrete (more precise) model of execution.

  • 6 CHAPTER 1. ABSTRACTION (COMPUTER SCIENCE)

    Abstraction may be exact or faithful with respect to a property if one can answer a question about the propertyequally well on the concrete or abstract model. For instance, if we wish to know what the result of the evaluation ofa mathematical expression involving only integers +, -, , is worth modulo n, we need only perform all operationsmodulo n (a familiar form of this abstraction is casting out nines).Abstractions, however, though not necessarily exact, should be sound. That is, it should be possible to get soundanswers from themeven though the abstraction may simply yield a result of undecidability. For instance, we mayabstract the students in a class by their minimal and maximal ages; if one asks whether a certain person belongs tothat class, one may simply compare that persons age with the minimal and maximal ages; if his age lies outside therange, one may safely answer that the person does not belong to the class; if it does not, one may only answer I don'tknow.The level of abstraction included in a programming language can inuence its overall usability. The Cognitive dimen-sions framework includes the concept of abstraction gradient in a formalism. This framework allows the designer ofa programming language to study the trade-os between abstraction and other characteristics of the design, and howchanges in abstraction inuence the language usability.Abstractions can prove useful when dealing with computer programs, because non-trivial properties of computerprograms are essentially undecidable (see Rices theorem). As a consequence, automatic methods for deriving in-formation on the behavior of computer programs either have to drop termination (on some occasions, they may fail,crash or never yield out a result), soundness (they may provide false information), or precision (they may answer Idon't know to some questions).Abstraction is the core concept of abstract interpretation. Model checking generally takes place on abstract versionsof the studied systems.

    1.7 Levels of abstractionMain article: Abstraction layer

    Computer science commonly presents levels (or, less commonly, layers) of abstraction, wherein each level representsa dierent model of the same information and processes, but uses a system of expression involving a unique set ofobjects and compositions that apply only to a particular domain. [4] Each relatively abstract, higher level builds ona relatively concrete, lower le