Discrete Structures, Logic, and Computability James L. Hein Portland State University Jones and Bartlett Publishers Sudbury, Massachusetts Boston London Singapore
Preface xv / Elementary Notions and Notations 1.1 A Proof Primer 2 Logical Statements 2 Something to Talk About 4 Proof Techniques 5 Exercises 9 1.2 Sets io Operations on Sets 15 Counting Finite Sets 21 Bags (Multisets) 24 Sets Should Not Be Too Complicated Exercises 27 26 1.3 Other Structures 30 Tuples 30 Products of Sets 32 Lists 34 Strings 36 Relations 38 Graphs 41
vi Contents Trees 48 Counting Tuples 52 Exercises 55 Chapter Summary 57 Facts About Functions 59 2.1 Definitions and Examples 60 Terminology 61 Some Useful Functions 65 Partial Functions 74 Exercises 75 2.2 Constructing Functions 77 Composition and Tupling 77 Higher-Order Functions 83 Exercises 88 2.3 Properties of Functions 89 Injective and Surjective 90 The Pigeonhole Principle 93 Hash Functions 94 Exercises 96 2.4 Counting Infinite Sets 98 Countable and Uncountable 99 Exercises 105 Chapter Summary 106 3 Construction Techniques 109 3.1 Inductively Defined Sets 110 Natural Numbers 111 Lists 113 Strings 117 Binary Trees 120 Product Sets 122 Exercises 124
vii 3.2 Language Constructions 126 Combining Languages 128 Grammars and Derivations 130 Grammars and Languages 136 Meaning and Ambiguity 142 Exercises 145 3.3 Recursively Defined Functions and Procedures 146 Natural Numbers 148 Lists 151 Strings 157 Binary Trees 159 The Redundant Element Problem. 162 The Power Set Problem 163 Computing Streams 165 Exercises 169 Chapter Summary Note 172 m 4 Equivalence, Order, and Inductive Proof 173 4.1 Properties and Tools 174 Composition 175 Closures 179 Path Problems 183 Exercises 189 4.2 Equivalence Relations 192 Equivalence and Partitioning 194 Generating Equivalence Relations 200 An Equivalence Problem 205 Exercises 207 4.3 Order Relations 209 Partial Orders 210 Weil-Founded Orders 218 Ordinal Numbers 226 Exercises 227
vin Contents 4.4 Inductive Proof 229 The Idea of Induction 229 Well-Founded Induction 236 Practical Techniques 236 Proofs About Inductively Denned Sets 241 Exercises 243 Chapter Summary 247 5 Analysis Techniques 249 5.1 Optimal Algorithms 250 Decision Trees 253 Exercises 256 5.2 Elementary Counting Techniques 257 Permutations (Order Is Important) 257 Combinations (Order Is Not Important) 261 Finite Probability 265 Exercises 273 5.3 Solving Recurrences 275 Finding Closed Forms for Sums 278 Generating Functions 282 Exercises 293 5.4 Comparing Rates of Growth 296 Big Theta 296 Little Oh 300 Big Oh and Big Omega 301 Exercises 303 Chapter Summary 303 Notes 304 6 Elementary Logic 305 6.1 How Do We Reason? 306 What Is a Calculus? 308 How Can We Tell Whether Something Is a Proof? 308
ix 6.2 Propositional Calculus 309 Well-Formed Formulas and Semantics 310 Equivalence 313 Truth Functions and Normal Forms 318 Complete Sets of Connectives 326 Exercises 327 6.3 Formal Reasoning Systems 329 Conditional Proof 333 Indirect Proof 338 Proof Notes 340 Reasoning Systems for Propositional Calculus 341 Logic Puzzles 345 Exercises 346 Chapter Summary 348 Notes 349 7 Predicate Logic 351 7.1 First-Order Predicate Calculus 351 Well-Formed Formulas 356. Semantics 358 Validity 362 The Validity Problem 365 Exercises 366 7.2 Equivalent Formulas 368 Equivalence 368 Normal Forms 374 Formalizing English Sentences 378 Summary 380 Exercises 381 7.3 Formal Proofs in Predicate Calculus 382 Universal Instantiation (UI) 383 Existential Instantiation (El) 385 Universal Generalization (UG) 387 Existential Generalization (EG) 392 Examples of Formal Proofs 394 Summary 400 Exercises 401
Chapter Summary 403 Notes 404 8 Applied Logic 405 8.1 Equality 406 Describing Equality 406 Extending Equals for Equals 412 Exercises 413 8.2 Program Correctness 414 Imperative Program Correctness 414 Arrays 426 Termination 430 Note 433 Exercises 434 8.3 Higher-Order Logics 437 Classifying Higher-Order Logics 438 Semantics 442 Higher-Order Reasoning 443 Exercises 445 Chapter Summary 446 9 Computational Logic 449 9.1 A Family Tree 450 Exercises 454 9.2 Automatic Reasoning 454 Clauses and Clausal Forms 455 A Primer of Resolution for Propositions 461 Substitution and Unification 462 Resolution: The General Case 467 Theorem Proving with Resolution 473 Remarks 475 Exercises 476
xi 9.3 Logic Programming 478 Resolution and Logic Programming 480 Logic Programming Techniques 493 Exercises 498 Chapter Summary 500 10 Algebraic Structures and Techniques 501 10.1 What Is an Algebra? 502 The Description Problem 502 High School Algebra 503 Definition of an Algebra 504 Working in Algebras 510 Exercises 515 10.2 Boolean Algebra 516 Simplifying Boolean Expressions 518 Digital Circuits 522 Summary of Properties 527 Exercises 528 10.3 Abstract Data Types as Algebras 529 Natural Numbers 530 Lists and Strings 534 Stacks and Queues 537 Binary Trees and Priority Queues 541 Exercises 543 10.4 Computational Algebras 545 Relational Algebras 546 Process Algebras 548 Functional Algebras 550 Exercises 556 10.5 Other Algebraic Ideas 557 Congruences 557 New Algebras from Old Algebras 562 Morphisms 564 Exercises 571 Chapter Summary 572
xii Contents 11 Regular Languages and Finite Automata 575 11.1 Regular Languages 576 Regular Expressions Exercises 583 577 11.2 Finite Automata 584 Deterministic Finite Automata 585 Nondeterministic Finite Automata 588 Transforming Regular Expressions into Finite Automata 590 Transforming Finite Automata into Regular Expressions Finite Automata as Output Devices 597 592 Representing and Executing Finite Automata 600 Exercises 607 11.3 Constructing Efficient Finite Automata 609 Another Regular Expression to NFA Algorithm 609 Transforming an NFA into a DFA 612 Minimum-State DFAs 617 Exercises 624 11.4 Regular Language Topics 626 Regular Grammars 626 Properties of Regular Languages 631 Exercises 635 Chapter Summary 637 12 Context-Free Languages and Pushdown Automata 639 12.1 Context-Free Languages 640 Exercises 642 12.2 Pushdown Automata 642 Equivalent Forms of Acceptance 645 Context-Free Grammars and Pushdown Automata 649 Representing and Executing Pushdown Automata 655 Exercises 657
xiii 12.3 Parsing Techniques 659 LL(k) Parsing 659 LR(k) Parsing 672 Exercises 684 12.4 Context-Free Language Topics 685 Exercises 694 Chapter Summary 694 13 Turing Machines and Equivalent Models 697 13.1 Turing Machines 698 Turing Machines with Output 701 Alternative Definitions 703 A Universal Turing Machine 708 Exercises 711 13.2 The Church-Turing Thesis 712 Equivalence of Computational Models 713 A Simple Programming Language 716 Partial Recursive Functions 717 Machines That Transform Strings 724 Logic Programming Languages 730 Some Notes 732 Exercises 732 Chapter Summary 734 14 Computational Notions 735 14.1 Computability 735 Effective Enumerations 736 The Halting Problem 739 The Total Problem 741 Other Problems 743 Exercises 746 14.2 A Hierarchy of Languages 747 The Languages 747 Summary 750 Exercises 751
xiv Contents 14.3 Evaluation of Expressions 751 Lambda Calculus 754 Knuth-Bendix Completion 766 Exercises 772 Chapter Summary 774 Answers to Selected Exercises 777 Bibliography 845 Greek Alphabet 850 Symbol Glossary 851 Index 855