Introductory logic and sets for Computer scientists Nimal Nissanke University of Reading ADDISON WESLEY LONGMAN Harlow, England II Reading, Massachusetts Menlo Park, California New York Don Mills, Ontario Amsterdam «* Bonn Sydney Singapore Tokyo Madrid II San Juan Milan Mexico City Seoul # Taipei
Contents Preface A note on the exercises XIII xvi 1 An overview of logic 1.1 1.2 1.3 1.4 1.5 1.6 1.7 What is logic? Logic in real arguments Arguments and deduction The logical Systems Scientific theories and specifications Mathematical modeis Limitations of our study 1 2 3 3 5 7 8 2 Propositions and propositional connectives 10 2.1 Propositions 11 2.2 Connectives 12 2.3 Ambiguity and imprecision 19 3 Propositional logic as a language 22 3.1 About formal languages 23 3.2 Grammar of propositional logic 24 3.3 The semantics 28 3.4 Truth tables 29 3.5 Tautologies, contradictions and contingent propositions 30 3.6 Notations: T vs true and F vs false 33 3.7 Logical equivalence and logical implication 35 3.8 An application: digital circuits 37 4 Transformational proofs 45 4.1 Logical laws and how to establish them 45 4.2 The logical laws listed 49
4.3 On the art of proofs 52 4.4 An application: programming 55 4.5 An application: digital circuits 57 5 Deductive proofs 60 5.1 Arguments 60 5.2 Validity 62 5.3 Demonstrating validity using truth tables 63 5.4 Demonstrating invalidity 64 5.5 Proving validity using deductive proofs 66 5.6 Inference rules 66 5.7 On the art of proofs 71 5.8 An application: reasoning in theories 78 6 Predicates and quantifiers 80 6.1 The need for predicate logic 80 6.2 Predicates 81 6.3 Unary predicates 83 6.4 Predicate logic and propositional logic 84 6.5 Quantifiers 85 6.6 Elementary reasoning in predicate logic 87 6.7 Predicates with higher arities 88 6.8 An application: program specification 90 7 Further predicate logic 96 7.1 Scope of quantifiers 96 7.2 Bound and free variables 98 7.3 Types of values 100 7.4 Some Conventions 102 7.5 Comparison with variable usage in programming 104 7.6 Comparison with variable usage in mathematics 106 8 Interpretation of formulae 108 8.1 Interpretation of universal quantification 108 8.2 Interpretation of existential quantification 110 8.3 Theorems in predicate logic and proofs 110 8.4 Useful theorems in predicate logic 112 9 Proofs in predicate logic 113 9.1 Recapitulation 114 9.2 Formulae in propositional form 114 9.3 Unknowns and genuine variables 116 9.4 Notation for new inference rules 118 9.5 What to guard against 119
Contents ix 9.6 Theorems in predicate logic 129 9.7 An application: program refinement 133 10 Proof by mathematical induction 141 10.1 What is mathematical induction? 141 10.2 Relationship with induction 142 10.3 The technique of mathematical induction 144 10.4 An application: algorithm analysis 153 11 Basic set theoretical concepts 163 11.1 Whataresets? 163 11.2 How to define sets? 164 11.3 Setequality 166 11.4 The empty set 167 11.5 The universal set 167 11.6 Subsets 168 11.7 Sizeofsets 170 11.8 Power set 171 11.9 An extended notation for sets 172 12 Operations on sets 174 12.1 Binary set Operations 174 12.2 Uses of sets 177 12.3 Set theoretic laws listed 179 12.4 Set theoretic proofs 181 12.5 Generalized set Operations 183 12.6 Disjointsets 185 12.7 An application: formal System specification 185 13 Relations: basic concepts 195 13.1 Pairs and tuples 195 13.2 Cartesian product 196 13.3 Relations as sets 198 1 3.4 Relations as predicates 200 13.5 Graphical representation of relations 202 13.6 Domain, ränge and field 203 13.7 Inverse relation 204 1 3.8 Identity relation 206 1 3.9 An application: relational model of databases 207 14 Advanced relational Operations 211 14.1 Relational composition 211 14.2 Iteration 214 14.3 An application: relational image 216
14.4 Domain and ränge restriction and co-restriction 218 14.5 Relational overriding 220 15 Properties of binary relations 224 15.1 Properties of binary relations 225 15.2 Equivalence relations 227 15.3 Partitions and equivalence classes 232 15.4 Relational closures 236 16 Functions and their Classification 240 16.1 Functions as relations 241 16.2 Classification of functions 243 16.3 Functions as expressions 251 16.4 Function composition 253 16.5 An application: more on formal System specification 256 16.6 An application: functional programming 261 17 Numbers 273 17.1 Natural numbers 273 17.2 Integers 279 17.3 A tour through other number Systems 283 1 7.4 Dense vs sparse sets 288 17.5 Countability 288 17.6 Numbers in Computers 289 18 Sequencesand bags 299 18.1 Sequences as sets 299 18.2 Operations on sequences 301 18.3 Bags 304 18.4 Operations on bags 305 19 Boolean algebra 308 19.1 What is Boolean algebra? 309 19.2 Theorems in Boolean algebra 310 19.3 Proof of theorems 312 19.4 Propositional Interpretation of Boolean algebra 314 19.5 Set interpretation of Boolean algebra 315 19.6 Significance of Boolean algebra 316 20 Lambda abstraction of functions 317 20.1 Curried functions 317 20.2 Infix Operators 318 20.3 Function names 319
Contents xi 20.4 Lambda abstraction 320 20.5 Lambda calculus 322 20.6 Modeiling mathematical objects 334 Appendix: Outline answers to exercises 336 References 374 Index 375