Kenneth H. Rosen Discrete Mathematics and Its Applications Eighth Edition Discrete Mathematics and Its Applications Eighth Edition Kenneth H. Rosen formerly AT&T Laboratories DISCRETE MATHEMATICS AND ITS APPLICATIONS, EIGHTH EDITION Published by McGraw-Hill Education, 2 Penn Plaza, New York, NY 10121. Copyright c 2019 by McGraw-Hill Education. All rights reserved. Printed in the United States of America. Previous editions c 2012, 2007, and 2003. No part of this publication may be reproduced or distributed in any form or by any means, or stored in a database or retrieval system, without the prior written consent of McGraw-Hill Education, including, but not limited to, in any network or other electronic storage or transmission, or broadcast for distance learning. Some ancillaries, including electronic and print components, may not be available to customers outside the United States. This book is printed on acid-free paper. 1 2 3 4 5 6 7 8 9 LWI 21 20 19 18 ISBN 978-1-259-67651-2 MHID 1-259-67651-X Product Developer: Nora Devlin Marketing Manager: Alison Frederick Content Project Manager: Peggy Selle Buyer: Sandy Ludovissy Design: Egzon Shaqiri Content Licensing Specialist: Lorraine Buczek Cover Image: c Karl Dehnam/Alamy Stock Photo Compositor: Aptara, Inc. All credits appearing on page or at the end of the book are considered to be an extension of the copyright page. Library of Congress Cataloging-in-Publication Data Names: Rosen, Kenneth H., author. Title: Discrete mathematics and its applications / Kenneth H. Rosen, Monmouth University (and formerly AT&T Laboratories). Description: Eighth edition. | New York, NY : McGraw-Hill, [2019] | Includes bibliographical references and index. Identifiers: LCCN 2018008740| ISBN 9781259676512 (alk. paper) | ISBN 125967651X (alk. paper) Subjects: LCSH: Mathematics. | Computer science–Mathematics. Classification: LCC QA39.3 .R67 2019 | DDC 511–dc23 LC record available at https://lccn.loc.gov/2018008740 The Internet addresses listed in the text were accurate at the time of publication. The inclusion of a website does not indicate an endorsement by the authors or McGraw-Hill Education, and McGraw-Hill Education does not guarantee the accuracy of the information presented at these sites. mheducation.com/highered Contents About the Author vi Preface vii Online Resources xvi To the Student xix 1 The Foundations: Logic and Proofs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 1.1 Propositional Logic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 1.2 Applications of Propositional Logic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 1.3 Propositional Equivalences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26 1.4 Predicates and Quantifiers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40 1.5 Nested Quantifiers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60 1.6 Rules of Inference. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .73 1.7 Introduction to Proofs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84 1.8 Proof Methods and Strategy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96 End-of-Chapter Material . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115 2 Basic Structures: Sets, Functions, Sequences, Sums, and Matrices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121 2.1 Sets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121 2.2 Set Operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133 2.3 Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147 2.4 Sequences and Summations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165 2.5 Cardinality of Sets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179 2.6 Matrices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 188 End-of-Chapter Material . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 195 3 Algorithms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 201 3.1 Algorithms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 201 3.2 The Growth of Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 216 3.3 Complexity of Algorithms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 231 End-of-Chapter Material . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 244 4 Number Theory and Cryptography . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 251 4.1 Divisibility and Modular Arithmetic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 251 4.2 Integer Representations and Algorithms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 260 4.3 Primes and Greatest Common Divisors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 271 4.4 Solving Congruences. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .290 4.5 Applications of Congruences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 303 4.6 Cryptography . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 310 End-of-Chapter Material . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 324 iii iv Contents 5 Induction and Recursion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 331 5.1 Mathematical Induction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 331 5.2 Strong Induction and Well-Ordering . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 354 5.3 Recursive Definitions and Structural Induction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 365 5.4 Recursive Algorithms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 381 5.5 Program Correctness . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 393 End-of-Chapter Material . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 398 6 Counting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 405 6.1 The Basics of Counting. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .405 6.2 The Pigeonhole Principle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 420 6.3 Permutations and Combinations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 428 6.4 Binomial Coefficients and Identities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 437 6.5 Generalized Permutations and Combinations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 445 6.6 Generating Permutations and Combinations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 457 End-of-Chapter Material . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 461 7 Discrete Probability . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 469 7.1 An Introduction to Discrete Probability . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 469 7.2 Probability Theory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 477 7.3 Bayes’ Theorem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 494 7.4 Expected Value and Variance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 503 End-of-Chapter Material . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 520 8 Advanced Counting Techniques . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 527 8.1 Applications of Recurrence Relations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 527 8.2 Solving Linear Recurrence Relations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 540 8.3 Divide-and-Conquer Algorithms and Recurrence Relations . . . . . . . . . . . . . . . . . . . . . . 553 8.4 Generating Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 563 8.5 Inclusion–Exclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 579 8.6 Applications of Inclusion–Exclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 585 End-of-Chapter Material . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 592 9 Relations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 599 9.1 Relations and Their Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 599 9.2 n-ary Relations and Their Applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 611 9.3 Representing Relations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 621 9.4 Closures of Relations. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .628 9.5 Equivalence Relations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 638 9.6 Partial Orderings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 650 End-of-Chapter Material . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 665 Contents v 10 Graphs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 673 10.1 Graphs and Graph Models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 673 10.2 Graph Terminology and Special Types of Graphs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 685 10.3 Representing Graphs and Graph Isomorphism . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 703 10.4 Connectivity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 714 10.5 Euler and Hamilton Paths . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 728 10.6 Shortest-Path Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 743 10.7 Planar Graphs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 753 10.8 Graph Coloring . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 762 End-of-Chapter Material . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 771 11 Trees . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 781 11.1 Introduction to Trees . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 781 11.2 Applications of Trees . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 793 11.3 Tree Traversal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 808 11.4 Spanning Trees . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 821 11.5 Minimum Spanning Trees . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 835 End-of-Chapter Material . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 841 12 Boolean Algebra . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 847 12.1 Boolean Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 847 12.2 Representing Boolean Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 855 12.3 Logic Gates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 858 12.4 Minimization of Circuits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 864 End-of-Chapter Material . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 879 13 Modeling Computation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 885 13.1 Languages and Grammars . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 885 13.2 Finite-State Machines with Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 897 13.3 Finite-State Machines with No Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 904 13.4 Language Recognition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 917 13.5 Turing Machines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 927 End-of-Chapter Material . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 938 Appendices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-1 1 Axioms for the Real Numbers and the Positive Integers . . . . . . . . . . . . . . . . . . . . . . . . . . A-1 2 Exponential and Logarithmic Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-7 3 Pseudocode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-11 Suggested Readings B-1 Answers to Odd-Numbered Exercises S-1 Index of Biographies I-1 Index I-2 About the Author Kenneth H. Rosen received his B.S. in Mathematics from the University of Michigan, Ann Arbor (1972), and his Ph.D. in Mathematics from M.I.T. (1976), where he wrote his thesis in number theory under the direction of Harold Stark. Before joining Bell Laboratories in 1982, he held positions at the University of Colorado, Boulder; The Ohio State University, Columbus; and the University of Maine, Orono, where he was an associate professor of mathematics. He enjoyed a long career as a Distinguished Member of the Technical Staff at AT&T Bell Laboratories (and AT&T Laboratories) in Monmouth County, New Jersey. While working at Bell Labs, he taught at Monmouth University, teaching courses in discrete mathematics, coding theory, and data security. After leaving AT&T Labs, he became a visiting research professor of computer science at Monmouth University, where he has taught courses in algorithm design, computer security and cryptography, and discrete mathematics. Dr. Rosen has published numerous articles in professional journals on number theory and on mathematical modeling. He is the author of the widely used Elementary Number Theory and Its Applications, published by Pearson, currently in its sixth edition, which has been translated into Chinese. He is also the author of Discrete Mathematics and Its Applications, published by McGraw-Hill, currently in its eighth edition. Discrete Mathematics and Its Applications has sold more than 450,000 copies in North America during its lifetime, and hundreds of thousands of copies throughout the rest of the world. This book has also been translated into many languages, including Spanish, French, Portuguese, Greek, Chinese, Vietnamese, and Korean. He is also coauthor of UNIX: The Complete Reference; UNIX System V Release 4: An Introduction; and Best UNIX Tips Ever, all published by Osborne McGraw-Hill. These books have sold more than 150,000 copies, with translations into Chinese, German, Spanish, and Italian. Dr. Rosen is also the editor of both the first and second editions (published in 1999 and 2018, respectively) of the Handbook of Discrete and Combinatorial Mathematics, published by CRC Press. He has served as the advisory editor of the CRC series of books in discrete mathematics, sponsoring more than 70 volumes on diverse aspects of discrete mathematics, many of which are introduced in this book. He is an advisory editor for the CRC series of mathematics textbooks, where he has helped more than 30 authors write better texts. Dr. Rosen serves as an Associate Editor for the journal Discrete Mathematics, where he handles papers in many areas, including graph theory, enumeration, number theory, and cryptography. Dr. Rosen has had a longstanding interest in integrating mathematical software into the educational and professional environments. He has worked on several projects with Waterloo Maple Inc.’s MapleTM software in both these areas. Dr. Rosen has devoted a great deal of energy to ensuring that the online homework for Discrete Mathematics and its Applications is a superior teaching tool. Dr. Rosen has also worked with several publishing companies on their homework delivery platforms. At Bell Laboratories and AT&T Laboratories, Dr. Rosen worked on a wide range of projects, including operations research studies, product line planning for computers and data communications equipment, technology assessment and innovation, and many other efforts. He helped plan AT&T’s products and services in the area of multimedia, including video communications, speech recognition, speech synthesis, and image networking. He evaluated new technology for use by AT&T and did standards work in the area of image networking. He also invented many new services, and holds more than 70 patents. One of his more interesting projects involved helping evaluate technology for the AT&T attraction that was part of EPCOT Center. After leaving AT&T, Dr. Rosen has worked as a technology consultant for Google and for AT&T. vi Preface In writing this book, I was guided by my long-standing experience and interest in teaching discrete mathematics. For the student, my purpose was to present material in a precise, readable manner, with the concepts and techniques of discrete mathematics clearly presented and demonstrated. My goal was to show the relevance and practicality of discrete mathematics to students, who are often skeptical. I wanted to give students studying computer science all of the mathematical foundations they need for their future studies. I wanted to give mathematics students an understanding of important mathematical concepts together with a sense of why these concepts are important for applications. And most importantly, I wanted to accomplish these goals without watering down the material. For the instructor, my purpose was to design a flexible, comprehensive teaching tool using proven pedagogical techniques in mathematics. I wanted to provide instructors with a package of materials that they could use to teach discrete mathematics effectively and efficiently in the most appropriate manner for their particular set of students. I hope that I have achieved these goals. I have been extremely gratified by the tremendous success of this text, including its use by more than one million students around the world over the last 30 years and its translation into many different languages. The many improvements in the eighth edition have been made possible by the feedback and suggestions of a large number of instructors and students at many of the more than 600 North American schools, and at many universities in different parts of the world, where this book has been successfully used. I have been able to significantly improve the appeal and effectiveness of this book edition to edition because of the feedback I have received and the significant investments that have been made in the evolution of the book. This text is designed for a one- or two-term introductory discrete mathematics course taken by students in a wide variety of majors, including mathematics, computer science, and engineering. College algebra is the only explicit prerequisite, although a certain degree of mathematical maturity is needed to study discrete mathematics in a meaningful way. This book has been designed to meet the needs of almost all types of introductory discrete mathematics courses. It is highly flexible and extremely comprehensive. The book is designed not only to be a successful textbook, but also to serve as a valuable resource students can consult throughout their studies and professional life. Goals of a Discrete Mathematics Course A discrete mathematics course has more than one purpose. Students should learn a particular set of mathematical facts and how to apply them; more importantly, such a course should teach students how to think logically and mathematically. To achieve these goals, this text stresses mathematical reasoning and the different ways problems are solved. Five important themes are interwoven in this text: mathematical reasoning, combinatorial analysis, discrete structures, algorithmic thinking, and applications and modeling. A successful discrete mathematics course should carefully blend and balance all five themes. 1. Mathematical Reasoning: Students must understand mathematical reasoning in order to read, comprehend, and construct mathematical arguments. This text starts with a discussion of mathematical logic, which serves as the foundation for the subsequent discussions of methods of proof. Both the science and the art of constructing proofs are addressed. The technique of vii viii Preface mathematical induction is stressed through many different types of examples of such proofs and a careful explanation of why mathematical induction is a valid proof technique. 2. Combinatorial Analysis: An important problem-solving skill is the ability to count or enumerate objects. The discussion of enumeration in this book begins with the basic techniques of counting. The stress is on performing combinatorial analysis to solve counting problems and analyze algorithms, not on applying formulae. 3. Discrete Structures: A course in discrete mathematics should teach students how to work with discrete structures, which are the abstract mathematical structures used to represent discrete objects and relationships between these objects. These discrete structures include sets, permutations, relations, graphs, trees, and finite-state machines. 4. Algorithmic Thinking: Certain classes of problems are solved by the specification of an algorithm. After an algorithm has been described, a computer program can be constructed implementing it. The mathematical portions of this activity, which include the specification of the algorithm, the verification that it works properly, and the analysis of the computer memory and time required to perform it, are all covered in this text. Algorithms are described using both English and an easily understood form of pseudocode. 5. Applications and Modeling: Discrete mathematics has applications to almost every conceivable area of study. There are many applications to computer science and data networking in this text, as well as applications to such diverse areas as chemistry, biology, linguistics, geography, business, and the Internet. These applications are natural and important uses of discrete mathematics and are not contrived. Modeling with discrete mathematics is an extremely important problem-solving skill, which students have the opportunity to develop by constructing their own models in some of the exercises. Changes in the Eighth Edition Although the seventh edition has been an extremely effective text, many instructors have requested changes to make the book more useful to them. I have devoted a significant amount of time and energy to satisfy their requests and I have worked hard to find my own ways to improve the book and to keep it up-to-date. The eighth edition includes changes based on input from more than 20 formal reviewers, feedback from students and instructors, and my insights. The result is a new edition that I expect will be a more effective teaching tool. Numerous changes in the eighth edition have been designed to help students learn the material. Additional explanations and examples have been added to clarify material where students have had difficulty. New exercises, both routine and challenging, have been added. Highly relevant applications, including many related to the Internet, to computer science, and to mathematical biology, have been added. The companion website has benefited from extensive development; it now provides extensive tools students can use to master key concepts and to explore the world of discrete mathematics. Furthermore, additional effective and comprehensive learning and assessment tools are available, complementing the textbook. I hope that instructors will closely examine this new edition to discover how it might meet their needs. Although it is impractical to list all the changes in this edition, a brief list that highlights some key changes, listed by the benefits they provide, may be useful. Changes in the Eighth Edition This new edition of the book includes many enhancements, updates, additions, and edits, all designed to make the book a more effective teaching tool for a modern discrete mathematics course. Instructors who have used the book previously will notice overall changes that have been made throughout the book, as well as specific changes. The most notable revisions are described here. Preface ix Overall Changes ▶ Exposition has been improved throughout the book with a focus on providing more clarity to help students read and comprehend concepts. ▶ Many proofs have been enhanced by adding more details and explanations, and by reminding the reader of the proof methods used. ▶ New examples have been added, often to meet needs identified by reviewers or to illustrate new material. Many of these examples are found in the text, but others are available only on the companion website. ▶ Many new exercises, both routine and challenging, address needs identified by instructors or cover new material, while others strengthen and broaden existing exercise sets. ▶ More second and third level heads have been used to break sections into smaller coherent parts, and a new numbering scheme has been used to identify subsections of the book. ▶ The online resources for this book have been greatly expanded, providing extensive support for both instructors and students. These resources are described later in the front matter. Topic Coverage ▶ Logic Several logical puzzles have been introduced. A new example explains how to model the n-queens problem as a satisfiability problem that is both concise and accessible to students. ▶ Set theory Multisets are now covered in the text. (Previously they were introduced in the exercises.) ▶ Algorithms The string matching problem, an important algorithm for many applications, including spell checking, key-word searching, string-matching, and computational biology, is now discussed. The brute-force algorithm for solving string-matching exercises is presented. ▶ Number theory The new edition includes the latest numerical and theoretic discoveries relating to primes and open conjectures about them. The extended Euclidean algorithm, a one-pass algorithm, is now discussed in the text. (Previously it was covered in the exercises.) ▶ Cryptography The concept of homomorphic encryption, and its importance to cloud computing, is now covered. ▶ Mathematical induction The template for proofs by mathematical induction has been expanded. It is now placed in the text before examples of proof by mathematical induction. ▶ Counting methods The coverage of the division rule for counting has been expanded. ▶ Data mining Association rules—key concepts in data mining—are now discussed in the section on n-ary relations. Also, the Jaccard metric, which is used to find the distance between two sets and which is used in data mining, is introduced in the exercises. ▶ Graph theory applications A new example illustrates how semantic networks, an important structure in artificial intelligence, can be modeled using graphs. x Preface ▶ Biographies New biographies of Wiles, Bhaskaracharya, de la Valle´e-Poussin, Hadamard, Zhang, and Gentry have been added. Existing biographies have been expanded and updated. This adds diversity by including more historically important Eastern mathematicians, major nineteenth and twentieth century researchers, and currently active twenty-first century mathematicians and computer scientists. Features of the Book ACCESSIBILITY This text has proven to be easily read and understood by many beginning students. There are no mathematical prerequisites beyond college algebra for almost all the contents of the text. Students needing extra help will find tools on the companion website for bringing their mathematical maturity up to the level of the text. The few places in the book where calculus is referred to are explicitly noted. Most students should easily understand the pseudocode used in the text to express algorithms, regardless of whether they have formally studied programming languages. There is no formal computer science prerequisite. Each chapter begins at an easily understood and accessible level. Once basic mathematical concepts have been carefully developed, more difficult material and applications to other areas of study are presented. FLEXIBILITY This text has been carefully designed for flexible use. The dependence of chapters on previous material has been minimized. Each chapter is divided into sections of approximately the same length, and each section is divided into subsections that form natural blocks of material for teaching. Instructors can easily pace their lectures using these blocks. WRITING STYLE The writing style in this book is direct and pragmatic. Precise mathematical language is used without excessive formalism and abstraction. Care has been taken to balance the mix of notation and words in mathematical statements. MATHEMATICAL RIGOR AND PRECISION All definitions and theorems in this text are stated extremely carefully so that students will appreciate the precision of language and rigor needed in mathematics. Proofs are motivated and developed slowly; their steps are all carefully justified. The axioms used in proofs and the basic properties that follow from them are explicitly described in an appendix, giving students a clear idea of what they can assume in a proof. Recursive definitions are explained and used extensively. WORKED EXAMPLES Over 800 examples are used to illustrate concepts, relate different topics, and introduce applications. In most examples, a question is first posed, then its solution is presented with the appropriate amount of detail. APPLICATIONS The applications included in this text demonstrate the utility of discrete mathematics in the solution of real-world problems. This text includes applications to a wide variety of areas, including computer science, data networking, psychology, chemistry, engineering, linguistics, biology, business, and the Internet. ALGORITHMS Results in discrete mathematics are often expressed in terms of algorithms; hence, key algorithms are introduced in most chapters of the book. These algorithms are expressed in words and in an easily understood form of structured pseudocode, which is described and specified in Appendix 3. The computational complexity of the algorithms in the text is also analyzed at an elementary level. HISTORICAL INFORMATION The background of many topics is succinctly described in the text. Brief biographies of 89 mathematicians and computer scientists are included as Preface xi footnotes. These biographies include information about the lives, careers, and accomplishments of these important contributors to discrete mathematics, and images, when available, are displayed. In addition, numerous historical footnotes are included that supplement the historical information in the main body of the text. Efforts have been made to keep the book up-to-date by reflecting the latest discoveries. KEY TERMS AND RESULTS A list of key terms and results follows each chapter. The key terms include only the most important that students should learn, and not every term defined in the chapter. EXERCISES There are over 4200 exercises in the text, with many different types of questions posed. There is an ample supply of straightforward exercises that develop basic skills, a large number of intermediate exercises, and many challenging exercises. Exercises are stated clearly and unambiguously, and all are carefully graded for level of difficulty. Exercise sets contain special discussions that develop new concepts not covered in the text, enabling students to discover new ideas through their own work. Exercises that are somewhat more difficult than average are marked with a single star, ∗; those that are much more challenging are marked with two stars, ∗∗. Exercises whose solutions require calculus are explicitly noted. Exercises that develop results used in the text are clearly identified with the right pointing hand symbol, . Answers or outlined solutions to all oddnumbered exercises are provided at the back of the text. The solutions include proofs in which most of the steps are clearly spelled out. REVIEW QUESTIONS A set of review questions is provided at the end of each chapter. These questions are designed to help students focus their study on the most important concepts and techniques of that chapter. To answer these questions students need to write long answers, rather than just perform calculations or give short replies. SUPPLEMENTARY EXERCISE SETS Each chapter is followed by a rich and varied set of supplementary exercises. These exercises are generally more difficult than those in the exercise sets following the sections. The supplementary exercises reinforce the concepts of the chapter and integrate different topics more effectively. COMPUTER PROJECTS Each chapter is followed by a set of computer projects. The approximately 150 computer projects tie together what students may have learned in computing and in discrete mathematics. Computer projects that are more difficult than average, from both a mathematical and a programming point of view, are marked with a star, and those that are extremely challenging are marked with two stars. COMPUTATIONS AND EXPLORATIONS A set of computations and explorations is included at the conclusion of each chapter. These exercises (approximately 120 in total) are designed to be completed using existing software tools, such as programs that students or instructors have written or mathematical computation packages such as MapleTM or MathematicaTM. Many of these exercises give students the opportunity to uncover new facts and ideas through computation. (Some of these exercises are discussed in the Exploring Discrete Mathematics companion workbooks available online.) WRITING PROJECTS Each chapter is followed by a set of writing projects. To do these projects students need to consult the mathematical literature. Some of these projects are historical in nature and may involve looking up original sources. Others are designed to serve as gateways to new topics and ideas. All are designed to expose students to ideas not covered in depth in the text. These projects tie mathematical concepts together with the writing process and xii Preface help expose students to possible areas for future study. (Suggested references for these projects can be found online or in the printed Student’s Solutions Guide.) APPENDICES There are three appendices to the text. The first introduces axioms for real numbers and the positive integers, and illustrates how facts are proved directly from these axioms. The second covers exponential and logarithmic functions, reviewing some basic material used heavily in the course. The third specifies the pseudocode used to describe algorithms in this text. SUGGESTED READINGS A list of suggested readings for the overall book and for each chapter is provided after the appendices. These suggested readings include books at or below the level of this text, more difficult books, expository articles, and articles in which discoveries in discrete mathematics were originally published. Some of these publications are classics, published many years ago, while others have been published in the last few years. These suggested readings are complemented by the many links to valuable resources available on the web that can be found on the website for this book. How to Use This Book This text has been carefully written and constructed to support discrete mathematics courses at several levels and with differing foci. The following table identifies the core and optional sections. An introductory one-term course in discrete mathematics at the sophomore level can be based on the core sections of the text, with other sections covered at the discretion of the instructor. A two-term introductory course can include all the optional mathematics sections in addition to the core sections. A course with a strong computer science emphasis can be taught by covering some or all of the optional computer science sections. Instructors can find sample syllabi for a wide range of discrete mathematics courses and teaching suggestions for using each section of the text can be found in the Instructor’s Resource Guide available on the website for this book. Chapter 1 2 3 4 5 6 7 8 9 10 11 12 13 Core 1.1–1.8 (as needed) 2.1–2.4, 2.6 (as needed) 4.1–4.4 (as needed) 5.1–5.3 6.1–6.3 7.1 8.1, 8.5 9.1, 9.3, 9.5 10.1–10.5 11.1 Optional CS 3.1–3.3 (as needed) 4.5, 4.6 5.4, 5.5 6.6 7.4 8.3 9.2 11.2, 11.3 12.1–12.4 13.1–13.5 Optional Math 2.5 6.4, 6.5 7.2, 7.3 8.2, 8.4, 8.6 9.4, 9.6 10.6–10.8 11.4, 11.5 Instructors using this book can adjust the level of difficulty of their course by choosing either to cover or to omit the more challenging examples at the end of sections, as well as the more challenging exercises. The chapter dependency chart shown here displays the strong dependencies. A star indicates that only relevant sections of the chapter are needed for study of a later chapter. Weak dependencies have been ignored. More details can be found in the Instructor’s Resource Guide. Preface xiii Ancillaries Chapter 9* Chapter 10* Chapter 11 Chapter 1 Chapter 2* Chapter 3* Chapter 4* Chapter 5* Chapter 6* Chapter 13 Chapter 7 Chapter 8 Chapter 12 STUDENT’S SOLUTIONS GUIDE This student manual, available separately, contains full solutions to all odd-numbered exercises in the exercise sets. These solutions explain why a particular method is used and why it works. For some exercises, one or two other possible approaches are described to show that a problem can be solved in several different ways. Suggested references for the writing projects found at the end of each chapter are also included in this volume. Also included are a guide to writing proofs and an extensive description of common mistakes students make in discrete mathematics, plus sample tests and a sample crib sheet for each chapter designed to help students prepare for exams. INSTRUCTOR’S RESOURCE GUIDE This manual, available on the website and in printed form by request for instructors, contains full solutions to even-numbered exercises in the text. Suggestions on how to teach the material in each chapter of the book are provided, including the points to stress in each section and how to put the material into perspective. It also offers sample tests for each chapter and a test bank containing over 1500 exam questions to choose from. Answers to all sample tests and test bank questions are included. Finally, sample syllabi are presented for courses with differing emphases and student ability levels. Acknowledgments I would like to thank the many instructors and students at a variety of schools who have used this book and provided me with their valuable feedback and helpful suggestions. Their input has made this a much better book than it would have been otherwise. I especially want to thank Jerrold Grossman and Dan Jordan for their technical reviews of the eighth edition and their “eagle eyes,” which have helped ensure the accuracy and quality of this book. Both have proofread every part of the book many times as it has gone through the different steps of production and have helped eliminate old errata and prevented the insertion of new errata. Thanks go to Dan Jordan for his work on the student solutions manual and instructor’s resource guide. He has done an admirable job updating these ancillaries. Jerrold Grossman, the author of these ancillaries for the first seven editions of the book, has provided valuable assistance to Dan. I would also like to express my gratitude to the many people who have helped create and maintain the online resources for this book. In particular, special thanks go to Dan Jordan and Rochus Boerner for their extensive work improving online questions for the Connect Site, described later in this preface. I thank the reviewers of this eighth and all previous editions. These reviewers have provided much helpful criticism and encouragement to me. I hope this edition lives up to their high expectations. There have been well in excess of 200 reviewers of this book since its first edition, with many from countries other than the United States. The most recent reviewers are listed here. xiv Preface Recent Reviewers Barbara Anthony Southwestern University Philip Barry University of Minnesota, Minneapolis Benkam Bobga University of North Georgia Miklos Bona University of Florida Steve Brick University of South Alabama Kirby Brown Queens College John Carter University of Toronto Narendra Chaudhari Nanyang Technological University Tim Chappell Penn Valley Community College Allan Cochran University of Arkansas Daniel Cunningham Buffalo State College H.K. Dai Oklahoma State University George Davis Georgia State University Andrzej Derdzinski The Ohio State University Ronald Dotzel University of Missouri-St. Louis T.J. Duda Columbus State Community College Bruce Elenbogen University of Michigan, Dearborn Norma Elias Purdue University, Calumet-Hammond Herbert Enderton University of California, Los Angeles Anthony Evans Wright State University Kim Factor Marquette University Margaret Fleck University of Illinois, Champaign Melissa Gaddini Robert Morris University Peter Gillespie Fayetteville State University Johannes Hattingh Georgia State University James Helmreich Marist College Ken Holladay University of New Orleans Jerry Ianni LaGuardia Community College Milagros Izquierdo Linko¨ping University Ravi Janardan University of Minnesota, Minneapolis Norliza Katuk University of Utara Malaysia Monika Kiss Saint Leo University William Klostermeyer University of North Florida Przemo Kranz University of Mississippi Jaromy Kuhl University of West Florida Loredana Lanzani University of Arkansas, Fayetteville Frederic Latour Central Connecticut State University Steven Leonhardi Winona State University Chunlei Liu Valdosta State University Xu Liutong Beijing University of Posts and Telecommunications Vladimir Logvinenko De Anza Community College Tamsen McGinley Santa Clara University Ramon A. Mata-Toledo James Madison University Tamara Melnik Computer Systems Institute Osvaldo Mendez University of Texas at El Paso Darrell Minor Columbus State Community College Kathleen O’Connor Quinsigamond Community College Keith Olson Utah Valley University Dimitris Papamichail The College of New Jersey Yongyuth Permpoontanalarp King Mongkut’s University of Technology, Thonburi Galin Piatniskaia University of Missouri, St. Louis Shawon Rahman University of Hawaii at Hilo Eric Rawdon University of St. Thomas Stefan Robila Montclair State University Chris Rodger Auburn University Sukhit Singh Texas State University, San Marcos David Snyder Texas State University, San Marcos Wasin So San Jose State University Bogdan Suceava California State University, Fullerton Christopher Swanson Ashland University Bon Sy Queens College Fereja Tahir Illinois Central College K.A. Venkatesh Presidency University Matthew Walsh Indiana-Purdue University, Fort Wayne Sheri Wang University of Phoenix Gideon Weinstein Western Governors University David Wilczynski University of Southern California James Wooland Florida State University Preface xv I also want to thank the many students who have provided suggestions and reported errata. The students in the discrete mathematics courses I have taught at Monmouth University, both undergraduate and graduate computer science students, have helped me improve the book in many ways. There are many people to thank at McGraw-Hill Higher Education, the publisher of this book, as well as people who did the production work at Aptara. I would also like to thank the original editor at Random House, Wayne Yuhasz, whose insights and skills helped ensure the book’s success, as well as all the many other previous editors of this book. I want to express my deep appreciation to Nora Devlin, the Product Developer who has gone far beyond her assigned duties to support the author. She has displayed many skills and virtues working to solve a wide variety of problems that have arisen in the development of this new edition. I am also grateful to Peggy Selle, the Content Product Manager, who managed the production process. She has kept the production on track and has helped resolve many issues that have arise during this process. Thanks go to Sarita Yadav, Senior Product Manager of Aptara, and her colleagues at Aptara, who worked diligently to ensure the production quality of this edition. I also want to express my appreciation to the many others in the Science, Engineering, and Mathematics (SEM) Division of McGraw-Hill Higher Education for their valuable support for this new edition and the associated media content, including ▶ Mike Ryan, VP, Portfolio & Learning Content, Higher Education ▶ Kathleen McMahon, Managing Director, Mathematics & Physical Sciences ▶ Caroline Celano, Director, Mathematics ▶ Alison Frederick, Marketing Manager ▶ Robin Reed, Lead Product Developer ▶ Sandy Ludovissey, Buyer ▶ Egzon Shaqiri, Designer ▶ Tammy Juran, Assessment Content Project Manager ▶ Cynthia Northrup, Director of Digital Content ▶ Ruth Czarnecki-Lichstein, Business Product Manager ▶ Megan Platt, Editorial Coordinator ▶ Lora Neyens and Jolynn Kilburg, Program Managers ▶ Lorraine Buczek, Content Licensing Specialist Kenneth H. Rosen Online Resources Extensive effort has been devoted to producing valuable web resources for this book. Instructors should make a special effort to explore these resources to identify those they feel will help their students learn and explore discrete mathematics. These resources are available in the Online Learning Center, which is available to all students and instructors, and the Connect Site, designed for interactive instruction, which instructors can choose to use. To use Connect, students purchase online access for a specific time period. 0.1 The Online Learning Center The Online Learning Center (OLC), accessible at www.mhhe.com/rosen, includes an Information Center, a Student Site, and an Instructor Site. Key features of each area are described here. Extra Examples Demo Assessment Links xvi 0.1.1 The Information Center The Information Center contains basic information about the book including the expanded table of contents (including subsection heads), the preface, descriptions of the ancillaries, and a sample chapter. It also provides a link that can be used to submit errata reports and other feedback about the book. 0.1.2 Student Site The Student Site contains a wealth of resources available for student use, including the following, tied into the text wherever the special icons displayed below are found in the text: ▶ Extra Examples You can find a large number of additional examples on the site, covering all chapters of the book. These examples are concentrated in areas where students often ask for additional material. Although most of these examples amplify the basic concepts, more-challenging examples can also be found here. Many new extra examples have been recently added for the eighth edition. Each icon in the book corresponds to one or more extra examples on the website. ▶ Interactive Demonstration Applets These applets enable you to interactively explore how important algorithms work, and are tied directly to material in the text with linkages to examples and exercises. Additional resources are provided on how to use and apply these applets. ▶ Self Assessments These interactive guides help you assess your understanding of 14 key concepts, providing a question bank where each question includes a brief tutorial followed by a multiple-choice question. If you select an incorrect answer, advice is provided to help you understand your error. Using these Self Assessments, you should be able to diagnose your problems and find appropriate help. ▶ Web Resources Guide This guide provides annotated links to hundreds of external websites containing relevant material such as historical and biographical information, puzzles and problems, discussions, applets, programs, and more. These links are keyed to the text by page number. Online Resources xvii Additional resources in the Student Site include: ▶ Exploring Discrete Mathematics This ancillary provides help for using a computer algebra system to do a wide range of computations in discrete mathematics. Each chapter provides a description of relevant functions in the computer algebra system and how they are used, programs to carry out computations in discrete mathematics, examples, and exercises that can be worked using this computer algebra system. Two versions, Exploring Discrete Mathematics with MapleTM and Exploring Discrete Mathematics with MathematicaTM, are available. ▶ Applications of Discrete Mathematics This ancillary contains 24 chapters—each with its own set of exercises—presenting a wide variety of interesting and important applications covering three general areas in discrete mathematics: discrete structures, combinatorics, and graph theory. These applications are ideal for supplementing the text or for independent study. ▶ A Guide to Proof-Writing This guide provides additional help for writing proofs, a skill that many students find difficult to master. By reading this guide at the beginning of the course and periodically thereafter when proof writing is required, you will be rewarded as your proof-writing ability grows. (Also available in the Student’s Solutions Guide.) ▶ Common Mistakes in Discrete Mathematics This guide includes a detailed list of common misconceptions that students of discrete mathematics often have and the kinds of errors they tend to make. You are encouraged to review this list from time to time to help avoid these common traps. (Also available in the Student’s Solutions Guide.) ▶ Advice on Writing Projects This guide offers helpful hints and suggestions for the Writing Projects in the text, including an extensive bibliography of helpful books and articles for research, discussion of various resources available in print and online, tips on doing library research, and suggestions on how to write well. (Also available in the Student’s Solutions Guide.) 0.1.3 Instructor Site This part of the website provides access to all of the resources on the Student Site, as well as these resources for instructors: ▶ Suggested Syllabi Detailed course outlines are shown, offering suggestions for courses with different emphases and different student backgrounds and ability levels. ▶ Teaching Suggestions This guide contains detailed teaching suggestions for instructors, including chapter overviews for the entire text, detailed remarks on each section, and comments on the exercise sets. ▶ Printable Tests Printable tests are offered in TeX and Word format for every chapter, and can be customized by instructors. ▶ PowerPoint Lecture Slides and PowerPoint Figures and Tables An extensive collection of PowerPoint lecture notes for all chapters of the text are provided for instructor use. In addition, images of all figures and tables from the text are provided as PowerPoint slides. 0.1.4 Connect A comprehensive online learning package has been developed in conjunction with the text. A high-level description of this site will be provided here. Interested instructors and students can find out more about Connect from McGraw-Hill Higher Education. When instructors choose to use this option, students in their classes must obtain access to Connect for this text, either by purchasing a copy of the textbook that also includes access privileges or by purchasing access only with the option of buying a loose-leaf version of the textbook. xviii Online Resources Instructors who adopt Connect have access to a full-featured course management system. Course management capabilities are provided that allow instructors to create assignments, automatically assign and grade homework, quiz, and test questions from a bank of questions tied directly to the text, create and edit their own questions, manage course announcements and due dates, and track student progress. Instructors can create their own assignments using Connect. They select the particular exercises from each section of the book that they want to assign. They can also assign chapters from the SmartBook version of the text, which provides an adaptive learning environment. Students have access to the interactive version of the textbook, the online homework exercises, and SmartBook. Interactive Textbook Students have access to an easy-to-use interactive version of the textbook when they use Connect. The interactive site provides the full content of the text, as well as the many extra resources that enrich the book. The resources include extra examples, interactive demonstrations, and self-assessments. Homework and Learning Management Solution An extensive learning management solution has been developed that instructors can use to construct homework assignments. Approximately 800 online questions are available, including questions from every section of the text. These questions are tied to the most commonly assigned exercises in the book. These online questions have been constructed to support the same objectives as the corresponding written homework questions. This challenge has been met by stretching the capabilities of different question types supported by the Connect platform. SmartBook Connect also provides another extended online version of the text in the McGrawHill SmartBook platform. The SmartBook version of the text includes a set of objectives for each chapter of the text. A collection of questions, called probes, is provided to assess student understanding of each objective. Students are directed to the appropriate part of the text to review the material needed for each of these objectives. SmartBook provides an adaptive learning environment; it selects probes for students based on their performance answering earlier probes. Instructors can assign SmartBook as assignments or can have their students use SmartBook as a learning tool. To the Student What is discrete mathematics? Discrete mathematics is the part of mathematics devoted to the study of discrete objects. (Here discrete means consisting of distinct or unconnected elements.) The kinds of problems solved using discrete mathematics include: ▶ How many ways are there to choose a valid password on a computer system? ▶ What is the probability of winning a lottery? ▶ Is there a link between two computers in a network? ▶ How can I identify spam e-mail messages? ▶ How can I encrypt a message so that no unintended recipient can read it? ▶ What is the shortest path between two cities using a transportation system? ▶ How can a list of integers be sorted so that the integers are in increasing order? ▶ How many steps are required to do such a sorting? ▶ How can it be proved that a sorting algorithm correctly sorts a list? ▶ How can a circuit that adds two integers be designed? ▶ How many valid Internet addresses are there? You will learn the discrete structures and techniques needed to solve problems such as these. More generally, discrete mathematics is used whenever objects are counted, when relation- ships between finite (or countable) sets are studied, and when processes involving a finite number of steps are analyzed. A key reason for the growth in the importance of discrete mathematics is that information is stored and manipulated by computing machines in a discrete fashion. WHY STUDY DISCRETE MATHEMATICS? There are several important reasons for studying discrete mathematics. First, through this course you can develop your mathematical maturity: that is, your ability to understand and create mathematical arguments. You will not get very far in your studies in the mathematical sciences without these skills. Second, discrete mathematics is the gateway to more advanced courses in all parts of the mathematical sciences. Discrete mathematics provides the mathematical foundations for many computer science courses, including data structures, algorithms, database theory, automata theory, formal languages, compiler theory, computer security, and operating systems. Students find these courses much more difficult when they have not had the appropriate mathematical foundations from discrete mathematics. One student sent me an e-mail message saying that she used the contents of this book in every computer science course she took! Math courses based on the material studied in discrete mathematics include logic, set theory, number theory, linear algebra, abstract algebra, combinatorics, graph theory, and probability theory (the discrete part of the subject). Also, discrete mathematics contains the necessary mathematical background for solving problems in operations research (including discrete optimization), chemistry, engineering, biology, and so on. In the text, we will study applications to some of these areas. Many students find their introductory discrete mathematics course to be significantly more challenging than courses they have previously taken. One reason for this is that one of the primary goals of this course is to teach mathematical reasoning and problem solving, rather than a discrete set of skills. The exercises in this book are designed to reflect this goal. Although there are plenty of exercises in this text similar to those addressed in the examples, a large percentage xix xx To the Student of the exercises require original thought. This is intentional. The material discussed in the text provides the tools needed to solve these exercises, but your job is to successfully apply these tools using your own creativity. One of the primary goals of this course is to learn how to attack problems that may be somewhat different from any you may have previously seen. Unfortunately, learning how to solve only particular types of exercises is not sufficient for success in developing the problem-solving skills needed in subsequent courses and professional work. This text addresses many different topics, but discrete mathematics is an extremely diverse and large area of study. One of my goals as an author is to help you develop the skills needed to master the additional material you will need in your own future pursuits. Finally, discrete mathematics is an excellent environment in which to learn how to read and write mathematical proofs. In addition to explicit material on proofs in Chapter 1 and Chapter 5, this textbook contains throughout many proofs of theorems and many exercises asking the student to prove statements. This not only deepens one’s understanding of the subject matter but is also valuable preparation for more advanced courses in mathematics and theoretical computer science. THE EXERCISES I would like to offer some advice about how you can best learn discrete mathematics (and other subjects in the mathematical and computing sciences). You will learn the most by actively working exercises. I suggest that you solve as many as you possibly can. After working the exercises your instructor has assigned, I encourage you to solve additional exercises such as those in the exercise sets following each section of the text and in the supplementary exercises at the end of each chapter. (Note the key explaining the markings preceding exercises.) Key to the Exercises no marking ∗ ∗∗ A routine exercise A difficult exercise An extremely challenging exercise An exercise containing a result used in the book (Table 1 on the following page shows where these exercises are used.) (Requires calculus) An exercise whose solution requires the use of limits or concepts from differential or integral calculus The best approach is to try exercises yourself before you consult the answer section at the end of this book. Note that the odd-numbered exercise answers provided in the text are answers only and not full solutions; in particular, the reasoning required to obtain answers is omitted in these answers. The Student’s Solutions Guide, available separately, provides complete, worked solutions to all odd-numbered exercises in this text. When you hit an impasse trying to solve an odd-numbered exercise, I suggest you consult the Student’s Solutions Guide and look for some guidance as to how to solve the problem. The more work you do yourself rather than passively reading or copying solutions, the more you will learn. The answers and solutions to the evennumbered exercises are intentionally not available from the publisher; ask your instructor if you have trouble with these. WEB RESOURCES All users of the book are able to access the online resources accessible via the Online Learning Center (OLC) for the book. You will find many Extra Examples designed to clarify key concepts, Self Assessments for gauging how well you understand core topics, Interactive Demonstrations that explore key algorithms and other concepts, a Web Resources Guide containing an extensive selection of links to external sites relevant to the world of discrete mathematics, extra explanations and practice to help you master core concepts, added instruction on writing proofs and on avoiding common mistakes in discrete mathematics, in-depth discussions of important applications, and guidance on utilizing MapleTM and To the Student xxi TABLE 1 Hand-Icon Exercises and Where They Are Used Section Exercise Section Where Used Pages Where Used 1.1 42 1.3 33 1.1 43 1.3 33 1.3 11 1.6 76 1.3 12 1.6 74, 76 1.3 19 1.6 76 1.3 34 1.6 76, 78 1.3 46 12.2 856 1.7 18 1.7 86 2.3 74 2.3 144 2.3 81 2.5 170 2.5 15 2.5 174 2.5 16 2.5 173 3.1 45 3.1 197 3.2 74 11.2 797 4.3 37 4.1 253 4.4 2 4.6 318 4.4 44 7.2 489 6.4 21 7.2 491 6.4 25 7.4 480 7.2 15 7.2 491 9.1 26 9.4 629 10.4 59 11.1 782 11.1 15 11.1 786 11.1 30 11.1 791 11.1 48 11.2 798 12.1 12 12.3 861 A.2 4 8.3 531 MathematicaTM software to explore the computational aspects of discrete mathematics. Places in the text where these additional online resources are available are identified in the margins by special icons. For more details on these and other online resources, see the description of the companion website immediately preceding this “To the Student” message. THE VALUE OF THIS BOOK My intention is to make your substantial investment in this text an excellent value. The book, the associated ancillaries, and companion website have taken many years of effort to develop and refine. I am confident that most of you will find that the text and associated materials will help you master discrete mathematics, just as so many previous students have. Even though it is likely that you will not cover some chapters in your current course, you should find it helpful—as many other students have—to read the relevant sections of the book as you take additional courses. Most of you will return to this book as a useful tool throughout your future studies, especially for those of you who continue in computer science, mathematics, and engineering. I have designed this book to be a gateway for future studies and explorations, and to be comprehensive reference, and I wish you luck as you begin your journey. Kenneth H. Rosen CHAPTER 1 The Foundations: Logic and Proofs 1.1 Propositional Logic 1.2 Applications of Propositional Logic 1.3 Propositional Equivalences 1.4 Predicates and Quantifiers 1.5 Nested Quantifiers 1.6 Rules of Inference 1.7 Introduction to Proofs 1.8 Proof Methods and Strategy The rules of logic specify the meaning of mathematical statements. For instance, these rules help us understand and reason with statements such as “There exists an integer that is not the sum of two squares” and “For every positive integer n, the sum of the positive integers not exceeding n is n(n + 1)∕2.” Logic is the basis of all mathematical reasoning, and of all automated reasoning. It has practical applications to the design of computing machines, to the specification of systems, to artificial intelligence, to computer programming, to programming languages, and to other areas of computer science, as well as to many other fields of study. To understand mathematics, we must understand what makes up a correct mathematical argument, that is, a proof. Once we prove a mathematical statement is true, we call it a theorem. A collection of theorems on a topic organize what we know about this topic. To learn a mathematical topic, a person needs to actively construct mathematical arguments on this topic, and not just read exposition. Moreover, knowing the proof of a theorem often makes it possible to modify the result to fit new situations. Everyone knows that proofs are important throughout mathematics, but many people find it surprising how important proofs are in computer science. In fact, proofs are used to verify that computer programs produce the correct output for all possible input values, to show that algorithms always produce the correct result, to establish the security of a system, and to create artificial intelligence. Furthermore, automated reasoning systems have been created to allow computers to construct their own proofs. In this chapter, we will explain what makes up a correct mathematical argument and introduce tools to construct these arguments. We will develop an arsenal of different proof methods that will enable us to prove many different types of results. After introducing many different methods of proof, we will introduce several strategies for constructing proofs. We will introduce the notion of a conjecture and explain the process of developing mathematics by studying conjectures. 1.1 Propositional Logic 1.1.1 Introduction The rules of logic give precise meaning to mathematical statements. These rules are used to distinguish between valid and invalid mathematical arguments. Because a major goal of this book is to teach the reader how to understand and how to construct correct mathematical arguments, we begin our study of discrete mathematics with an introduction to logic. Besides the importance of logic in understanding mathematical reasoning, logic has numerous applications to computer science. These rules are used in the design of computer circuits, the construction of computer programs, the verification of the correctness of programs, and in many other ways. Furthermore, software systems have been developed for constructing some, but not all, types of proofs automatically. We will discuss these applications of logic in this and later chapters. 1 2 1 / The Foundations: Logic and Proofs 1.1.2 Propositions Our discussion begins with an introduction to the basic building blocks of logic—propositions. A proposition is a declarative sentence (that is, a sentence that declares a fact) that is either true or false, but not both. EXAMPLE 1 All the following declarative sentences are propositions. Extra Examples 1. Washington, D.C., is the capital of the United States of America. 2. Toronto is the capital of Canada. 3. 1 + 1 = 2. 4. 2 + 2 = 3. Propositions 1 and 3 are true, whereas 2 and 4 are false. ◂ Some sentences that are not propositions are given in Example 2. EXAMPLE 2 Consider the following sentences. 1. What time is it? 2. Read this carefully. 3. x + 1 = 2. 4. x + y = z. Sentences 1 and 2 are not propositions because they are not declarative sentences. Sentences 3 and 4 are not propositions because they are neither true nor false. Note that each of sentences 3 and 4 can be turned into a proposition if we assign values to the variables. We will also discuss other ways to turn sentences such as these into propositions in Section 1.4. ◂ We use letters to denote propositional variables (or sentential variables), that is, variables that represent propositions, just as letters are used to denote numerical variables. The conventional letters used for propositional variables are p, q, r, s, … . The truth value of a proposition Links ARISTOTLE (384 B.C.E.–322 B.C.E.) Aristotle was born in Stagirus (Stagira) in northern Greece. His father was the personal physician of the King of Macedonia. Because his father died when Aristotle was young, Aristotle could not follow the custom of following his father’s profession. Aristotle became an orphan at a young age when his mother also died. His guardian who raised him taught him poetry, rhetoric, and Greek. At the age of 17, his guardian sent him to Athens to further his education. Aristotle joined Plato’s Academy, where for 20 years he attended Plato’s lectures, later presenting his own lectures on rhetoric. When Plato died in 347 B.C.E., Aristotle was not chosen to succeed him because his views differed too much from those of Plato. Instead, Aristotle joined the court of King Hermeas where he remained for three years, and married the niece Source: National Library of of the King. When the Persians defeated Hermeas, Aristotle moved to Mytilene and, at the invitation of King Medicine Philip of Macedonia, he tutored Alexander, Philip’s son, who later became Alexander the Great. Aristotle tutored Alexander for five years and after the death of King Philip, he returned to Athens and set up his own school, called the Lyceum. Aristotle’s followers were called the peripatetics, which means “to walk about,” because Aristotle often walked around as he discussed philosophical questions. Aristotle taught at the Lyceum for 13 years where he lectured to his advanced students in the morning and gave popular lectures to a broad audience in the evening. When Alexander the Great died in 323 B.C.E., a backlash against anything related to Alexander led to trumped-up charges of impiety against Aristotle. Aristotle fled to Chalcis to avoid prosecution. He only lived one year in Chalcis, dying of a stomach ailment in 322 B.C.E. Aristotle wrote three types of works: those written for a popular audience, compilations of scientific facts, and systematic treatises. The systematic treatises included works on logic, philosophy, psychology, physics, and natural history. Aristotle’s writings were preserved by a student and were hidden in a vault where a wealthy book collector discovered them about 200 years later. They were taken to Rome, where they were studied by scholars and issued in new editions, preserving them for posterity. 1.1 Propositional Logic 3 Links is true, denoted by T, if it is a true proposition, and the truth value of a proposition is false, denoted by F, if it is a false proposition. Propositions that cannot be expressed in terms of simpler propositions are called atomic propositions. The area of logic that deals with propositions is called the propositional calculus or propositional logic. It was first developed systematically by the Greek philosopher Aristotle more than 2300 years ago. We now turn our attention to methods for producing new propositions from those that we already have. These methods were discussed by the English mathematician George Boole in 1854 in his book The Laws of Thought. Many mathematical statements are constructed by combining one or more propositions. New propositions, called compound propositions, are formed from existing propositions using logical operators. Definition 1 Let p be a proposition. The negation of p, denoted by ¬p (also denoted by p), is the statement “It is not the case that p.” The proposition ¬p is read “not p.” The truth value of the negation of p, ¬p, is the opposite of the truth value of p. Remark: The notation for the negation operator is not standardized. Although ¬p and p are the most common notations used in mathematics to express the negation of p, other notations you might see are ∼p, −p, p′, Np, and !p. EXAMPLE 3 Find the negation of the proposition Extra Examples “Michael’s PC runs Linux” and express this in simple English. Solution: The negation is “It is not the case that Michael’s PC runs Linux.” This negation can be more simply expressed as “Michael’s PC does not run Linux.” ◂ EXAMPLE 4 Find the negation of the proposition “Vandana’s smartphone has at least 32 GB of memory” and express this in simple English. Solution: The negation is “It is not the case that Vandana’s smartphone has at least 32 GB of memory.” This negation can also be expressed as “Vandana’s smartphone does not have at least 32 GB of memory” or even more simply as “Vandana’s smartphone has less than 32 GB of memory.” ◂ 4 1 / The Foundations: Logic and Proofs TABLE 1 The Truth Table for the Negation of a Proposition. p ¬p T F F T Table 1 displays the truth table for the negation of a proposition p. This table has a row for each of the two possible truth values of p. Each row shows the truth value of ¬p corresponding to the truth value of p for this row. The negation of a proposition can also be considered the result of the operation of the negation operator on a proposition. The negation operator constructs a new proposition from a single existing proposition. We will now introduce the logical operators that are used to form new propositions from two or more existing propositions. These logical operators are also called connectives. Definition 2 Let p and q be propositions. The conjunction of p and q, denoted by p ∧ q, is the proposition “p and q.” The conjunction p ∧ q is true when both p and q are true and is false otherwise. Table 2 displays the truth table of p ∧ q. This table has a row for each of the four possible combinations of truth values of p and q. The four rows correspond to the pairs of truth values TT, TF, FT, and FF, where the first truth value in the pair is the truth value of p and the second truth value is the truth value of q. Note that in logic the word “but” sometimes is used instead of “and” in a conjunction. For example, the statement “The sun is shining, but it is raining” is another way of saying “The sun is shining and it is raining.” (In natural language, there is a subtle difference in meaning between “and” and “but”; we will not be concerned with this nuance here.) EXAMPLE 5 Find the conjunction of the propositions p and q where p is the proposition “Rebecca’s PC has more than 16 GB free hard disk space” and q is the proposition “The processor in Rebecca’s PC runs faster than 1 GHz.” Solution: The conjunction of these propositions, p ∧ q, is the proposition “Rebecca’s PC has more than 16 GB free hard disk space, and the processor in Rebecca’s PC runs faster than 1 GHz.” This conjunction can be expressed more simply as “Rebecca’s PC has more than 16 GB free hard disk space, and its processor runs faster than 1 GHz.” For this conjunction to be true, both conditions given must be true. It is false when one or both of these conditions are false. ◂ Definition 3 Let p and q be propositions. The disjunction of p and q, denoted by p ∨ q, is the proposition “p or q.” The disjunction p ∨ q is false when both p and q are false and is true otherwise. Table 3 displays the truth table for p ∨ q. TABLE 2 The Truth Table for the Conjunction of Two Propositions. p q p∧q T T T T F F F T F F F F TABLE 3 The Truth Table for the Disjunction of Two Propositions. p q p∨q T T T T F T F T T F F F 1.1 Propositional Logic 5 The use of the connective or in a disjunction corresponds to one of the two ways the word or is used in English, namely, as an inclusive or. A disjunction is true when at least one of the two propositions is true. That is, p ∨ q is true when both p and q are true or when exactly one of p and q is true. EXAMPLE 6 Translate the statement “Students who have taken calculus or introductory computer science can take this class” in a statement in propositional logic using the propositions p: “A student who has taken calculus can take this class” and q: “A student who has taken introductory computer science can take this class.” Solution: We assume that this statement means that students who have taken both calculus and introductory computer science can take the class, as well as the students who have taken only one of the two subjects. Hence, this statement can be expressed as p ∨ q, the inclusive or, or disjunction, of p and q. ◂ EXAMPLE 7 Extra Examples What is the disjunction of the propositions p and q, where p and q are the same propositions as in Example 5? Solution: The disjunction of p and q, p ∨ q, is the proposition “Rebecca’s PC has at least 16 GB free hard disk space, or the processor in Rebecca’s PC runs faster than 1 GHz.” This proposition is true when Rebecca’s PC has at least 16 GB free hard disk space, when the PC’s processor runs faster than 1 GHz, and when both conditions are true. It is false when both of these conditions are false, that is, when Rebecca’s PC has less than 16 GB free hard disk space and the processor in her PC runs at 1 GHz or slower. ◂ Besides its use in disjunctions, the connective or is also used to express an exclusive or. Unlike the disjunction of two propositions p and q, the exclusive or of these two propositions is true when exactly one of p and q is true; it is false when both p and q are true (and when both are false). Definition 4 Let p and q be propositions. The exclusive or of p and q, denoted by p ⊕ q (or p XOR q), is the proposition that is true when exactly one of p and q is true and is false otherwise. Links GEORGE BOOLE (1815–1864) George Boole, the son of a cobbler, was born in Lincoln, England, in November 1815. Because of his family’s difficult financial situation, Boole struggled to educate himself while supporting his family. Nevertheless, he became one of the most important mathematicians of the 1800s. Al- though he considered a career as a clergyman, he decided instead to go into teaching, and soon afterward opened a school of his own. In his preparation for teaching mathematics, Boole—unsatisfied with textbooks of his day—decided to read the works of the great mathematicians. While reading papers of the great French mathematician Lagrange, Boole made discoveries in the calculus of variations, the branch of analysis dealing with finding curves and surfaces by optimizing certain parameters. Source: Library of Congress In 1848 Boole published The Mathematical Analysis of Logic, the first of his contributions to Washington, D.C. 20540 symbolic logic. In 1849 he was appointed professor of mathematics at Queen’s College in Cork, USA [LC-USZ62-61664] Ireland. In 1854 he published The Laws of Thought, his most famous work. In this book, Boole introduced what is now called Boolean algebra in his honor. Boole wrote textbooks on differential equations and on difference equations that were used in Great Britain until the end of the nineteenth century. Boole married in 1855; his wife was the niece of the professor of Greek at Queen’s College. In 1864 Boole died from pneumonia, which he contracted as a result of keeping a lecture engagement even though he was soaking wet from a rainstorm. 6 1 / The Foundations: Logic and Proofs The truth table for the exclusive or of two propositions is displayed in Table 4. EXAMPLE 8 Let p and q be the propositions that state “A student can have a salad with dinner” and “A student can have soup with dinner,” respectively. What is p ⊕ q, the exclusive or of p and q? Solution: The exclusive or of p and q is the statement that is true when exactly one of p and q is true. That is, p ⊕ q is the statement “A student can have soup or salad, but not both, with dinner.” Note that this is often stated as “A student can have soup or a salad with dinner,” without explicitly stating that taking both is not permitted. ◂ EXAMPLE 9 Express the statement “I will use all my savings to travel to Europe or to buy an electric car” in propositional logic using the statement p: “I will use all my savings to travel to Europe” and the statement q: “I will use all my savings to buy an electric car.” Solution: To translate this statement, we first note that the or in this statement must be an ex- clusive or because this student can either use all his or her savings to travel to Europe or use all these savings to buy an electric car, but cannot both go to Europe and buy an electric car. (This is clear because either option requires all his savings.) Hence, this statement can be expressed as p ⊕ q. ◂ 1.1.3 Conditional Statements We will discuss several other important ways in which propositions can be combined. Definition 5 Let p and q be propositions. The conditional statement p → q is the proposition “if p, then q.” The conditional statement p → q is false when p is true and q is false, and true otherwise. In the conditional statement p → q, p is called the hypothesis (or antecedent or premise) and q is called the conclusion (or consequence). Assessment The statement p → q is called a conditional statement because p → q asserts that q is true on the condition that p holds. A conditional statement is also called an implication. The truth table for the conditional statement p → q is shown in Table 5. Note that the statement p → q is true when both p and q are true and when p is false (no matter what truth value q has). TABLE 4 The Truth Table for the Exclusive Or of Two Propositions. p q p⊕q T T F T F T F T T F F F TABLE 5 The Truth Table for the Conditional Statement p → q. p q p→q T T T T F F F T T F F T 1.1 Propositional Logic 7 You might have trouble understanding how “unless” is used in conditional statements unless you read this paragraph carefully. Because conditional statements play such an essential role in mathematical reasoning, a variety of terminology is used to express p → q. You will encounter most if not all of the following ways to express this conditional statement: “if p, then q” “if p, q” “p is sufficient for q” “q if p” “q when p” “a necessary condition for p is q” “q unless ¬p” “p implies q” “p only if q” “a sufficient condition for q is p” “q whenever p” “q is necessary for p” “q follows from p” “q provided that p” A useful way to understand the truth value of a conditional statement is to think of an obligation or a contract. For example, the pledge many politicians make when running for office is “If I am elected, then I will lower taxes.” If the politician is elected, voters would expect this politician to lower taxes. Furthermore, if the politician is not elected, then voters will not have any expectation that this person will lower taxes, although the person may have sufficient influence to cause those in power to lower taxes. It is only when the politician is elected but does not lower taxes that voters can say that the politician has broken the campaign pledge. This last scenario corresponds to the case when p is true but q is false in p → q. Similarly, consider a statement that a professor might make: “If you get 100% on the final, then you will get an A.” If you manage to get 100% on the final, then you would expect to receive an A. If you do not get 100%, you may or may not receive an A depending on other factors. However, if you do get 100%, but the professor does not give you an A, you will feel cheated. Remark: Because some of the different ways to express the implication p implies q can be confusing, we will provide some extra guidance. To remember that “p only if q” expresses the same thing as “if p, then q,” note that “p only if q” says that p cannot be true when q is not true. That is, the statement is false if p is true, but q is false. When p is false, q may be either true or false, because the statement says nothing about the truth value of q. For example, suppose your professor tells you “You can receive an A in the course only if your score on the final is at least 90%.” Then, if you receive an A in the course, then you know that your score on the final is at least 90%. If you do not receive an A, you may or may not have scored at least 90% on the final. Be careful not to use “q only if p” to express p → q because this is incorrect. The word “only” plays an essential role here. To see this, note that the truth values of “q only if p” and p → q are different when p and q have different truth values. To see why “q is necessary for p” is equivalent to “if p, then q,” observe that “q is necessary for p” means that p cannot be true unless q is true, or that if q is false, then p is false. This is the same as saying that if p is true, then q is true. To see why “p is sufficient for q” is equivalent to “if p, then q,” note that “p is sufficient for q” means if p is true, it must be the case that q is also true. This is the same as saying that if p is true, then q is also true. To remember that “q unless ¬p” expresses the same conditional statement as “if p, then q,” note that “q unless ¬p” means that if ¬p is false, then q must be true. That is, the statement “q unless ¬p” is false when p is true but q is false, but it is true otherwise. Consequently, “q unless ¬p” and p → q always have the same truth value. 8 1 / The Foundations: Logic and Proofs We illustrate the translation between conditional statements and English statements in Example 10. EXAMPLE 10 Extra Examples Let p be the statement “Maria learns discrete mathematics” and q the statement “Maria will find a good job.” Express the statement p → q as a statement in English. Solution: From the definition of conditional statements, we see that when p is the statement “Maria learns discrete mathematics” and q is the statement “Maria will find a good job,” p → q represents the statement “If Maria learns discrete mathematics, then she will find a good job.” There are many other ways to express this conditional statement in English. Among the most natural of these are “Maria will find a good job when she learns discrete mathematics.” “For Maria to get a good job, it is sufficient for her to learn discrete mathematics.” and “Maria will find a good job unless she does not learn discrete mathematics.” ◂ Note that the way we have defined conditional statements is more general than the meaning attached to such statements in the English language. For instance, the conditional statement in Example 10 and the statement “If it is sunny, then we will go to the beach” are statements used in normal language where there is a relationship between the hypothesis and the conclusion. Further, the first of these statements is true unless Maria learns discrete mathematics, but she does not get a good job, and the second is true unless it is indeed sunny, but we do not go to the beach. On the other hand, the statement “If Juan has a smartphone, then 2 + 3 = 5” is true from the definition of a conditional statement, because its conclusion is true. (The truth value of the hypothesis does not matter then.) The conditional statement “If Juan has a smartphone, then 2 + 3 = 6” is true if Juan does not have a smartphone, even though 2 + 3 = 6 is false. We would not use these last two conditional statements in natural language (except perhaps in sarcasm), because there is no relationship between the hypothesis and the conclusion in either statement. In mathematical reasoning, we consider conditional statements of a more general sort than we use in English. The mathematical concept of a conditional statement is independent of a cause-andeffect relationship between hypothesis and conclusion. Our definition of a conditional statement specifies its truth values; it is not based on English usage. Propositional language is an artificial language; we only parallel English usage to make it easy to use and remember. The if-then construction used in many programming languages is different from that used in logic. Most programming languages contain statements such as if p then S, where p is a proposition and S is a program segment (one or more statements to be executed). (Although this looks as if it might be a conditional statement, S is not a proposition, but rather is a set of executable instructions.) When execution of a program encounters such a statement, S is executed if p is true, but S is not executed if p is false, as illustrated in Example 11. 1.1 Propositional Logic 9 EXAMPLE 11 What is the value of the variable x after the statement if 2 + 2 = 4 then x := x + 1 if x = 0 before this statement is encountered? (The symbol := stands for assignment. The statement x := x + 1 means the assignment of the value of x + 1 to x.) Solution: Because 2 + 2 = 4 is true, the assignment statement x := x + 1 is executed. Hence, x has the value 0 + 1 = 1 after this statement is encountered. ◂ Remember that the contrapositive, but neither the converse or inverse, of a conditional statement is equivalent to it. CONVERSE, CONTRAPOSITIVE, AND INVERSE We can form some new conditional statements starting with a conditional statement p → q. In particular, there are three related conditional statements that occur so often that they have special names. The proposition q → p is called the converse of p → q. The contrapositive of p → q is the proposition ¬q → ¬p. The proposition ¬p → ¬q is called the inverse of p → q. We will see that of these three conditional statements formed from p → q, only the contrapositive always has the same truth value as p → q. We first show that the contrapositive, ¬q → ¬p, of a conditional statement p → q always has the same truth value as p → q. To see this, note that the contrapositive is false only when ¬p is false and ¬q is true, that is, only when p is true and q is false. We now show that neither the converse, q → p, nor the inverse, ¬p → ¬q, has the same truth value as p → q for all possible truth values of p and q. Note that when p is true and q is false, the original conditional statement is false, but the converse and the inverse are both true. When two compound propositions always have the same truth values, regardless of the truth values of its propositional variables, we call them equivalent. Hence, a conditional statement and its contrapositive are equivalent. The converse and the inverse of a conditional statement are also equivalent, as the reader can verify, but neither is equivalent to the original conditional statement. (We will study equivalent propositions in Section 1.3.) Take note that one of the most common logical errors is to assume that the converse or the inverse of a conditional statement is equivalent to this conditional statement. We illustrate the use of conditional statements in Example 12. EXAMPLE 12 Find the contrapositive, the converse, and the inverse of the conditional statement Extra Examples “The home team wins whenever it is raining.” Solution: Because “q whenever p” is one of the ways to express the conditional statement p → q, the original statement can be rewritten as “If it is raining, then the home team wins.” Consequently, the contrapositive of this conditional statement is “If the home team does not win, then it is not raining.” The converse is “If the home team wins, then it is raining.” The inverse is “If it is not raining, then the home team does not win.” Only the contrapositive is equivalent to the original statement. ◂ 10 1 / The Foundations: Logic and Proofs TABLE 6 The Truth Table for the Biconditional p ↔ q. p q p↔q T T T T F F F T F F F T BICONDITIONALS We now introduce another way to combine propositions that expresses that two propositions have the same truth value. Definition 6 Let p and q be propositions. The biconditional statement p ↔ q is the proposition “p if and only if q.” The biconditional statement p ↔ q is true when p and q have the same truth values, and is false otherwise. Biconditional statements are also called bi-implications. The truth table for p ↔ q is shown in Table 6. Note that the statement p ↔ q is true when both the conditional statements p → q and q → p are true and is false otherwise. That is why we use the words “if and only if” to express this logical connective and why it is symbolically written by combining the symbols → and ←. There are some other common ways to express p ↔ q: “p is necessary and sufficient for q” “if p then q, and conversely” “p iff q.” “p exactly when q.” The last way of expressing the biconditional statement p ↔ q uses the abbreviation “iff” for “if and only if.” Note that p ↔ q has exactly the same truth value as (p → q) ∧ (q → p). EXAMPLE 13 Extra Examples Let p be the statement “You can take the flight,” and let q be the statement “You buy a ticket.” Then p ↔ q is the statement “You can take the flight if and only if you buy a ticket.” This statement is true if p and q are either both true or both false, that is, if you buy a ticket and can take the flight or if you do not buy a ticket and you cannot take the flight. It is false when p and q have opposite truth values, that is, when you do not buy a ticket, but you can take the flight (such as when you get a free trip) and when you buy a ticket but you cannot take the flight (such as when the airline bumps you). ◂ IMPLICIT USE OF BICONDITIONALS You should be aware that biconditionals are not always explicit in natural language. In particular, the “if and only if” construction used in biconditionals is rarely used in common language. Instead, biconditionals are often expressed using an “if, then” or an “only if” construction. The other part of the “if and only if” is implicit. That is, the converse is implied, but not stated. For example, consider the statement in English “If you finish your meal, then you can have dessert.” What is really meant is “You can have dessert if and only if you finish your meal.” This last statement is logically equivalent to the two statements “If you finish your meal, then you can have dessert” and “You can have dessert only if you finish your meal.” Because of this imprecision in natural language, we need to make an assumption whether a conditional statement in natural language implicitly includes its converse. Because precision is essential in mathematics and in logic, we will always distinguish between the conditional statement p → q and the biconditional statement p ↔ q. 1.1 Propositional Logic 11 1.1.4 Truth Tables of Compound Propositions Demo We have now introduced five important logical connectives—conjunction, disjunction, exclusive or, implication, and the biconditional operator—as well as negation. We can use these connectives to build up complicated compound propositions involving any number of propositional variables. We can use truth tables to determine the truth values of these compound propositions, as Example 14 illustrates. We use a separate column to find the truth value of each compound expression that occurs in the compound proposition as it is built up. The truth values of the compound proposition for each combination of truth values of the propositional variables in it is found in the final column of the table. EXAMPLE 14 Construct the truth table of the compound proposition (p ∨ ¬q) → (p ∧ q). Solution: Because this truth table involves two propositional variables p and q, there are four rows in this truth table, one for each of the pairs of truth values TT, TF, FT, and FF. The first two columns are used for the truth values of p and q, respectively. In the third column we find the truth value of ¬q, needed to find the truth value of p ∨ ¬q, found in the fourth column. The fifth column gives the truth value of p ∧ q. Finally, the truth value of (p ∨ ¬q) → (p ∧ q) is found in the last column. The resulting truth table is shown in Table 7. ◂ TABLE 7 The Truth Table of (p ∨ ¬ q) → (p ∧ q). p q ¬q p ∨ ¬q p∧q (p ∨ ¬q) → (p ∧ q) T T F T T T T F T T F F F T F F F T F F T T F F 1.1.5 Precedence of Logical Operators We can construct compound propositions using the negation operator and the logical operators defined so far. We will generally use parentheses to specify the order in which logical operators in a compound proposition are to be applied. For instance, (p ∨ q) ∧ (¬r) is the conjunction of p ∨ q and ¬r. However, to reduce the number of parentheses, we specify that the negation operator is applied before all other logical operators. This means that ¬p ∧ q is the conjunction of ¬p and q, namely, (¬p) ∧ q, not the negation of the conjunction of p and q, namely ¬(p ∧ q). (It TABLE 8 Precedence of Logical Operators. is generally the case that unary operators that involve only one object precede binary operators.) Another general rule of precedence is that the conjunction operator takes precedence over the disjunction operator, so that p ∨ q ∧ r means p ∨ (q ∧ r) rather than (p ∨ q) ∧ r and p ∧ q ∨ r means (p ∧ q) ∨ r rather than p ∧ (q ∨ r). Because this rule may be difficult to remember, we will Operator Precedence continue to use parentheses so that the order of the disjunction and conjunction operators is clear. Finally, it is an accepted rule that the conditional and biconditional operators, → and ↔, ¬ 1 have lower precedence than the conjunction and disjunction operators, ∧ and ∨. Consequently, ∧ 2 p → q ∨ r means p → (q ∨ r) rather than (p → q) ∨ r and p ∨ q → r means (p ∨ q) → r rather ∨ 3 than p ∨ (q → r). We will use parentheses when the order of the conditional operator and bi- → ↔ 4 5 conditional operator is at issue, although the conditional operator has precedence over the biconditional operator. Table 8 displays the precedence levels of the logical operators, ¬, ∧, ∨, →, and ↔. 12 1 / The Foundations: Logic and Proofs Truth Value Bit T 1 F 0 Links 1.1.6 Logic and Bit Operations Computers represent information using bits. A bit is a symbol with two possible values, namely, 0 (zero) and 1 (one). This meaning of the word bit comes from binary digit, because zeros and ones are the digits used in binary representations of numbers. The well-known statistician John Tukey introduced this terminology in 1946. A bit can be used to represent a truth value, because there are two truth values, namely, true and false. As is customarily done, we will use a 1 bit to represent true and a 0 bit to represent false. That is, 1 represents T (true), 0 represents F (false). A variable is called a Boolean variable if its value is either true or false. Consequently, a Boolean variable can be represented using a bit. Computer bit operations correspond to the logical connectives. By replacing true by a one and false by a zero in the truth tables for the operators ∧, ∨, and ⊕, the columns in Table 9 for the corresponding bit operations are obtained. We will also use the notation OR, AND, and XOR for the operators ∨, ∧, and ⊕, as is done in various programming languages. TABLE 9 Table for the Bit Operators OR, AND, and XOR. x y x∨y x∧y x⊕y 0 0 0 0 0 0 1 1 0 1 1 0 1 0 1 1 1 1 1 0 Information is often represented using bit strings, which are lists of zeros and ones. When this is done, operations on the bit strings can be used to manipulate this information. Definition 7 A bit string is a sequence of zero or more bits. The length of this string is the number of bits in the string. EXAMPLE 15 101010011 is a bit string of length nine. ◂ Links JOHN WILDER TUKEY (1915–2000) Tukey, born in New Bedford, Massachusetts, was an only child. His parents, both teachers, decided home schooling would best develop his potential. His formal education began at Brown University, where he studied mathematics and chemistry. He received a master’s degree in chemistry from Brown and continued his studies at Princeton University, changing his field of study from chemistry to mathematics. He received his Ph.D. from Princeton in 1939 for work in topology, when he was appointed an instructor in mathematics at Princeton. With the start of World War II, he joined the Fire Control Research Office, where he began working in statistics. Tukey found statistical research to his liking and impressed several leading statisticians with his skills. In 1945, at the conclusion of the war, Tukey re- c Alfred Eisenstaedt/ turned to the mathematics department at Princeton as a professor of statistics, and he also took a position The LIFE Picture at AT&T Bell Laboratories. Tukey founded the Statistics Department at Princeton in 1966 and was its first Collection/Getty Images chairman. Tukey made significant contributions to many areas of statistics, including the analysis of variance, the estimation of spectra of time series, inferences about the values of a set of parameters from a single experiment, and the philos- ophy of statistics. However, he is best known for his invention, with J. W. Cooley, of the fast Fourier transform. In addition to his contributions to statistics, Tukey was noted as a skilled wordsmith; he is credited with coining the terms bit and software. Tukey contributed his insight and expertise by serving on the President’s Science Advisory Committee. He chaired several important committees dealing with the environment, education, and chemicals and health. He also served on committees working on nuclear disarmament. Tukey received many awards, including the National Medal of Science. HISTORICAL NOTE There were several other suggested words for a binary digit, including binit and bigit, that never were widely accepted. The adoption of the word bit may be due to its meaning as a common English word. For an account of Tukey’s coining of the word bit, see the April 1984 issue of Annals of the History of Computing. 1.1 Propositional Logic 13 We can extend bit operations to bit strings. We define the bitwise OR, bitwise AND, and bitwise XOR of two strings of the same length to be the strings that have as their bits the OR, AND, and XOR of the corresponding bits in the two strings, respectively. We use the symbols ∨, ∧, and ⊕ to represent the bitwise OR, bitwise AND, and bitwise XOR operations, respectively. We illustrate bitwise operations on bit strings with Example 16. EXAMPLE 16 Find the bitwise OR, bitwise AND, and bitwise XOR of the bit strings 01 1011 0110 and 11 0001 1101. (Here, and throughout this book, bit strings will be split into blocks of four bits to make them easier to read.) Exercises Solution: The bitwise OR, bitwise AND, and bitwise XOR of these strings are obtained by taking the OR, AND, and XOR of the corresponding bits, respectively. This gives us 01 1011 0110 11 0001 1101 11 1011 1111 bitwise OR 01 0001 0100 bitwise AND 10 1010 1011 bitwise XOR ◂ 1. Which of these sentences are propositions? What are the truth values of those that are propositions? a) Boston is the capital of Massachusetts. b) Miami is the capital of Florida. c) 2 + 3 = 5. d) 5 + 7 = 10. e) x + 2 = 11. f ) Answer this question. 2. Which of these are propositions? What are the truth values of those that are propositions? a) Do not pass go. b) What time is it? c) There are no black flies in Maine. d) 4 + x = 5. e) The moon is made of green cheese. f ) 2n ≥ 100. 3. What is the negation of each of these propositions? a) Linda is younger than Sanjay. b) Mei makes more money than Isabella. c) Moshe is taller than Monica. d) Abby is richer than Ricardo. 4. What is the negation of each of these propositions? a) Janice has more Facebook friends than Juan. b) Quincy is smarter than Venkat. c) Zelda drives more miles to school than Paola. d) Briana sleeps longer than Gloria. 5. What is the negation of each of these propositions? a) Mei has an MP3 player. b) There is no pollution in New Jersey. c) 2 + 1 = 3. d) The summer in Maine is hot and sunny. 6. What is the negation of each of these propositions? a) Jennifer and Teja are friends. b) There are 13 items in a baker’s dozen. c) Abby sent more than 100 text messages yesterday. d) 121 is a perfect square. 7. What is the negation of each of these propositions? a) Steve has more than 100 GB free disk space on his laptop. b) Zach blocks e-mails and texts from Jennifer. c) 7 ⋅ 11 ⋅ 13 = 999. d) Diane rode her bicycle 100 miles on Sunday. 8. Suppose that Smartphone A has 256 MB RAM and 32 GB ROM, and the resolution of its camera is 8 MP; Smartphone B has 288 MB RAM and 64 GB ROM, and the resolution of its camera is 4 MP; and Smartphone C has 128 MB RAM and 32 GB ROM, and the resolution of its camera is 5 MP. Determine the truth value of each of these propositions. a) Smartphone B has the most RAM of these three smartphones. b) Smartphone C has more ROM or a higher resolution camera than Smartphone B. c) Smartphone B has more RAM, more ROM, and a higher resolution camera than Smartphone A. d) If Smartphone B has more RAM and more ROM than Smartphone C, then it also has a higher resolution camera. e) Smartphone A has more RAM than Smartphone B if and only if Smartphone B has more RAM than Smartphone A. 9. Suppose that during the most recent fiscal year, the annual revenue of Acme Computer was 138 billion dollars and its net profit was 8 billion dollars, the annual revenue of Nadir Software was 87 billion dollars and its net profit was 5 billion dollars, and the annual revenue of Quixote Media was 111 billion dollars and its net profit was 13 billion dollars. Determine the truth value of each of these propositions for the most recent fiscal year. 14 1 / The Foundations: Logic and Proofs a) Quixote Media had the largest annual revenue. b) Nadir Software had the lowest net profit and Acme Computer had the largest annual revenue. c) Acme Computer had the largest net profit or Quixote Media had the largest net profit. d) If Quixote Media had the smallest net profit, then Acme Computer had the largest annual revenue. e) Nadir Software had the smallest net profit if and only if Acme Computer had the largest annual revenue. 10. Let p and q be the propositions p: I bought a lottery ticket this week. q: I won the million dollar jackpot. Express each of these propositions as an English sentence. a) ¬p d) p ∧ q b) p ∨ q e) p ↔ q c) p → q f ) ¬p → ¬q g) ¬p ∧ ¬q h) ¬p ∨ (p ∧ q) 11. Let p and q be the propositions “Swimming at the New Jersey shore is allowed” and “Sharks have been spotted near the shore,” respectively. Express each of these compound propositions as an English sentence. a) ¬q d) p → ¬q g) p ↔ ¬q b) p ∧ q c) ¬p ∨ q e) ¬q → p f ) ¬p → ¬q h) ¬p ∧ (p ∨ ¬q) 12. Let p and q be the propositions “The election is decided” and “The votes have been counted,” respectively. Express each of these compound propositions as an English sen- tence. a) ¬p c) ¬p ∧ q e) ¬q → ¬p g) p ↔ q b) p ∨ q d) q → p f ) ¬p → ¬q h) ¬q ∨ (¬p ∧ q) 13. Let p and q be the propositions p: It is below freezing. q: It is snowing. Write these propositions using p and q and logical con- nectives (including negations). a) It is below freezing and snowing. b) It is below freezing but not snowing. c) It is not below freezing and it is not snowing. d) It is either snowing or below freezing (or both). e) If it is below freezing, it is also snowing. f ) Either it is below freezing or it is snowing, but it is not snowing if it is below freezing. g) That it is below freezing is necessary and sufficient for it to be snowing. 14. Let p, q, and r be the propositions p: You have the flu. q: You miss the final examination. r: You pass the course. Express each of these propositions as an English sen- tence. a) p → q c) q → ¬r e) (p → ¬r) ∨ (q → ¬r) b) ¬q ↔ r d) p ∨ q ∨ r f ) (p ∧ q) ∨ (¬q ∧ r) 15. Let p and q be the propositions p: You drive over 65 miles per hour. q: You get a speeding ticket. Write these propositions using p and q and logical connectives (including negations). a) You do not drive over 65 miles per hour. b) You drive over 65 miles per hour, but you do not get a speeding ticket. c) You will get a speeding ticket if you drive over 65 miles per hour. d) If you do not drive over 65 miles per hour, then you will not get a speeding ticket. e) Driving over 65 miles per hour is sufficient for getting a speeding ticket. f ) You get a speeding ticket, but you do not drive over 65 miles per hour. g) Whenever you get a speeding ticket, you are driving over 65 miles per hour. 16. Let p, q, and r be the propositions p: You get an A on the final exam. q: You do every exercise in this book. r: You get an A in this class. Write these propositions using p, q, and r and logical connectives (including negations). a) You get an A in this class, but you do not do every exercise in this book. b) You get an A on the final, you do every exercise in this book, and you get an A in this class. c) To get an A in this class, it is necessary for you to get an A on the final. d) You get an A on the final, but you don’t do every exercise in this book; nevertheless, you get an A in this class. e) Getting an A on the final and doing every exercise in this book is sufficient for getting an A in this class. f ) You will get an A in this class if and only if you either do every exercise in this book or you get an A on the final. 17. Let p, q, and r be the propositions p: Grizzly bears have been seen in the area. q: Hiking is safe on the trail. r: Berries are ripe along the trail. Write these propositions using p, q, and r and logical connectives (including negations). a) Berries are ripe along the trail, but grizzly bears have not been seen in the area. b) Grizzly bears have not been seen in the area and hiking on the trail is safe, but berries are ripe along the trail. c) If berries are ripe along the trail, hiking is safe if and only if grizzly bears have not been seen in the area. d) It is not safe to hike on the trail, but grizzly bears have not been seen in the area and the berries along the trail are ripe. e) For hiking on the trail to be safe, it is necessary but not sufficient that berries not be ripe along the trail and for grizzly bears not to have been seen in the area. f ) Hiking is not safe on the trail whenever grizzly bears have been seen in the area and berries are ripe along the trail. 18. Determine whether these biconditionals are true or false. a) 2 + 2 = 4 if and only if 1 + 1 = 2. b) 1 + 1 = 2 if and only if 2 + 3 = 4. c) 1 + 1 = 3 if and only if monkeys can fly. d) 0 > 1 if and only if 2 > 1. 19. Determine whether each of these conditional statements is true or false. a) If 1 + 1 = 2, then 2 + 2 = 5. b) If 1 + 1 = 3, then 2 + 2 = 4. c) If 1 + 1 = 3, then 2 + 2 = 5. d) If monkeys can fly, then 1 + 1 = 3. 20. Determine whether each of these conditional statements is true or false. a) If 1 + 1 = 3, then unicorns exist. b) If 1 + 1 = 3, then dogs can fly. c) If 1 + 1 = 2, then dogs can fly. d) If 2 + 2 = 4, then 1 + 2 = 3. 21. For each of these sentences, determine whether an inclusive or, or an exclusive or, is intended. Explain your answer. a) Coffee or tea comes with dinner. b) A password must have at least three digits or be at least eight characters long. c) The prerequisite for the course is a course in number theory or a course in cryptography. d) You can pay using U.S. dollars or euros. 22. For each of these sentences, determine whether an inclusive or, or an exclusive or, is intended. Explain your answer. a) Experience with C++ or Java is required. b) Lunch includes soup or salad. c) To enter the country you need a passport or a voter registration card. d) Publish or perish. 23. For each of these sentences, state what the sentence means if the logical connective or is an inclusive or (that is, a disjunction) versus an exclusive or. Which of these meanings of or do you think is intended? a) To take discrete mathematics, you must have taken calculus or a course in computer science. b) When you buy a new car from Acme Motor Company, you get $2000 back in cash or a 2% car loan. c) Dinner for two includes two items from column A or three items from column B. d) School is closed if more than two feet of snow falls or if the wind chill is below −100 ◦F. 24. Write each of these statements in the form “if p, then q” in English. [Hint: Refer to the list of common ways to express conditional statements provided in this section.] a) It is necessary to wash the boss’s car to get promoted. b) Winds from the south imply a spring thaw. 1.1 Propositional Logic 15 c) A sufficient condition for the warranty to be good is that you bought the computer less than a year ago. d) Willy gets caught whenever he cheats. e) You can access the website only if you pay a subscrip- tion fee. f ) Getting elected follows from knowing the right people. g) Carol gets seasick whenever she is on a boat. 25. Write each of these statements in the form “if p, then q” in English. [Hint: Refer to the list of common ways to express conditional statements.] a) It snows whenever the wind blows from the northeast. b) The apple trees will bloom if it stays warm for a week. c) That the Pistons win the championship implies that they beat the Lakers. d) It is necessary to walk eight miles to get to the top of Long’s Peak. e) To get tenure as a professor, it is sufficient to be world famous. f ) If you drive more than 400 miles, you will need to buy gasoline. g) Your guarantee is good only if you bought your CD player less than 90 days ago. h) Jan will go swimming unless the water is too cold. i) We will have a future, provided that people believe in science. 26. Write each of these statements in the form “if p, then q” in English. [Hint: Refer to the list of common ways to express conditional statements provided in this section.] a) I will remember to send you the address only if you send me an e-mail message. b) To be a citizen of this country, it is sufficient that you were born in the United States. c) If you keep your textbook, it will be a useful reference in your future courses. d) The Red Wings will win the Stanley Cup if their goalie plays well. e) That you get the job implies that you had the best credentials. f ) The beach erodes whenever there is a storm. g) It is necessary to have a valid password to log on to the server. h) You will reach the summit unless you begin your climb too late. i) You will get a free ice cream cone, provided that you are among the first 100 customers tomorrow. 27. Write each of these propositions in the form “p if and only if q” in English. a) If it is hot outside you buy an ice cream cone, and if you buy an ice cream cone it is hot outside. b) For you to win the contest it is necessary and sufficient that you have the only winning ticket. c) You get promoted only if you have connections, and you have connections only if you get promoted. d) If you watch television your mind will decay, and conversely. e) The trains run late on exactly those days when I take it. 16 1 / The Foundations: Logic and Proofs 28. Write each of these propositions in the form “p if and only if q” in English. a) For you to get an A in this course, it is necessary and sufficient that you learn how to solve discrete mathe- matics problems. b) If you read the newspaper every day, you will be in- formed, and conversely. c) It rains if it is a weekend day, and it is a weekend day if it rains. d) You can see the wizard only if the wizard is not in, and the wizard is not in only if you can see him. e) My airplane flight is late exactly when I have to catch a connecting flight. 29. State the converse, contrapositive, and inverse of each of these conditional statements. a) If it snows today, I will ski tomorrow. b) I come to class whenever there is going to be a quiz. c) A positive integer is a prime only if it has no divisors other than 1 and itself. 30. State the converse, contrapositive, and inverse of each of these conditional statements. a) If it snows tonight, then I will stay at home. b) I go to the beach whenever it is a sunny summer day. c) When I stay up late, it is necessary that I sleep until noon. 31. How many rows appear in a truth table for each of these compound propositions? a) p → ¬p b) (p ∨ ¬r) ∧ (q ∨ ¬s) c) q ∨ p ∨ ¬s ∨ ¬r ∨ ¬t ∨ u d) (p ∧ r ∧ t) ↔ (q ∧ t) 32. How many rows appear in a truth table for each of these compound propositions? a) (q → ¬p) ∨ (¬p → ¬q) b) (p ∨ ¬t) ∧ (p ∨ ¬s) c) (p → r) ∨ (¬s → ¬t) ∨ (¬u → v) d) (p ∧ r ∧ s) ∨ (q ∧ t) ∨ (r ∧ ¬t) 33. Construct a truth table for each of these compound propo- sitions. a) p ∧ ¬p c) (p ∨ ¬q) → q e) (p → q) ↔ (¬q → ¬p) f ) (p → q) → (q → p) b) p ∨ ¬p d) (p ∨ q) → (p ∧ q) 34. Construct a truth table for each of these compound propo- sitions. a) p → ¬p c) p ⊕ (p ∨ q) e) (q → ¬p) ↔ (p ↔ q) f ) (p ↔ q) ⊕ (p ↔ ¬q) b) p ↔ ¬p d) (p ∧ q) → (p ∨ q) 35. Construct a truth table for each of these compound propo- sitions. a) (p ∨ q) → (p ⊕ q) c) (p ∨ q) ⊕ (p ∧ q) e) (p ↔ q) ⊕ (¬p ↔ ¬r) f ) (p ⊕ q) → (p ⊕ ¬q) b) (p ⊕ q) → (p ∧ q) d) (p ↔ q) ⊕ (¬p ↔ q) 36. Construct a truth table for each of these compound propositions. a) p ⊕ p c) p ⊕ ¬q e) (p ⊕ q) ∨ (p ⊕ ¬q) b) p ⊕ ¬p d) ¬p ⊕ ¬q f ) (p ⊕ q) ∧ (p ⊕ ¬q) 37. Construct a truth table for each of these compound propositions. a) p → ¬q c) (p → q) ∨ (¬p → q) e) (p ↔ q) ∨ (¬p ↔ q) f ) (¬p ↔ ¬q) ↔ (p ↔ q) b) ¬p ↔ q d) (p → q) ∧ (¬p → q) 38. Construct a truth table for each of these compound propositions. a) (p ∨ q) ∨ r c) (p ∧ q) ∨ r e) (p ∨ q) ∧ ¬r b) (p ∨ q) ∧ r d) (p ∧ q) ∧ r f ) (p ∧ q) ∨ ¬r 39. Construct a truth table for each of these compound propositions. a) p → (¬q ∨ r) b) ¬p → (q → r) c) (p → q) ∨ (¬p → r) d) (p → q) ∧ (¬p → r) e) (p ↔ q) ∨ (¬q ↔ r) f ) (¬p ↔ ¬q) ↔ (q ↔ r) 40. Construct a truth table for ((p → q) → r) → s. 41. Construct a truth table for (p ↔ q) ↔ (r ↔ s). 42. Explain, without using a truth table, why (p ∨ ¬q) ∧ (q ∨ ¬r) ∧ (r ∨ ¬p) is true when p, q, and r have the same truth value and it is false otherwise. 43. Explain, without using a truth table, why (p ∨ q ∨ r) ∧ (¬p ∨ ¬q ∨ ¬r) is true when at least one of p, q, and r is true and at least one is false, but is false when all three variables have the same truth value. 44. If p1, p2, … , pn are n propositions, explain why ⋀ n−1 ⋀n (¬pi ∨ ¬pj) i=1 j=i+1 is true if and only if at most one of p1, p2, … , pn is true. 45. Use Exercise 44 to construct a compound proposition that is true if and only if exactly one of the proposi- tions p1, p2, … , pn is true. [Hint: Combine the compound proposition in Exercise 44 and a compound proposition that is true if and only if at least one of p1, p2, … , pn is true.] 46. What is the value of x after each of these statements is encountered in a computer program, if x = 1 before the statement is reached? a) if x + 2 = 3 then x := x + 1 b) if (x + 1 = 3) OR (2x + 2 = 3) then x := x + 1 c) if (2x + 3 = 5) AND (3x + 4 = 7) then x := x + 1 d) if (x + 1 = 2) XOR (x + 2 = 3) then x := x + 1 e) if x < 2 then x := x + 1 47. Find the bitwise OR, bitwise AND, and bitwise XOR of each of these pairs of bit strings. a) 101 1110, 010 0001 b) 1111 0000, 1010 1010 c) 00 0111 0001, 10 0100 1000 d) 11 1111 1111, 00 0000 0000 1.2 Applications of Propositional Logic 17 48. Evaluate each of these expressions. a) 1 1000 ∧ (0 1011 ∨ 1 1011) b) (0 1111 ∧ 1 0101) ∨ 0 1000 c) (0 1010 ⊕ 1 1011) ⊕ 0 1000 d) (1 1011 ∨ 0 1010) ∧ (1 0001 ∨ 1 1011) Fuzzy logic is used in artificial intelligence. In fuzzy logic, a proposition has a truth value that is a number between 0 and 1, inclusive. A proposition with a truth value of 0 is false and one with a truth value of 1 is true. Truth values that are between 0 and 1 indicate varying degrees of truth. For instance, the truth value 0.8 can be assigned to the statement “Fred is happy,” because Fred is happy most of the time, and the truth value 0.4 can be assigned to the statement “John is happy,” because John is happy slightly less than half the time. Use these truth values to solve Exercises 49–51. 49. The truth value of the negation of a proposition in fuzzy logic is 1 minus the truth value of the proposition. What are the truth values of the statements “Fred is not happy” and “John is not happy”? 50. The truth value of the conjunction of two propositions in fuzzy logic is the minimum of the truth values of the two propositions. What are the truth values of the statements “Fred and John are happy” and “Neither Fred nor John is happy”? 51. The truth value of the disjunction of two propositions in fuzzy logic is the maximum of the truth values of the two propositions. What are the truth values of the statements “Fred is happy, or John is happy” and “Fred is not happy, or John is not happy”? ∗ 52. Is the assertion “This statement is false” a proposition? ∗ 53. The nth statement in a list of 100 statements is “Exactly n of the statements in this list are false.” a) What conclusions can you draw from these statements? b) Answer part (a) if the nth statement is “At least n of the statements in this list are false.” c) Answer part (b) assuming that the list contains 99 statements. 54. An ancient Sicilian legend says that the barber in a remote town who can be reached only by traveling a dangerous mountain road shaves those people, and only those people, who do not shave themselves. Can there be such a barber? 1.2 Applications of Propositional Logic 1.2.1 Introduction Logic has many important applications to mathematics, computer science, and numerous other disciplines. Statements in mathematics and the sciences and in natural language often are imprecise or ambiguous. To make such statements precise, they can be translated into the language of logic. For example, logic is used in the specification of software and hardware, because these specifications need to be precise before development begins. Furthermore, propositional logic and its rules can be used to design computer circuits, to construct computer programs, to verify the correctness of programs, and to build expert systems. Logic can be used to analyze and solve many familiar puzzles. Software systems based on the rules of logic have been developed for constructing some, but not all, types of proofs automatically. We will discuss some of these applications of propositional logic in this section and in later chapters. 1.2.2 Translating English Sentences There are many reasons to translate English sentences into expressions involving propositional variables and logical connectives. In particular, English (and every other human language) is often ambiguous. Translating sentences into compound statements (and other types of logical expressions, which we will introduce later in this chapter) removes the ambiguity. Note that this may involve making a set of reasonable assumptions based on the intended meaning of the sentence. Moreover, once we have translated sentences from English into logical expressions, we can analyze these logical expressions to determine their truth values, we can manipulate them, and we can use rules of inference (which are discussed in Section 1.6) to reason about them. To illustrate the process of translating an English sentence into a logical expression, consider Examples 1 and 2. 18 1 / The Foundations: Logic and Proofs EXAMPLE 1 How can this English sentence be translated into a logical expression? Extra Examples “You can access the Internet from campus only if you are a computer science major or you are not a freshman.” Solution: There are many ways to translate this sentence into a logical expression. Although it is possible to represent the sentence by a single propositional variable, such as p, this would not be useful when analyzing its meaning or reasoning with it. Instead, we will use propositional variables to represent each sentence part and determine the appropriate logical connectives between them. In particular, we let a, c, and f represent “You can access the Internet from campus,” “You are a computer science major,” and “You are a freshman,” respectively. Noting that “only if” is one way a conditional statement can be expressed, this sentence can be represented as a → (c ∨ ¬f ). ◂ EXAMPLE 2 How can this English sentence be translated into a logical expression? “You cannot ride the roller coaster if you are under 4 feet tall unless you are older than 16 years old.” Solution: Let q, r, and s represent “You can ride the roller coaster,” “You are under 4 feet tall,” and “You are older than 16 years old,” respectively. Then the sentence can be translated to (r ∧ ¬s) → ¬q. There are other ways to represent the original sentence as a logical expression, but the one we have used should meet our needs. ◂ 1.2.3 System Specifications Translating sentences in natural language (such as English) into logical expressions is an essential part of specifying both hardware and software systems. System and software engineers take requirements in natural language and produce precise and unambiguous specifications that can be used as the basis for system development. Example 3 shows how compound propositions can be used in this process. EXAMPLE 3 Extra Examples Express the specification “The automated reply cannot be sent when the file system is full” using logical connectives. Solution: One way to translate this is to let p denote “The automated reply can be sent” and q de- note “The file system is full.” Then ¬p represents “It is not the case that the automated reply can be sent,” which can also be expressed as “The automated reply cannot be sent.” Consequently, our specification can be represented by the conditional statement q → ¬p. ◂ System specifications should be consistent, that is, they should not contain conflicting requirements that could be used to derive a contradiction. When specifications are not consistent, there would be no way to develop a system that satisfies all specifications. EXAMPLE 4 Determine whether these system specifications are consistent: “The diagnostic message is stored in the buffer or it is retransmitted.” “The diagnostic message is not stored in the buffer.” “If the diagnostic message is stored in the buffer, then it is retransmitted.” 1.2 Applications of Propositional Logic 19 Solution: To determine whether these specifications are consistent, we first express them using logical expressions. Let p denote “The diagnostic message is stored in the buffer” and let q denote “The diagnostic message is retransmitted.” The specifications can then be written as p ∨ q, ¬p, and p → q. An assignment of truth values that makes all three specifications true must have p false to make ¬p true. Because we want p ∨ q to be true but p must be false, q must be true. Because p → q is true when p is false and q is true, we conclude that these specifications are consistent, because they are all true when p is false and q is true. We could come to the same conclusion by use of a truth table to examine the four possible assignments of truth values to p and q. ◂ EXAMPLE 5 Do the system specifications in Example 4 remain consistent if the specification “The diagnostic message is not retransmitted” is added? Solution: By the reasoning in Example 4, the three specifications from that example are true only in the case when p is false and q is true. However, this new specification is ¬q, which is false when q is true. Consequently, these four specifications are inconsistent. ◂ 1.2.4 Boolean Searches Links Logical connectives are used extensively in searches of large collections of information, such as indexes of Web pages. Because these searches employ techniques from propositional logic, they are called Boolean searches. In Boolean searches, the connective AND is used to match records that contain both of two search terms, the connective OR is used to match one or both of two search terms, and the connective NOT (sometimes written as AND NOT ) is used to exclude a particular search term. Careful planning of how logical connectives are used is often required when Boolean searches are used to locate information of potential interest. Example 6 illustrates how Boolean searches are carried out. EXAMPLE 6 Extra Examples Web Page Searching Most Web search engines support Boolean searching techniques, which is useful for finding Web pages about particular subjects. For instance, using Boolean searching to find Web pages about universities in New Mexico, we can look for pages matching NEW AND MEXICO AND UNIVERSITIES. The results of this search will include those pages that contain the three words NEW, MEXICO, and UNIVERSITIES. This will include all of the pages of interest, together with others such as a page about new universities in Mexico. (Note that Google, and many other search engines, do require the use of “AND” because such search engines use all search terms by default.) Most search engines support the use of quotation marks to search for specific phrases. So, it may be more effective to search for pages matching “NEW MEXICO” AND UNIVERSITIES. Next, to find pages that deal with universities in New Mexico or Arizona, we can search for pages matching (NEW AND MEXICO OR ARIZONA) AND UNIVERSITIES. (Note: Here the AND operator takes precedence over the OR operator. Also, in Google, the terms used for this search would be NEW MEXICO OR ARIZONA.) The results of this search will include all pages that contain the word UNIVERSITIES and either both the words NEW and MEXICO or the word ARIZONA. Again, pages besides those of interest will be listed. Finally, to find Web pages that deal with universities in Mexico (and not New Mexico), we might first look for pages matching MEXICO AND UNIVERSITIES, but because the results of this search will include pages about universities in New Mexico, as well as universities in Mexico, it might be better to search for pages matching (MEXICO AND UNIVERSITIES) NOT NEW. The results of this search include pages that contain both the words MEXICO and UNIVERSITIES but do not contain the word NEW. (In Google, and many other search engines, the word “NOT” is 20 1 / The Foundations: Logic and Proofs replaced by the symbol “-”. In Google, the terms used for this last search would be MEXICO UNIVERSITIES -NEW.) ◂ Links 1.2.5 Logic Puzzles Puzzles that can be solved using logical reasoning are known as logic puzzles. Solving logic puzzles is an excellent way to practice working with the rules of logic. Also, computer programs designed to carry out logical reasoning often use well-known logic puzzles to illustrate their capabilities. Many people enjoy solving logic puzzles, published in periodicals, books, and on the Web, as a recreational activity. The next three examples present logic puzzles, in increasing level of difficulty. Many others can be found in the exercises. In Section 1.3 we will discuss the n-queens puzzle and the game of Sudoku. EXAMPLE 7 As a reward for saving his daughter from pirates, the King has given you the opportunity to win a treasure hidden inside one of three trunks. The two trunks that do not hold the treasure are empty. To win, you must select the correct trunk. Trunks 1 and 2 are each inscribed with the message “This trunk is empty,” and Trunk 3 is inscribed with the message “The treasure is in Trunk 2.” The Queen, who never lies, tells you that only one of these inscriptions is true, while the other two are wrong. Which trunk should you select to win? Solution: Let pi be the proposition that the treasure is in Trunk i, for i = 1, 2, 3. To translate into propositional logic the Queen’s statement that exactly one of the inscriptions is true, we observe that the inscriptions on Trunk 1, Trunk 2, and Trunk 3, are ¬p1, ¬p2, and p2, respectively. So, her statement can be translated to (¬p1 ∧ ¬(¬p2) ∧ ¬p2) ∨ (¬(¬p1) ∧ ¬p2 ∧ ¬p2) ∨ (¬(¬p1) ∧ ¬(¬p2) ∧ p2)). Using the rules for propositional logic, we see that this is equivalent to (p1 ∧ ¬p2) ∨ (p1 ∧ p2). By the distributive law, (p1 ∧ ¬p2) ∨ (p1 ∧ p2) is equivalent to p1 ∧ (¬p2 ∨ p2). But because ¬p2 ∨ p2 must be true, this is then equivalent to p1 ∧ T, which is in turn equivalent to p1. So the treasure is in Trunk 1 (that is, p1 is true), and p2 and p3 are false; and the inscription on Trunk 2 is the only true one. (Here, we have used the concept of propositional equivalence, which is discussed in Section 1.3.) ◂ Next, we introduce a puzzle originally posed by Raymond Smullyan, a master of logic puzzles, who has published more than a dozen books containing challenging puzzles that involve logical reasoning. EXAMPLE 8 Extra Examples In [Sm78] Smullyan posed many puzzles about an island that has two kinds of inhabitants, knights, who always tell the truth, and their opposites, knaves, who always lie. You encounter two people A and B. What are A and B if A says “B is a knight” and B says “The two of us are opposite types”? Solution: Let p and q be the statements that A is a knight and B is a knight, respectively, so that ¬p and ¬q are the statements that A is a knave and B is a knave, respectively. We first consider the possibility that A is a knight; this is the statement that p is true. If A is a knight, then he is telling the truth when he says that B is a knight, so that q is true, and A and B are the same type. However, if B is a knight, then B’s statement that A and B are of opposite 1.2 Applications of Propositional Logic 21 types, the statement (p ∧ ¬q) ∨ (¬p ∧ q), would have to be true, which it is not, because A and B are both knights. Consequently, we can conclude that A is not a knight, that is, that p is false. If A is a knave, then because everything a knave says is false, A’s statement that B is a knight, that is, that q is true, is a lie. This means that q is false and B is also a knave. Furthermore, if B is a knave, then B’s statement that A and B are opposite types is a lie, which is consistent with both A and B being knaves. We can conclude that both A and B are knaves. ◂ We pose more of Smullyan’s puzzles about knights and knaves in Exercises 23–27. In Exercises 28–35 we introduce related puzzles where we have three types of people, knights and knaves as in this puzzle together with spies who can lie. Next, we pose a puzzle known as the muddy children puzzle for the case of two children. EXAMPLE 9 A father tells his two children, a boy and a girl, to play in their backyard without getting dirty. However, while playing, both children get mud on their foreheads. When the children stop playing, the father says “At least one of you has a muddy forehead,” and then asks the children to answer “Yes” or “No” to the question: “Do you know whether you have a muddy forehead?” The father asks this question twice. What will the children answer each time this question is asked, assuming that a child can see whether his or her sibling has a muddy forehead, but cannot see his or her own forehead? Assume that both children are honest and that the children answer each question simultaneously. Solution: Let s be the statement that the son has a muddy forehead and let d be the statement that the daughter has a muddy forehead. When the father says that at least one of the two children has a muddy forehead, he is stating that the disjunction s ∨ d is true. Both children will answer “No” the first time the question is asked because each sees mud on the other child’s forehead. That is, the son knows that d is true, but does not know whether s is true, and the daughter knows that s is true, but does not know whether d is true. After the son has answered “No” to the first question, the daughter can determine that d must be true. This follows because when the first question is asked, the son knows that s ∨ d is true, but cannot determine whether s is true. Using this information, the daughter can conclude that d must be true, for if d were false, the son could have reasoned that because s ∨ d is true, Links RAYMOND SMULLYAN (1919–2017) Raymond Smullyan, the son of a businessman and a homemaker, was born in Far Rockaway, Queens, New York. He dropped out of high school because he wanted to study what he was really interested in and not standard high school material. After attending Pacific College and Reed College in Oregon, he earned an undergraduate degree in mathematics at the University of Chicago in 1955. He paid his college expenses by performing magic tricks at parties and clubs, using the stage name Five-Ace Merrill. He obtained a Ph.D. in logic in 1959 at Princeton, studying under Alonzo Church. After graduating from Princeton, he taught mathematics and logic at Dartmouth College, Princeton University, Yeshiva University, and the City University of New York. He joined the philosophy department at Indiana University in 1981, where be became Courtesy of Indiana University Archives an emeritus professor. Smullyan wrote many books on recreational logic and mathematics, including Satan, Cantor, and Infin- ity; What Is the Name of This Book?; The Lady or the Tiger?; Alice in Puzzleland; To Mock a Mockingbird; Forever Undecided; and The Riddle of Scheherazade: Amazing Logic Puzzles, Ancient and Modern. Because his logic puzzles are challenging, entertaining, and thought-provoking, he was considered to be a modern-day Lewis Carroll. Smullyan also wrote several books about the application of deductive logic to chess, three collections of philosophical essays and aphorisms, and several advanced books on mathematical logic and set theory. He was particularly interested in self-reference and worked on extending some of Go¨del’s results that show that it is impossible to write a computer program that can solve all mathematical problems. He was also particularly interested in explaining ideas from mathematical logic to the public. Smullyan was a talented musician and often played piano with his second wife, who was a concert-level pianist. Making telescopes was one of his hobbies and he was interested in optics and stereo photography. He said, “I’ve never had a conflict between teaching and research as some people do because when I’m teaching, I’m doing research.” Smullyan is the subject of a documentary short film entitled This Film Needs No Title. 22 1 / The Foundations: Logic and Proofs then s must be true, and he would have answered “Yes” to the first question. The son can reason in a similar way to determine that s must be true. It follows that both children answer “Yes” the second time the question is asked. ◂ In Chapter 12 we will design some useful circuits. 1.2.6 Logic Circuits Propositional logic can be applied to the design of computer hardware. This was first observed in 1938 by Claude Shannon in his MIT master’s thesis. In Chapter 12 we will study this topic in depth. (See that chapter for a biography of Shannon.) We give a brief introduction to this application here. A logic circuit (or digital circuit) receives input signals p1, p2, … , pn, each a bit [either 0 (off) or 1 (on)], and produces output signals s1, s2, … , sn, each a bit. In this section we will restrict our attention to logic circuits with a single output signal; in general, digital circuits may have multiple outputs. Complicated digital circuits can be constructed from three basic circuits, called gates, shown in Figure 1. The inverter, or NOT gate, takes an input bit p, and produces as output ¬p. The OR gate takes two input signals p and q, each a bit, and produces as output the signal p ∨ q. Finally, the AND gate takes two input signals p and q, each a bit, and produces as output the signal p ∧ q. We use combinations of these three basic gates to build more complicated circuits, such as that shown in Figure 2. ¬p p Inverter p p ∨ q q OR gate p p ∧ q q AND gate FIGURE 1 Basic logic gates. Given a circuit built from the basic logic gates and the inputs to the circuit, we determine the output by tracing through the circuit, as Example 10 shows. EXAMPLE 10 Determine the output for the combinatorial circuit in Figure 2. Solution: In Figure 2 we display the output of each logic gate in the circuit. We see that the AND gate takes input of p and ¬q, the output of the inverter with input q, and produces p ∧ ¬q. Next, we note that the OR gate takes input p ∧ ¬q and ¬r, the output of the inverter with input r, and produces the final output (p ∧ ¬q) ∨ ¬r. ◂ Suppose that we have a formula for the output of a digital circuit in terms of negations, disjunctions, and conjunctions. Then, we can systematically build a digital circuit with the desired output, as illustrated in Example 11. p p ∧ ¬q q ¬q (p ∧ ¬q) ∨ ¬r r ¬r FIGURE 2 A combinatorial circuit. 1.2 Applications of Propositional Logic 23 p p ∨ ¬r r ¬r ¬p p (p ∨ ¬r) ∧ (¬p ∨ (q ∨ ¬r)) q ¬p ∨ (q ∨ ¬r) r q ∨ ¬r ¬r FIGURE 3 The circuit for (p ∨ ¬r) ∧ (¬p ∨ (q ∨ ¬r)). EXAMPLE 11 Build a digital circuit that produces the output (p ∨ ¬r) ∧ (¬p ∨ (q ∨ ¬r)) when given input bits p, q, and r. Solution: To construct the desired circuit, we build separate circuits for p ∨ ¬r and for ¬p ∨ (q ∨ ¬r) and combine them using an AND gate. To construct a circuit for p ∨ ¬r, we use an inverter to produce ¬r from the input r. Then, we use an OR gate to combine p and ¬r. To build a circuit for ¬p ∨ (q ∨ ¬r), we first use an inverter to obtain ¬r. Then we use an OR gate with inputs q and ¬r to obtain q ∨ ¬r. Finally, we use another inverter and an OR gate to get ¬p ∨ (q ∨ ¬r) from the inputs p and q ∨ ¬r. To complete the construction, we employ a final AND gate, with inputs p ∨ ¬r and ¬p ∨ (q ∨ ¬r). The resulting circuit is displayed in Figure 3. ◂ Exercises We will study logic circuits in great detail in Chapter 12 in the context of Boolean algebra, and with different notation. In Exercises 1–6, translate the given statement into propositional logic using the propositions provided. 1. You cannot edit a protected Wikipedia entry unless you are an administrator. Express your answer in terms of e: “You can edit a protected Wikipedia entry” and a: “You are an administrator.” 2. You can see the movie only if you are over 18 years old or you have the permission of a parent. Express your answer in terms of m: “You can see the movie,” e: “You are over 18 years old,” and p: “You have the permission of a parent.” 3. You can graduate only if you have completed the requirements of your major and you do not owe money to the university and you do not have an overdue library book. Express your answer in terms of g: “You can graduate,” m: “You owe money to the university,” r: “You have completed the requirements of your major,” and b: “You have an overdue library book.” 4. To use the wireless network in the airport you must pay the daily fee unless you are a subscriber to the service. Express your answer in terms of w: “You can use the wireless network in the airport,” d: “You pay the daily fee,” and s: “You are a subscriber to the service.” 5. You are eligible to be President of the U.S.A. only if you are at least 35 years old, were born in the U.S.A., or at the time of your birth both of your parents were citizens, and you have lived at least 14 years in the country. Express your answer in terms of e: “You are eligible to be President of the U.S.A.,” a: “You are at least 35 years old,” b: “You were born in the U.S.A.,” p: “At the time of your birth, both of your parents were citizens,” and r: “You have lived at least 14 years in the U.S.A.” 6. You can upgrade your operating system only if you have a 32-bit processor running at 1 GHz or faster, at least 1 GB RAM, and 16 GB free hard disk space, or a 64-bit processor running at 2 GHz or faster, at least 2 GB RAM, and at least 32 GB free hard disk space. Express your answer in terms of u: “You can upgrade your operating system,” b32: “You have a 32-bit processor,” b64: “You have a 64-bit processor,” g1: “Your processor runs at 1 GHz or faster,” g2: “Your processor runs at 2 GHz or faster,” r1: “Your processor has at least 1 GB RAM,” r2: “Your processor has at least 2 GB RAM,” h16: “You have at least 16 GB free hard disk space,” and h32: “You have at least 32 GB free hard disk space.” 7. Express these system specifications using the propositions p: “The message is scanned for viruses” and q: “The message was sent from an unknown system” together with logical connectives (including negations). a) “The message is scanned for viruses whenever the message was sent from an unknown system.” 24 1 / The Foundations: Logic and Proofs b) “The message was sent from an unknown system but it was not scanned for viruses.” c) “It is necessary to scan the message for viruses whenever it was sent from an unknown system.” d) “When a message is not sent from an unknown system it is not scanned for viruses.” 8. Express these system specifications using the propositions p: “The user enters a valid password,” q: “Access is granted,” and r: “The user has paid the subscription fee” and logical connectives (including negations). a) “The user has paid the subscription fee, but does not enter a valid password.” b) “Access is granted whenever the user has paid the subscription fee and enters a valid password.” c) “Access is denied if the user has not paid the subscription fee.” d) “If the user has not entered a valid password but has paid the subscription fee, then access is granted.” 9. Are these system specifications consistent? “The system is in multiuser state if and only if it is operating normally. If the system is operating normally, the kernel is functioning. The kernel is not functioning or the system is in interrupt mode. If the system is not in multiuser state, then it is in interrupt mode. The system is not in interrupt mode.” 10. Are these system specifications consistent? “Whenever the system software is being upgraded, users cannot access the file system. If users can access the file system, then they can save new files. If users cannot save new files, then the system software is not being upgraded.” 11. Are these system specifications consistent? “The router can send packets to the edge system only if it supports the new address space. For the router to support the new address space it is necessary that the latest software release be installed. The router can send packets to the edge system if the latest software release is installed. The router does not support the new address space.” 12. Are these system specifications consistent? “If the file system is not locked, then new messages will be queued. If the file system is not locked, then the system is functioning normally, and conversely. If new messages are not queued, then they will be sent to the message buffer. If the file system is not locked, then new messages will be sent to the message buffer. New messages will not be sent to the message buffer.” 13. What Boolean search would you use to look for Web pages about beaches in New Jersey? What if you wanted to find Web pages about beaches on the isle of Jersey (in the English Channel)? 14. What Boolean search would you use to look for Web pages about hiking in West Virginia? What if you wanted to find Web pages about hiking in Virginia, but not in West Virginia? 15. What Google search would you use to look for Web pages relating to Ethiopian restaurants in New York or New Jersey? 16. What Google search would you use to look for men’s shoes or boots not designed for work? 17. Suppose that in Example 7, the inscriptions on Trunks 1, 2, and 3 are “The treasure is in Trunk 3,” “The treasure is in Trunk 1,” and “This trunk is empty.” For each of these statements, determine whether the Queen who never lies could state this, and if so, which trunk the treasure is in. a) “All the inscriptions are false.” b) “Exactly one of the inscriptions is true.” c) “Exactly two of the inscriptions are true.” d) “All three inscriptions are true.” 18. Suppose that in Example 7 there are treasures in two of the three trunks. The inscriptions on Trunks 1, 2, and 3 are “This trunk is empty,” “There is a treasure in Trunk 1,” and “There is a treasure in Trunk 2.” For each of these statements, determine whether the Queen who never lies could state this, and if so, which two trunks the treasures are in. a) “All the inscriptions are false.” b) “Exactly one of the inscriptions is true.” c) “Exactly two of the inscriptions are true.” d) “All three inscriptions are true.” ∗ 19. Each inhabitant of a remote village always tells the truth or always lies. A villager will give only a “Yes” or a “No” response to a question a tourist asks. Suppose you are a tourist visiting this area and come to a fork in the road. One branch leads to the ruins you want to visit; the other branch leads deep into the jungle. A villager is standing at the fork in the road. What one question can you ask the villager to determine which branch to take? 20. An explorer is captured by a group of cannibals. There are two types of cannibals—those who always tell the truth and those who always lie. The cannibals will barbecue the explorer unless he can determine whether a particular cannibal always lies or always tells the truth. He is allowed to ask the cannibal exactly one question. a) Explain why the question “Are you a liar?” does not work. b) Find a question that the explorer can use to determine whether the cannibal always lies or always tells the truth. 21. When three professors are seated in a restaurant, the hostess asks them: “Does everyone want coffee?” The first professor says “I do not know.” The second professor then says “I do not know.” Finally, the third professor says “No, not everyone wants coffee.” The hostess comes back and gives coffee to the professors who want it. How did she figure out who wanted coffee? 22. When planning a party you want to know whom to invite. Among the people you would like to invite are three touchy friends. You know that if Jasmine attends, she will become unhappy if Samir is there, Samir will attend only if Kanti will be there, and Kanti will not attend unless Jasmine also does. Which combinations of these three friends can you invite so as not to make someone unhappy? 1.2 Applications of Propositional Logic 25 Exercises 23–27 relate to inhabitants of the island of knights and knaves created by Smullyan, where knights always tell the truth and knaves always lie. You encounter two people, A and B. Determine, if possible, what A and B are if they address you in the ways described. If you cannot determine what these two people are, can you draw any conclusions? 23. A says “At least one of us is a knave” and B says nothing. 24. A says “The two of us are both knights” and B says “A is a knave.” 25. A says “I am a knave or B is a knight” and B says nothing. 26. Both A and B say “I am a knight.” 27. A says “We are both knaves” and B says nothing. Exercises 28–35 relate to inhabitants of an island on which there are three kinds of people: knights who always tell the truth, knaves who always lie, and spies (called normals by Smullyan [Sm78]) who can either lie or tell the truth. You encounter three people, A, B, and C. You know one of these people is a knight, one is a knave, and one is a spy. Each of the three people knows the type of person each of other two is. For each of these situations, if possible, determine whether there is a unique solution and determine who the knave, knight, and spy are. When there is no unique solution, list all possible solutions or state that there are no solutions. 28. A says “C is the knave,” B says “A is the knight,” and C says “I am the spy.” 29. A says “I am the knight,” B says “I am the knave,” and C says “B is the knight.” 30. A says “I am the knave,” B says “I am the knave,” and C says “I am the knave.” 31. A says “I am the knight,” B says “A is telling the truth,” and C says “I am the spy.” 32. A says “I am the knight,” B says “A is not the knave,” and C says “B is not the knave.” 33. A says “I am the knight,” B says “I am the knight,” and C says “I am the knight.” 34. A says “I am not the spy,” B says “I am not the spy,” and C says “A is the spy.” 35. A says “I am not the spy,” B says “I am not the spy,” and C says “I am not the spy.” Exercises 36–42 are puzzles that can be solved by translating statements into logical expressions and reasoning from these expressions using truth tables. 36. The police have three suspects for the murder of Mr. Cooper: Mr. Smith, Mr. Jones, and Mr. Williams. Smith, Jones, and Williams each declare that they did not kill Cooper. Smith also states that Cooper was a friend of Jones and that Williams disliked him. Jones also states that he did not know Cooper and that he was out of town the day Cooper was killed. Williams also states that he saw both Smith and Jones with Cooper the day of the killing and that either Smith or Jones must have killed him. Can you determine who the murderer was if a) one of the three men is guilty, the two innocent men are telling the truth, but the statements of the guilty man may or may not be true? b) innocent men do not lie? 37. Steve would like to determine the relative salaries of three coworkers using two facts. First, he knows that if Fred is not the highest paid of the three, then Janice is. Second, he knows that if Janice is not the lowest paid, then Maggie is paid the most. Is it possible to determine the relative salaries of Fred, Maggie, and Janice from what Steve knows? If so, who is paid the most and who the least? Explain your reasoning. 38. Five friends have access to a chat room. Is it possible to determine who is chatting if the following information is known? Either Kevin or Heather, or both, are chatting. Either Randy or Vijay, but not both, are chatting. If Abby is chatting, so is Randy. Vijay and Kevin are either both chatting or neither is. If Heather is chatting, then so are Abby and Kevin. Explain your reasoning. 39. A detective has interviewed four witnesses to a crime. From the stories of the witnesses the detective has concluded that if the butler is telling the truth then so is the cook; the cook and the gardener cannot both be telling the truth; the gardener and the handyman are not both lying; and if the handyman is telling the truth then the cook is lying. For each of the four witnesses, can the detective determine whether that person is telling the truth or lying? Explain your reasoning. 40. Four friends have been identified as suspects for an unauthorized access into a computer system. They have made statements to the investigating authorities. Alice said, “Carlos did it.” John said, “I did not do it.” Carlos said, “Diana did it.” Diana said, “Carlos lied when he said that I did it.” a) If the authorities also know that exactly one of the four suspects is telling the truth, who did it? Explain your reasoning. b) If the authorities also know that exactly one is lying, who did it? Explain your reasoning. 41. Suppose there are signs on the doors to two rooms. The sign on the first door reads “In this room there is a lady, and in the other one there is a tiger”; and the sign on the second door reads “In one of these rooms, there is a lady, and in one of them there is a tiger.” Suppose that you know that one of these signs is true and the other is false. Behind which door is the lady? ∗ 42. Solve this famous logic puzzle, attributed to Albert Ein- stein, and known as the zebra puzzle. Five men with Links different nationalities and with different jobs live in consecutive houses on a street. These houses are painted different colors. The men have different pets and have dif- ferent favorite drinks. Determine who owns a zebra and whose favorite drink is mineral water (which is one of the favorite drinks) given these clues: The Englishman lives in the red house. The Spaniard owns a dog. The Japanese man is a painter. The Italian drinks tea. The Norwegian lives in the first house on the left. The green house is im- mediately to the right of the white one. The photographer breeds snails. The diplomat lives in the yellow house. Milk is drunk in the middle house. The owner of the green house drinks coffee. The Norwegian’s house is next to the 26 1 / The Foundations: Logic and Proofs blue one. The violinist drinks orange juice. The fox is in a house next to that of the physician. The horse is in a house next to that of the diplomat. [Hint: Make a table where the rows represent the men and columns represent the color of their houses, their jobs, their pets, and their favorite drinks and use logical reasoning to determine the correct entries in the table.] 43. Freedonia has 50 senators. Each senator is either honest or corrupt. Suppose you know that at least one of the Freedonian senators is honest and that, given any two Freedonian senators, at least one is corrupt. Based on these facts, can you determine how many Freedonian senators are honest and how many are corrupt? If so, what is the answer? 44. Find the output of each of these combinatorial circuits. a) p q b) p p q 45. Find the output of each of these combinatorial circuits. a) p q r b) p q p r 46. Construct a combinatorial circuit using inverters, OR gates, and AND gates that produces the output (p ∧ ¬r) ∨ (¬q ∧ r) from input bits p, q, and r. 47. Construct a combinatorial circuit using inverters, OR gates, and AND gates that produces the output ((¬p ∨ ¬r) ∧ ¬q) ∨ (¬p ∧ (q ∨ r)) from input bits p, q, and r. 1.3 Propositional Equivalences 1.3.1 Introduction An important type of step used in a mathematical argument is the replacement of a statement with another statement with the same truth value. Because of this, methods that produce propositions with the same truth value as a given compound proposition are used extensively in the construction of mathematical arguments. Note that we will use the term “compound proposition” to refer to an expression formed from propositional variables using logical operators, such as p ∧ q. We begin our discussion with a classification of compound propositions according to their possible truth values. Definition 1 A compound proposition that is always true, no matter what the truth values of the propositional variables that occur in it, is called a tautology. A compound proposition that is always false is called a contradiction. A compound proposition that is neither a tautology nor a contradiction is called a contingency. Tautologies and contradictions are often important in mathematical reasoning. Example 1 illustrates these types of compound propositions. EXAMPLE 1 We can construct examples of tautologies and contradictions using just one propositional vari- able. Consider the truth tables of p ∨ ¬p and p ∧ ¬p, shown in Table 1. Because p ∨ ¬p is always true, it is a tautology. Because p ∧ ¬p is always false, it is a contradiction. ◂ 1.3 Propositional Equivalences 27 Demo TABLE 1 Examples of a Tautology and a Contradiction. p ¬p p ∨ ¬p p ∧ ¬p T F T F F T T F 1.3.2 Logical Equivalences Compound propositions that have the same truth values in all possible cases are called logically equivalent. We can also define this notion as follows. Definition 2 The compound propositions p and q are called logically equivalent if p ↔ q is a tautology. The notation p ≡ q denotes that p and q are logically equivalent. Extra Examples Remark: The symbol ≡ is not a logical connective, and p ≡ q is not a compound proposition but rather is the statement that p ↔ q is a tautology. The symbol ⇔ is sometimes used instead of ≡ to denote logical equivalence. One way to determine whether two compound propositions are equivalent is to use a truth table. In particular, the compound propositions p and q are equivalent if and only if the columns giving their truth values agree. Example 2 illustrates this method to establish an extremely important and useful logical equivalence, namely, that of ¬(p ∨ q) with ¬p ∧ ¬q. This logical equivalence is one of the two De Morgan laws, shown in Table 2, named after the English mathematician Augustus De Morgan, of the mid-nineteenth century. TABLE 2 De Morgan’s Laws. ¬(p ∧ q) ≡ ¬p ∨ ¬q ¬(p ∨ q) ≡ ¬p ∧ ¬q EXAMPLE 2 Show that ¬(p ∨ q) and ¬p ∧ ¬q are logically equivalent. Solution: The truth tables for these compound propositions are displayed in Table 3. Because the truth values of the compound propositions ¬(p ∨ q) and ¬p ∧ ¬q agree for all possible com- binations of the truth values of p and q, it follows that ¬(p ∨ q) ↔ (¬p ∧ ¬q) is a tautology and that these compound propositions are logically equivalent. ◂ TABLE 3 Truth Tables for ¬(p ∨ q) and ¬p ∧ ¬q. p q p∨q ¬(p ∨ q) ¬p ¬q T T T T F T F T T F F F F F F F F T F T F T T T ¬p ∧ ¬q F F F T 28 1 / The Foundations: Logic and Proofs EXAMPLE 3 The next example establishes an extremely important equivalence. It allows us to replace conditional statements with negations and disjunctions. Show that p → q and ¬p ∨ q are logically equivalent. (This is known as the conditionaldisjunction equivalence.) Solution: We construct the truth table for these compound propositions in Table 4. Because the truth values of ¬p ∨ q and p → q agree, they are logically equivalent. ◂ TABLE 4 Truth Tables for ¬p ∨ q and p → q. p q ¬p ¬p ∨ q p→q T T F T T T F F F F F T T T T F F T T T We will now establish a logical equivalence of two compound propositions involving three different propositional variables p, q, and r. To use a truth table to establish such a logical equivalence, we need eight rows, one for each possible combination of truth values of these three variables. We symbolically represent these combinations by listing the truth values of p, q, and r, respectively. These eight combinations of truth values are TTT, TTF, TFT, TFF, FTT, FTF, FFT, and FFF; we use this order when we display the rows of the truth table. Note that we need to double the number of rows in the truth tables we use to show that compound propositions are equivalent for each additional propositional variable, so that 16 rows are needed to establish the logical equivalence of two compound propositions involving four propositional variables, and so on. In general, 2n rows are required if a compound proposition involves n propositional variables. Because of the rapid growth of 2n, more efficient ways are needed to establish logical equivalences, such as by using ones we already know. This technique will be discussed later. EXAMPLE 4 Show that p ∨ (q ∧ r) and (p ∨ q) ∧ (p ∨ r) are logically equivalent. This is the distributive law of disjunction over conjunction. Solution: We construct the truth table for these compound propositions in Table 5. Because the truth values of p ∨ (q ∧ r) and (p ∨ q) ∧ (p ∨ r) agree, these compound propositions are logically equivalent. ◂ TABLE 5 A Demonstration That p ∨ (q ∧ r) and (p ∨ q) ∧ (p ∨ r) Are Logically Equivalent. p q r q∧r p ∨ (q ∧ r) p∨q p∨r (p ∨ q) ∧ (p ∨ r) T T T T T T T T T T F F T T T T T F T F T T T T T F F F T T T T F T T T T T T T F T F F F T F F F F T F F F T F F F F F F F F F TABLE 6 Logical Equivalences. Equivalence Name p∧T≡p p∨F≡p Identity laws p∨T≡T p∧F≡F Domination laws p∨p≡p p∧p≡p Idempotent laws ¬(¬p) ≡ p Double negation law p∨q≡q∨p p∧q≡q∧p Commutative laws (p ∨ q) ∨ r ≡ p ∨ (q ∨ r) (p ∧ q) ∧ r ≡ p ∧ (q ∧ r) Associative laws p ∨ (q ∧ r) ≡ (p ∨ q) ∧ (p ∨ r) p ∧ (q ∨ r) ≡ (p ∧ q) ∨ (p ∧ r) Distributive laws ¬(p ∧ q) ≡ ¬p ∨ ¬q ¬(p ∨ q) ≡ ¬p ∧ ¬q De Morgan’s laws p ∨ (p ∧ q) ≡ p p ∧ (p ∨ q) ≡ p Absorption laws p ∨ ¬p ≡ T p ∧ ¬p ≡ F Negation laws 1.3 Propositional Equivalences 29 The identities in Table 6 are a special case of Boolean algebra identities found in Table 5 of Section 12.1. See Table 1 in Section 2.2 for analogous set identities. Table 6 contains some important equivalences. In these equivalences, T denotes the compound proposition that is always true and F denotes the compound proposition that is always false. We also display some useful equivalences for compound propositions involving conditional statements and biconditional statements in Tables 7 and 8, respectively. The reader is asked to verify the equivalences in Tables 6–8 in the exercises. TABLE 7 Logical Equivalences Involving Conditional Statements. p → q ≡ ¬p ∨ q p → q ≡ ¬q → ¬p p ∨ q ≡ ¬p → q p ∧ q ≡ ¬(p → ¬q) ¬(p → q) ≡ p ∧ ¬q (p → q) ∧ (p → r) ≡ p → (q ∧ r) (p → r) ∧ (q → r) ≡ (p ∨ q) → r (p → q) ∨ (p → r) ≡ p → (q ∨ r) (p → r) ∨ (q → r) ≡ (p ∧ q) → r TABLE 8 Logical Equivalences Involving Biconditional Statements. p ↔ q ≡ (p → q) ∧ (q → p) p ↔ q ≡ ¬p ↔ ¬q p ↔ q ≡ (p ∧ q) ∨ (¬p ∧ ¬q) ¬(p ↔ q) ≡ p ↔ ¬q 30 1 / The Foundations: Logic and Proofs Be careful not to apply logical identities, such as associative laws, distributive laws, or De Morgan’s laws, to expressions that have a mix of conjunctions and disjunctions when the identities only apply when all these operators are the same. The associative law for disjunction shows that the expression p ∨ q ∨ r is well defined, in the sense that it does not matter whether we first take the disjunction of p with q and then the disjunction of p ∨ q with r, or if we first take the disjunction of q and r and then take the disjunction of p with q ∨ r. Similarly, the expression p ∧ q ∧ r is well defined. By extending this reasoning, it follows that p1 ∨ p2 ∨ ⋯ ∨ pn and p1 ∧ p2 ∧ ⋯ ∧ pn are well defined whenever p1, p2, … , pn are propositions. Furthermore, note that De Morgan’s laws extend to ¬(p1 ∨ p2 ∨ ⋯ ∨ pn) ≡ (¬p1 ∧ ¬p2 ∧ ⋯ ∧ ¬pn) and ¬(p1 ∧ p2 ∧ ⋯ ∧ pn) ≡ (¬p1 ∨ ¬p2 ∨ ⋯ ∨ ¬pn). We will sometimes use the notation ⋁n j=1 pj for p1 ∨ p2 ∨ ⋯ ∨ pn and ⋀n j=1 pj for p1 be ∧ p2 ∧ ⋯ ∧ pn. Using written concisely as ¬th(i⋁s nj=n1otpajt)io≡n,⋀thnj=e1 ¬epxjteanndded¬(ve⋀rsnj=io1npj)of≡ D⋁enj=M1 ¬oprjg.an(M’s etlhawodss can for proving these identities will be given in Section 5.1.) A truth table with 2n rows is needed to prove the equivalence of two compound propositions in n variables. (Note that the number of rows doubles for each additional propositional variable added. See Chapter 6 for details about solving counting problems such as this.) Because 2n grows extremely rapidly as n increases (see Section 3.2), the use of truth tables to establish equivalences becomes impractical as the number of variables grows. It is quicker to use other methods, such as employing logical equivalences that we already know. How that can be done is discussed later in this section. When using De Morgan’s laws, remember to change the logical connective after you negate. 1.3.3 Using De Morgan’s Laws The two logical equivalences known as De Morgan’s laws are particularly important. They tell us how to negate conjunctions and how to negate disjunctions. In particular, the equivalence ¬(p ∨ q) ≡ ¬p ∧ ¬q tells us that the negation of a disjunction is formed by taking the conjunction of the negations of the component propositions. Similarly, the equivalence ¬(p ∧ q) ≡ ¬p ∨ ¬q tells us that the negation of a conjunction is formed by taking the disjunction of the negations of the component propositions. Example 5 illustrates the use of De Morgan’s laws. EXAMPLE 5 Use De Morgan’s laws to express the negations of “Miguel has a cellphone and he has a laptop computer” and “Heather will go to the concert or Steve will go to the concert.” Assessment Solution: Let p be “Miguel has a cellphone” and q be “Miguel has a laptop computer.” Then “Miguel has a cellphone and he has a laptop computer” can be represented by p ∧ q. By the first of De Morgan’s laws, ¬(p ∧ q) is equivalent to ¬p ∨ ¬q. Consequently, we can express the negation of our original statement as “Miguel does not have a cellphone or he does not have a laptop computer.” Let r be “Heather will go to the concert” and s be “Steve will go to the concert.” Then “Heather will go to the concert or Steve will go to the concert” can be represented by r ∨ s. By the second of De Morgan’s laws, ¬(r ∨ s) is equivalent to ¬r ∧ ¬s. Consequently, we can express the negation of our original statement as “Heather will not go to the concert and Steve will not go to the concert.” ◂ 1.3 Propositional Equivalences 31 1.3.4 Constructing New Logical Equivalences The logical equivalences in Table 6, as well as any others that have been established (such as those shown in Tables 7 and 8), can be used to construct additional logical equivalences. The reason for this is that a proposition in a compound proposition can be replaced by a compound proposition that is logically equivalent to it without changing the truth value of the original compound proposition. This technique is illustrated in Examples 6–8, where we also use the fact that if p and q are logically equivalent and q and r are logically equivalent, then p and r are logically equivalent (see Exercise 60). EXAMPLE 6 Extra Examples Show that ¬(p → q) and p ∧ ¬q are logically equivalent. Solution: We could use a truth table to show that these compound propositions are equivalent (similar to what we did in Example 4). Indeed, it would not be hard to do so. However, we want to illustrate how to use logical identities that we already know to establish new logical identities, something that is of practical importance for establishing equivalences of compound propositions with a large number of variables. So, we will establish this equivalence by developing a series of logical equivalences, using one of the equivalences in Table 6 at a time, starting with ¬(p → q) and ending with p ∧ ¬q. We have the following equivalences. ¬(p → q) ≡ ¬(¬p ∨ q) by the conditional-disjunction equivalence (Example 3) ≡ ¬(¬p) ∧ ¬q by the second De Morgan law ≡ p ∧ ¬q by the double negation law ◂ EXAMPLE 7 Show that ¬(p ∨ (¬p ∧ q)) and ¬p ∧ ¬q are logically equivalent by developing a series of logical equivalences. Solution: We will use one of the equivalences in Table 6 at a time, starting with ¬(p ∨ (¬p ∧ q)) and ending with ¬p ∧ ¬q. (Note: we could also easily establish this equivalence using a truth table.) We have the following equivalences. Links AUGUSTUS DE MORGAN (1806–1871) Augustus De Morgan was born in India, where his father was a colonel in the Indian army. De Morgan’s family moved to England when he was 7 months old. He attended private schools, where in his early teens he developed a strong interest in mathematics. De Morgan studied at Trinity College, Cambridge, graduating in 1827. Although he considered medicine or law, he decided on mathematics for his career. He won a position at University College, London, in 1828, but resigned after the college dismissed a fellow professor without giving reasons. However, he resumed this position in 1836 when his successor died, remaining until 1866. De Morgan was a noted teacher who stressed principles over techniques. His students inc Bettmann/Getty Images cluded many famous mathematicians, including Augusta Ada, Countess of Lovelace, who was Charles Babbage’s collaborator in his work on computing machines (see page 32 for biographical notes on Augusta Ada). (De Morgan cautioned the countess against studying too much mathematics, because it might interfere with her childbearing abilities!) De Morgan was an extremely prolific writer, publishing more than 1000 articles in more than 15 periodicals. De Morgan also wrote textbooks on many subjects, including logic, probability, calculus, and algebra. In 1838 he presented what was perhaps the first clear explanation of an important proof technique known as mathematical induction (discussed in Section 5.1 of this text), a term he coined. In the 1840s De Morgan made fundamental contributions to the development of symbolic logic. He invented notations that helped him prove propositional equivalences, such as the laws that are named after him. In 1842 De Morgan presented what is considered to be the first precise definition of a limit and developed new tests for convergence of infinite series. De Morgan was also interested in the history of mathematics and wrote biographies of Newton and Halley. In 1837 De Morgan married Sophia Frend, who wrote his biography in 1882. De Morgan’s research, writing, and teaching left little time for his family or social life. Nevertheless, he was noted for his kindness, humor, and wide range of knowledge. 32 1 / The Foundations: Logic and Proofs ¬(p ∨ (¬p ∧ q)) ≡ ¬p ∧ ¬(¬p ∧ q) ≡ ¬p ∧ [¬(¬p) ∨ ¬q] ≡ ¬p ∧ (p ∨ ¬q) ≡ (¬p ∧ p) ∨ (¬p ∧ ¬q) ≡ F ∨ (¬p ∧ ¬q) ≡ (¬p ∧ ¬q) ∨ F ≡ ¬p ∧ ¬q by the second De Morgan law by the first De Morgan law by the double negation law by the second distributive law because ¬p ∧ p ≡ F by the commutative law for disjunction by the identity law for F Consequently ¬(p ∨ (¬p ∧ q)) and ¬p ∧ ¬q are logically equivalent. ◂ EXAMPLE 8 Show that (p ∧ q) → (p ∨ q) is a tautology. Solution: To show that this statement is a tautology, we will use logical equivalences to demonstrate that it is logically equivalent to T. (Note: This could also be done using a truth table.) (p ∧ q) → (p ∨ q) ≡ ¬(p ∧ q) ∨ (p ∨ q) by Example 3 ≡ (¬p ∨ ¬q) ∨ (p ∨ q) by the first De Morgan law ≡ (¬p ∨ p) ∨ (¬q ∨ q) by the associative and commutative laws for disjunction ≡T∨T by Example 1 and the commutative law for disjunction ≡T by the domination law ◂ Links AUGUSTA ADA, COUNTESS OF LOVELACE (1815–1852) Augusta Ada was the only child from the mar- riage of the flamboyant and notorious poet Lord Byron and Lady Byron, Annabella Millbanke, who separated when Ada was 1 month old, because of Lord Byron’s scandalous affair with his half sister. The Lord Byron had quite a reputation, being described by one of his lovers as “mad, bad, and dangerous to know.” Lady Byron was noted for her intellect and had a passion for mathematics; she was called by Lord Byron “The Princess of Parallelograms.” Augusta was raised by her mother, who encouraged her intellectual talents especially in music and mathematics, to counter what Lady Byron considered dangerous poetic tendencies. At this time, women were not allowed to attend universities and could not join learned societies. Nevertheless, Augusta pursued c Hulton Archive/Getty her mathematical studies independently and with mathematicians, including William Frend. She was also en- Images couraged by another female mathematician, Mary Somerville, and in 1834 at a dinner party hosted by Mary Somerville, she learned about Charles Babbage’s ideas for a calculating machine, called the Analytic Engine. In 1838 Augusta Ada married Lord King, later elevated to Earl of Lovelace. Together they had three children. Augusta Ada continued her mathematical studies after her marriage. Charles Babbage had continued work on his Analytic Engine and lectured on this in Europe. In 1842 Babbage asked Augusta Ada to translate an article in French describing Babbage’s invention. When Babbage saw her translation, he suggested she add her own notes, and the resulting work was three times the length of the original. The most complete accounts of the Analytic Engine are found in Augusta Ada’s notes. In her notes, she compared the working of the Analytic Engine to that of the Jacquard loom, with Babbage’s punch cards analogous to the cards used to create patterns on the loom. Furthermore, she recognized the promise of the machine as a general purpose computer much better than Babbage did. She stated that the “engine is the material expression of any indefinite function of any degree of generality and complexity.” Her notes on the Analytic Engine anticipate many future developments, including computer-generated music. Augusta Ada published her writings under her initials A.A.L., concealing her identity as a woman as did many women at a time when women were not considered to be the intellectual equals of men. After 1845 she and Babbage worked toward the development of a system to predict horse races. Unfortunately, their system did not work well, leaving Augusta Ada heavily in debt at the time of her death at an unfortunately young age from uterine cancer. In 1953 Augusta Ada’s notes on the Analytic Engine were republished more than 100 years after they were written, and after they had been long forgotten. In his work in the 1950s on the capacity of computers to think (and his influential Turing test for determining whether a machine is intelligent), Alan Turing responded to Augusta Ada’s statement that “The Analytic Engine has no pretensions whatever to originate anything. It can do whatever we know how to order it to perform.” This “dialogue” between Turing and Augusta Ada is still the subject of controversy. Because of her fundamental contributions to computing, the programming language Ada is named in honor of the Countess of Lovelace. 1.3 Propositional Equivalences 33 1.3.5 Satisfiability A compound proposition is satisfiable if there is an assignment of truth values to its variables that makes it true (that is, when it is a tautology or a contingency). When no such assignments exists, that is, when the compound proposition is false for all assignments of truth values to its variables, the compound proposition is unsatisfiable. Note that a compound proposition is unsatisfiable if and only if its negation is true for all assignments of truth values to the variables, that is, if and only if its negation is a tautology. When we find a particular assignment of truth values that makes a compound proposition true, we have shown that it is satisfiable; such an assignment is called a solution of this particular satisfiability problem. However, to show that a compound proposition is unsatisfiable, we need to show that every assignment of truth values to its variables makes it false. Although we can always use a truth table to determine whether a compound proposition is satisfiable, it is often more efficient not to, as Example 9 demonstrates. EXAMPLE 9 Determine whether each of the compound propositions (p ∨ ¬q) ∧ (q ∨ ¬r) ∧ (r ∨ ¬p), (p ∨ q ∨ r) ∧ (¬p ∨ ¬q ∨ ¬r), and (p ∨ ¬q) ∧ (q ∨ ¬r) ∧ (r ∨ ¬p) ∧ (p ∨ q ∨ r) ∧ (¬p ∨ ¬q ∨ ¬r) is satisfiable. Solution: Instead of using a truth table to solve this problem, we will reason about truth values. Note that (p ∨ ¬q) ∧ (q ∨ ¬r) ∧ (r ∨ ¬p) is true when the three variables p, q, and r have the same truth value (see Exercise 42 of Section 1.1). Hence, it is satisfiable as there is at least one assignment of truth values for p, q, and r that makes it true. Similarly, note that (p ∨ q ∨ r) ∧ (¬p ∨ ¬q ∨ ¬r) is true when at least one of p, q, and r is true and at least one is false (see Exercise 43 of Section 1.1). Hence, (p ∨ q ∨ r) ∧ (¬p ∨ ¬q ∨ ¬r) is satisfiable, as there is at least one assignment of truth values for p, q, and r that makes it true. Finally, note that for (p ∨ ¬q) ∧ (q ∨ ¬r) ∧ (r ∨ ¬p) ∧ (p ∨ q ∨ r) ∧ (¬p ∨ ¬q ∨ ¬r) to be true, (p ∨ ¬q) ∧ (q ∨ ¬r) ∧ (r ∨ ¬p) and (p ∨ q ∨ r) ∧ (¬p ∨ ¬q ∨ ¬r) must both be true. For the first to be true, the three variables must have the same truth values, and for the sec- ond to be true, at least one of the three variables must be true and at least one must be false. However, these conditions are contradictory. From these observations we conclude that no assignment of truth values to p, q, and r makes (p ∨ ¬q) ∧ (q ∨ ¬r) ∧ (r ∨ ¬p) ∧ (p ∨ q ∨ r) ∧ (¬p ∨ ¬q ∨ ¬r) true. Hence, it is unsatisfiable. ◂ 1.3.6 Applications of Satisfiability Many problems, in diverse areas such as robotics, software testing, artificial intelligence planning, computer-aided design, machine vision, integrated circuit design, scheduling, computer networking, and genetics, can be modeled in terms of propositional satisfiability. Although most applications are quite complex and beyond the scope of this book, we can illustrate how two puzzles can be modeled as satisfiability problems. EXAMPLE 10 The n-Queens Problem The n-queens problem asks for a placement of n queens on an n × n chessboard so that no queen can attack another queen. This means that no two queens can be placed in the same row, in the same column, or on the same diagonal. We display a solution to the eight-queens problem in Figure 1. (The eight-queens problem dates back to 1848 when it was proposed by Max Bezzel and was completely solved by Franz Nauck in 1850. We will return to the n-queens problem in Section 11.4.) To model the n-queens problem as a satisfiability problem, we introduce n2 variables, p(i, j) for i = 1, 2, … , n and j = 1, 2, … , n. For a given placement of a queens on the chessboard, p(i, j) is true when there is a queen on the square in the ith row and jth column, and is false 34 1 / The Foundations: Logic and Proofs FIGURE 1 otherwise. Note that squares (i, j) and (i′, j′) are on the same diagonal if either i + i′ = j + j′ or i − i′ = j − j′. In the chessboard in Figure 1, p(6, 2) and p(2, 1) are true, while p(3, 4) and p(5, 4) are false. For no two of the n queens to be in the same row, there must be one queen in each row. We cqauneesnhoawndththaatttehveereryisroownecqounetaeinnsinatemacohstroownebqyuveeerni.fyWinegfitrhsattneovteertyharot w⋁cnj=o1npta(ii,njs) at least asserts one that row i contains at least one queen, and ⋀n ⋁n Q1 = p(i, j) i=1 j=1 asserts that every row contains at least one queen. For every row to include at most one queen, it must be the case that p(i, j) and p(k, j) are not both true for integers j and k with 1 ≤ j < k ≤ n. Observe that ¬p(i, j) ∨ ¬p(i, k) asserts that at least one of ¬p(i, j) and ¬p(i, k) is true, which means that at least one of p(i, j) and p(i, k) is false. So, to check that there is at most one queen in each row, we assert ⋀n ⋀ n−1 ⋀n Q2 = (¬p(i, j) ∨ ¬p(k, j)). i=1 j=1 k=j+1 To assert that no column contains more than one queen, we assert that ⋀n ⋀ n−1 ⋀n Q3 = (¬p(i, j) ∨ ¬p(k, j)). j=1 i=1 k=i+1 (This assertion, together with the previous assertion that every row contains a queen, implies that every column contains a queen.) To assert that no diagonal contains two queens, we assert ⋀n ⋀ n−1 min(⋀ i−1,n−j) Q4 = (¬p(i, j) ∨ ¬p(i − k, k + j)) i=2 j=1 k=1 and ⋀ n−1 ⋀ n−1 min(⋀ n−i,n−j) Q5 = (¬p(i, j) ∨ ¬p(i + k, j + k)). i=1 j=1 k=1 1.3 Propositional Equivalences 35 The innermost conjunction in Q4 and in Q5 for a pair (i, j) runs through the positions on a diagonal that begin at (i, j) and runs rightward along this diagonal. The upper limits on these innermost conjunctions identify the last cell in the board on each diagonal. Putting all this together, we find that the solutions of the n-queens problem are given by the assignments of truth values to the variables p(i, j), i = 1, 2, … , n and j = 1, 2, … , n that make Q = Q1 ∧ Q2 ∧ Q3 ∧ Q4 ∧ Q5 true. Using this and other approaches, the number of ways n queens can be placed on a chessboard so that no queen can attack another has been computed for n ≤ 27. When n = 8 there are 92 such placements, while for n = 16 this number grows to 14,772,512. (See the OEIS discussed in Section 2.4 for details.) ◂ EXAMPLE 11 Links Sudoku Sudoku puzzles are constructed using a 9 × 9 grid made up of nine 3 × 3 subgrids, known as blocks, as shown in Figure 2. For each puzzle, some of the 81 cells, called givens, are assigned one of the numbers 1, 2, … , 9, and the other cells are blank. The puzzle is solved by assigning a number to each blank cell so that every row, every column, and every one of the nine 3 × 3 blocks contains each of the nine possible numbers. Note that instead of using a 9 × 9 grid, Sudoku puzzles can be based on n2 × n2 grids, for any positive integer n, with the n2 × n2 grid made up of n2 n × n subgrids. The popularity of Sudoku dates back to the 1980s when it was introduced in Japan. It took 20 years for Sudoku to spread to rest of the world, but by 2005, Sudoku puzzles were a worldwide craze. The name Sudoku is short for the Japanese suuji wa dokushin ni kagiru, which means “the digits must remain single.” The modern game of Sudoku was apparently designed in the late 1970s by an American puzzle designer. The basic ideas of Sudoku date back even further; puzzles printed in French newspapers in the 1890s were quite similar, but not identical, to modern Sudoku. Sudoku puzzles designed for entertainment have two additional important properties. First, they have exactly one solution. Second, they can be solved using reasoning alone, that is, without resorting to searching all possible assignments of numbers to the cells. As a Sudoku puzzle is solved, entries in blank cells are successively determined by already known values. For instance, in the grid in Figure 2, the number 4 must appear in exactly one cell in the second row. How can we determine in which of the seven blank cells it must appear? First, we observe that 4 cannot appear in one of the first three cells or in one of the last three cells of this row, because it already appears in another cell in the block each of these cells is in. We can also see that 4 29 4 5 1 4 42 6 7 5 7 3 5 1 9 6 FIGURE 2 A 9 × 9 Sudoku puzzle. 36 1 / The Foundations: Logic and Proofs cannot appear in the fifth cell in this row, as it already appears in the fifth column in the fourth row. This means that 4 must appear in the sixth cell of the second row. Many strategies based on logic and mathematics have been devised for solving Sudoku puzzles (see [Da10], for example). Here, we discuss one of the ways that have been developed for solving Sudoku puzzles with the aid of a computer, which depends on modeling the puzzle as a propositional satisfiability problem. Using the model we describe, particular Sudoku puzzles can be solved using software developed to solve satisfiability problems. Currently, Sudoku puzzles can be solved in less than 10 milliseconds this way. It should be noted that there are many other approaches for solving Sudoku puzzles via computers using other techniques. To encode a Sudoku puzzle, let p(i, j, n) denote the proposition that is true when the number n is in the cell in the ith row and jth column. There are 9 × 9 × 9 = 729 such propositions, as i, j, and n all range from 1 to 9. For example, for the puzzle in Figure 2, the number 6 is given as the value in the fifth row and first column. Hence, we see that p(5, 1, 6) is true, but p(5, j, 6) is false for j = 2, 3, … , 9. Given a particular Sudoku puzzle, we begin by encoding each of the given values. Then, we construct compound propositions that assert that every row contains every number, every column contains every number, every 3 × 3 block contains every number, and each cell contains no more than one number. It follows, as the reader should verify, that the Sudoku puzzle is solved by finding an assignment of truth values to the 729 propositions p(i, j, n) with i, j, and n each ranging from 1 to 9 that makes the conjunction of all these compound propositions true. After listing these assertions, we will explain how to construct the assertion that every row contains every integer from 1 to 9. We will leave the construction of the other assertions that every column contains every number and each of the nine 3 × 3 blocks contains every number to the exercises. ▶ For each cell with a given value, we assert p(i, j, n) when the cell in row i and column j has the given value n. ▶ We assert that every row contains every number: ⋀9 ⋀9 ⋁9 p(i, j, n) i=1 n=1 j=1 ▶ We assert that every column contains every number: ⋀9 ⋀9 ⋁9 p(i, j, n) j=1 n=1 i=1 It is tricky setting up the two inner indices so that all nine cells in each square block are examined. ▶ We assert that each of the nine 3 × 3 blocks contains every number: ⋀2 ⋀2 ⋀9 ⋁3 ⋁3 p(3r + i, 3s + j, n) r=0 s=0 n=1 i=1 j=1 ▶ To assert that no cell contains more than one number, we take the conjunction over all values of n, n′, i, and j, where each variable ranges from 1 to 9 and n ≠ n′ of p(i, j, n) → ¬p(i, j, n′). We First, to now explain assert that how row i to construct the assertion contains the number n, wtheatfoervmery⋁r9jo=w1 pc(io,nj,tani)n. sTeovearsysenrut mthbaetr. row i contains possible values all of n n, numbers, giving us w⋀e9n=f1or⋁m9j=t1hpe(ic,oj,nnju).nFctiinoanllyo,ftothaessseerdtistjhuantcetivoenrsy over row all nine contains 1.3 Propositional Equivalences 37 every number, we take us ⋀9 i=1 ⋀9 n=1 ⋁9 j=1 p(i, the conjunction j, n). (Exercises of ⋀9 n=1 71 and ⋁9 j=1 p(i, j, n) over all nine rows. 72 ask for explanations of the This gives assertions that every column contains every number and that each of the nine 3 × 3 blocks contains every number.) Given a particular Sudoku puzzle, to solve this puzzle we can find a solution to the satisfi- ability problems that asks for a set of truth values for the 729 variables p(i, j, n) that makes the conjunction of all the listed assertions true. ◂ Links 1.3.7 Solving Satisfiability Problems A truth table can be used to determine whether a compound proposition is satisfiable, or equivalently, whether its negation is a tautology (see Exercise 64). This can be done by hand for a compound proposition with a small number of variables, but when the number of variables grows, this becomes impractical. For instance, there are 220 = 1,048,576 rows in the truth table for a compound proposition with 20 variables. Thus, you need a computer to help you determine, in this way, whether a compound proposition in 20 variables is satisfiable. When many applications are modeled, questions concerning the satisfiability of compound propositions with hundreds, thousands, or millions of variables arise. Note, for example, that when there are 1000 variables, checking every one of the 21000 (a number with more than 300 decimal digits) possible combinations of truth values of the variables in a compound proposition cannot be done by a computer in even trillions of years. No procedure is known that a computer can follow to determine in a reasonable amount of time whether an arbitrary compound proposition in such a large number of variables is satisfiable. However, progress has been made developing methods for solving the satisfiability problem for the particular types of compound propositions that arise in practical applications, such as for the solution of Sudoku puzzles. Many computer programs have been developed for solving satisfiability problems which have practical use. In our discussion of the subject of algorithms in Chapter 3, we will discuss this question further. In particular, we will explain the important role the propositional satisfiability problem plays in the study of the complexity of algorithms. Links HENRY MAURICE SHEFFER (1883–1964) Henry Maurice Sheffer, born to Jewish parents in the western Ukraine, emigrated to the United States in 1892 with his parents and six siblings. He studied at the Boston Latin School before entering Harvard, where he completed his undergraduate degree in 1905, his master’s in 1907, and his Ph.D. in philosophy in 1908. After holding a postdoctoral position at Harvard, Henry traveled to Europe on a fellowship. Upon returning to the United States, he became an academic nomad, spending one year each at the University of Washington, Cornell, the University of Minnesota, the University of Missouri, and City College in New York. In 1916 he returned to Harvard as a faculty member in the philosophy department. He remained at Harvard until his retirement in 1952. Courtesy of Harvard University Portrait Collection, Department of Philosophy Sheffer introduced what is now known as the Sheffer stroke in 1913; it became well known only after its use in the 1925 edition of Whitehead and Russell’s Principia Mathematica. In this same edition Russell wrote that Sheffer had invented a powerful method that could be used to simplify the Principia. Because of this comment, Sheffer was something of a mystery man to logicians, especially because Sheffer, who published little in his career, never published the details of this method, only describing it in mimeographed notes and in a brief published abstract. Sheffer was a dedicated teacher of mathematical logic. He liked his classes to be small and did not like auditors. When strangers appeared in his classroom, Sheffer would order them to leave, even his colleagues or distinguished guests visiting Harvard. Sheffer was barely five feet tall; he was noted for his wit and vigor, as well as for his nervousness and irritability. Although widely liked, he was quite lonely. He is noted for a quip he spoke at his retirement: “Old professors never die, they just become emeriti.” Sheffer is also credited with coining the term “Boolean algebra” (the subject of Chapter 12 of this text). Sheffer was briefly married and lived most of his later life in small rooms at a hotel packed with his logic books and vast files of slips of paper he used to jot down his ideas. Unfortunately, Sheffer suffered from severe depression during the last two decades of his life. 38 1 / The Foundations: Logic and Proofs Exercises 1. Use truth tables to verify these equivalences. a) p ∧ T ≡ p c) p ∧ F ≡ F e) p ∨ p ≡ p b) p ∨ F ≡ p d) p ∨ T ≡ T f) p∧p ≡ p 2. Show that ¬(¬p) and p are logically equivalent. 3. Use truth tables to verify the commutative laws a) p ∨ q ≡ q ∨ p. b) p ∧ q ≡ q ∧ p. 4. Use truth tables to verify the associative laws a) (p ∨ q) ∨ r ≡ p ∨ (q ∨ r). b) (p ∧ q) ∧ r ≡ p ∧ (q ∧ r). 5. Use a truth table to verify the distributive law p ∧ (q ∨ r) ≡ (p ∧ q) ∨ (p ∧ r). 6. Use a truth table to verify the first De Morgan law ¬(p ∧ q) ≡ ¬p ∨ ¬q. 7. Use De Morgan’s laws to find the negation of each of the following statements. a) Jan is rich and happy. b) Carlos will bicycle or run tomorrow. c) Mei walks or takes the bus to class. d) Ibrahim is smart and hard working. 8. Use De Morgan’s laws to find the negation of each of the following statements. a) Kwame will take a job in industry or go to graduate school. b) Yoshiko knows Java and calculus. c) James is young and strong. d) Rita will move to Oregon or Washington. 9. For each of these compound propositions, use the conditional-disjunction equivalence (Example 3) to find an equivalent compound proposition that does not involve conditionals. a) p → ¬q b) (p → q) → r c) (¬q → p) → (p → ¬q) 10. For each of these compound propositions, use the conditional-disjunction equivalence (Example 3) to find an equivalent compound proposition that does not involve conditionals. a) ¬p → ¬q b) (p ∨ q) → ¬p c) (p → ¬q) → (¬p → q) 11. Show that each of these conditional statements is a tau- tology by using truth tables. a) (p ∧ q) → p c) ¬p → (p → q) e) ¬(p → q) → p b) p → (p ∨ q) d) (p ∧ q) → (p → q) f ) ¬(p → q) → ¬q 12. Show that each of these conditional statements is a tau- tology by using truth tables. a) [¬p ∧ (p ∨ q)] → q b) [(p → q) ∧ (q → r)] → (p → r) c) [p ∧ (p → q)] → q d) [(p ∨ q) ∧ (p → r) ∧ (q → r)] → r 13. Show that each conditional statement in Exercise 11 is a tautology using the fact that a conditional statement is false exactly when the hypothesis is true and the conclusion is false. (Do not use truth tables.) 14. Show that each conditional statement in Exercise 12 is a tautology using the fact that a conditional statement is false exactly when the hypothesis is true and the conclusion is false. (Do not use truth tables.) 15. Show that each conditional statement in Exercise 11 is a tautology by applying a chain of logical identities as in Example 8. (Do not use truth tables.) 16. Show that each conditional statement in Exercise 12 is a tautology by applying a chain of logical identities as in Example 8. (Do not use truth tables.) 17. Use truth tables to verify the absorption laws. a) p ∨ (p ∧ q) ≡ p b) p ∧ (p ∨ q) ≡ p 18. Determine whether (¬p ∧ (p → q)) → ¬q is a tautology. 19. Determine whether (¬q ∧ (p → q)) → ¬p is a tautology. Each of Exercises 20–32 asks you to show that two compound propositions are logically equivalent. To do this, either show that both sides are true, or that both sides are false, for exactly the same combinations of truth values of the propositional variables in these expressions (whichever is easier). 20. Show that p ↔ q and (p ∧ q) ∨ (¬p ∧ ¬q) are logically equivalent. 21. Show that ¬(p ↔ q) and p ↔ ¬q are logically equivalent. 22. Show that p → q and ¬q → ¬p are logically equivalent. 23. Show that ¬p ↔ q and p ↔ ¬q are logically equivalent. 24. Show that ¬(p ⊕ q) and p ↔ q are logically equivalent. 25. Show that ¬(p ↔ q) and ¬p ↔ q are logically equivalent. 26. Show that (p → q) ∧ (p → r) and p → (q ∧ r) are logically equivalent. 27. Show that (p → r) ∧ (q → r) and (p ∨ q) → r are logically equivalent. 28. Show that (p → q) ∨ (p → r) and p → (q ∨ r) are logically equivalent. 29. Show that (p → r) ∨ (q → r) and (p ∧ q) → r are logically equivalent. 30. Show that ¬p → (q → r) and q → (p ∨ r) are logically equivalent. 31. Show that p ↔ q and (p → q) ∧ (q → p) are logically equivalent. 32. Show that p ↔ q and ¬p ↔ ¬q are logically equivalent. 33. Show that (p → q) ∧ (q → r) → (p → r) is a tautology. 34. Show that (p ∨ q) ∧ (¬p ∨ r) → (q ∨ r) is a tautology. 35. Show that (p → q) → r and p → (q → r) are not logically equivalent. 36. Show that (p ∧ q) → r and (p → r) ∧ (q → r) are not logically equivalent. 1.3 Propositional Equivalences 39 37. Show that (p → q) → (r → s) and (p → r) → (q → s) are not logically equivalent. The dual of a compound proposition that contains only the logical operators ∨, ∧, and ¬ is the compound proposition obtained by replacing each ∨ by ∧, each ∧ by ∨, each T by F, and each F by T. The dual of s is denoted by s∗. 38. Find the dual of each of these compound propositions. a) p ∨ ¬q c) (p ∧ ¬q) ∨ (q ∧ F) b) p ∧ (q ∨ (r ∧ T)) 39. Find the dual of each of these compound propositions. a) p ∧ ¬q ∧ ¬r c) (p ∨ F) ∧ (q ∨ T) b) (p ∧ q ∧ r) ∨ s 40. When does s∗ = s, where s is a compound proposition? 41. Show that (s∗)∗ = s when s is a compound proposition. 42. Show that the logical equivalences in Table 6, except for the double negation law, come in pairs, where each pair contains compound propositions that are duals of each other. ∗∗ 43. Why are the duals of two equivalent compound propositions also equivalent, where these compound propositions contain only the operators ∧, ∨, and ¬? 44. Find a compound proposition involving the propositional variables p, q, and r that is true when p and q are true and r is false, but is false otherwise. [Hint: Use a conjunction of each propositional variable or its negation.] 45. Find a compound proposition involving the propositional variables p, q, and r that is true when exactly two of p, q, and r are true and is false otherwise. [Hint: Form a disjunction of conjunctions. Include a conjunction for each combination of values for which the compound proposition is true. Each conjunction should include each of the three propositional variables or its negations.] 46. Suppose that a truth table in n propositional variables is specified. Show that a compound proposition with this truth table can be formed by taking the disjunction of conjunctions of the variables or their negations, with one conjunction included for each combination of values for which the compound proposition is true. The resulting compound proposition is said to be in disjunctive normal form. A collection of logical operators is called functionally complete if every compound proposition is logically equivalent to a compound proposition involving only these logical operators. 47. Show that ¬, ∧, and ∨ form a functionally complete collection of logical operators. [Hint: Use the fact that every compound proposition is logically equivalent to one in disjunctive normal form, as shown in Exercise 46.] ∗ 48. Show that ¬ and ∧ form a functionally complete collection of logical operators. [Hint: First use a De Morgan law to show that p ∨ q is logically equivalent to ¬(¬p ∧ ¬q).] ∗ 49. Show that ¬ and ∨ form a functionally complete collection of logical operators. We now present a group of exercises that involve the logical operators NAND and NOR. The proposition p NAND q is true when either p or q, or both, are false; and it is false when both p and q are true. The proposition p NOR q is true when both p and q are false, and it is false otherwise. The propositions p NAND q and p NOR q are denoted by p ∣ q and p ↓ q, respectively. (The operators | and ↓ are called the Sheffer stroke and the Peirce arrow after H. M. Sheffer and C. S. Peirce, respectively.) 50. Construct a truth table for the logical operator NAND. 51. Show that p ∣ q is logically equivalent to ¬(p ∧ q). 52. Construct a truth table for the logical operator NOR. 53. Show that p ↓ q is logically equivalent to ¬(p ∨ q). 54. In this exercise we will show that {↓} is a functionally complete collection of logical operators. a) Show that p ↓ p is logically equivalent to ¬p. b) Show that (p ↓ q) ↓ (p ↓ q) is logically equivalent to p ∨ q. c) Conclude from parts (a) and (b), and Exercise 49, that {↓} is a functionally complete collection of logical operators. ∗ 55. Find a compound proposition logically equivalent to p → q using only the logical operator ↓. 56. Show that {∣} is a functionally complete collection of logical operators. 57. Show that p ∣ q and q ∣ p are equivalent. 58. Show that p ∣ (q ∣ r) and (p ∣ q) ∣ r are not equivalent, so that the logical operator ∣ is not associative. ∗ 59. How many different truth tables of compound propositions are there that involve the propositional variables p and q? 60. Show that if p, q, and r are compound propositions such that p and q are logically equivalent and q and r are logically equivalent, then p and r are logically equivalent. 61. The following sentence is taken from the specification of a telephone system: “If the directory database is opened, then the monitor is put in a closed state, if the system is not in its initial state.” This specification is hard to understand because it involves two conditional statements. Find an equivalent, easier-to-understand specification that involves disjunctions and negations but not conditional statements. 62. How many of the disjunctions p ∨ ¬q, ¬p ∨ q, q ∨ r, q ∨ ¬r, and ¬q ∨ ¬r can be made simultaneously true by an assignment of truth values to p, q, and r? 63. How many of the disjunctions p ∨ ¬q ∨ s, ¬p ∨ ¬r ∨ s, ¬p ∨ ¬r ∨ ¬s, ¬p ∨ q ∨ ¬s, q ∨ r ∨ ¬s, q ∨ ¬r ∨ ¬s, ¬p ∨ ¬q ∨ ¬s, p ∨ r ∨ s, and p ∨ r ∨¬s can be made simultaneously true by an assignment of truth values to p, q, r, and s? 64. Show that the negation of an unsatisfiable compound proposition is a tautology and the negation of a compound proposition that is a tautology is unsatisfiable. 65. Determine whether each of these compound propositions is satisfiable. a) (p ∨ ¬q) ∧ (¬p ∨ q) ∧ (¬p ∨ ¬q) b) (p → q) ∧ (p → ¬q) ∧ (¬p → q) ∧ (¬p → ¬q) c) (p ↔ q) ∧ (¬p ↔ q) 40 1 / The Foundations: Logic and Proofs 66. Determine whether each of these compound propositions is satisfiable. a) (p ∨ q ∨ ¬r) ∧ (p ∨ ¬q ∨ ¬s) ∧ (p ∨ ¬r ∨ ¬s) ∧ (¬p ∨ ¬q ∨ ¬s) ∧ (p ∨ q ∨ ¬s) b) (¬p ∨ ¬q ∨ r) ∧ (¬p ∨ q ∨ ¬s) ∧ (p ∨ ¬q ∨ ¬s) ∧ (¬p ∨ ¬r ∨ ¬s) ∧ (p ∨ q ∨ ¬r) ∧ (p ∨ ¬r ∨ ¬s) c) (p ∨ q ∨ r) ∧ (p ∨ ¬q ∨ ¬s) ∧ (q ∨ ¬r ∨ s) ∧ (¬p ∨ r ∨ s) ∧ (¬p ∨ q ∨ ¬s) ∧ (p ∨ ¬q ∨ ¬r) ∧ (¬p ∨ ¬q ∨ s) ∧ (¬p ∨ ¬r ∨ ¬s) 67. Find the compound proposition Q constructed in Example 10 for the n-queens problem, and use it to find all the ways that n queens can be placed on an n × n chessboard, so that no queen can attack another when n is a) 2. b) 3. c) 4. 68. Starting with the compound proposition Q found in Ex- ample 10, construct a compound proposition that can be used to find all solutions of the n-queens problem where the queen in the first column is in an odd-numbered row. 69. Show how the solution of a given 4 × 4 Sudoku puzzle can be found by solving a satisfiability problem. 70. Construct a compound proposition that asserts that every cell of a 9 × 9 Sudoku puzzle contains at least one number. 71. Explain the steps in the construction of the compound proposition given in the text that asserts that every column of a 9 × 9 Sudoku puzzle contains every number. ∗ 72. Explain the steps in the construction of the compound proposition given in the text that asserts that each of the nine 3 × 3 blocks of a 9 × 9 Sudoku puzzle contains every number. 1.4 Predicates and Quantifiers 1.4.1 Introduction Propositional logic, studied in Sections 1.1–1.3, cannot adequately express the meaning of all statements in mathematics and in natural language. For example, suppose that we know that “Every computer connected to the university network is functioning properly.” No rules of propositional logic allow us to conclude the truth of the statement “MATH3 is functioning properly,” where MATH3 is one of the computers connected to the university network. Likewise, we cannot use the rules of propositional logic to conclude from the statement “CS2 is under attack by an intruder,” where CS2 is a computer on the university network, to conclude the truth of “There is a computer on the university network that is under attack by an intruder.” In this section we will introduce a more powerful type of logic called predicate logic. We will see how predicate logic can be used to express the meaning of a wide range of statements in mathematics and computer science in ways that permit us to reason and explore relationships between objects. To understand predicate logic, we first need to introduce the concept of a predicate. Afterward, we will introduce the notion of quantifiers, which enable us to reason with statements that assert that a certain property holds for all objects of a certain type and with statements that assert the existence of an object with a particular property. 1.4.2 Predicates Statements involving variables, such as “x > 3,” “x = y + 3,” “x + y = z,” 1.4 Predicates and Quantifiers 41 and “Computer x is under attack by an intruder,” and “Computer x is functioning properly,” are often found in mathematical assertions, in computer programs, and in system specifications. These statements are neither true nor false when the values of the variables are not specified. In this section, we will discuss the ways that propositions can be produced from such statements. The statement “x is greater than 3” has two parts. The first part, the variable x, is the subject of the statement. The second part—the predicate, “is greater than 3”—refers to a property that the subject of the statement can have. We can denote the statement “x is greater than 3” by P(x), where P denotes the predicate “is greater than 3” and x is the variable. The statement P(x) is also said to be the value of the propositional function P at x. Once a value has been assigned to the variable x, the statement P(x) becomes a proposition and has a truth value. Consider Examples 1 and 2. EXAMPLE 1 Let P(x) denote the statement “x > 3.” What are the truth values of P(4) and P(2)? Solution: We obtain the statement P(4) by setting x = 4 in the statement “x > 3.” Hence, P(4), which is the statement “4 > 3,” is true. However, P(2), which is the statement “2 > 3,” is false. ◂ EXAMPLE 2 Let A(x) denote the statement “Computer x is under attack by an intruder.” Suppose that of the computers on campus, only CS2 and MATH1 are currently under attack by intruders. What are truth values of A(CS1), A(CS2), and A(MATH1)? Solution: We obtain the statement A(CS1) by setting x = CS1 in the statement “Computer x is under attack by an intruder.” Because CS1 is not on the list of computers currently under attack, we conclude that A(CS1) is false. Similarly, because CS2 and MATH1 are on the list of computers under attack, we know that A(CS2) and A(MATH1) are true. ◂ We can also have statements that involve more than one variable. For instance, consider the statement “x = y + 3.” We can denote this statement by Q(x, y), where x and y are variables and Q is the predicate. When values are assigned to the variables x and y, the statement Q(x, y) has a truth value. EXAMPLE 3 Extra Examples Let Q(x, y) denote the statement “x = y + 3.” What are the truth values of the propositions Q(1, 2) and Q(3, 0)? Solution: To obtain Q(1, 2), set x = 1 and y = 2 in the statement Q(x, y). Hence, Q(1, 2) is the statement “1 = 2 + 3,” which is false. The statement Q(3, 0) is the proposition “3 = 0 + 3,” which is true. ◂ EXAMPLE 4 Let A(c, n) denote the statement “Computer c is connected to network n,” where c is a variable representing a computer and n is a variable representing a network. Suppose that the computer MATH1 is connected to network CAMPUS2, but not to network CAMPUS1. What are the values of A(MATH1, CAMPUS1) and A(MATH1, CAMPUS2)? 42 1 / The Foundations: Logic and Proofs Solution: Because MATH1 is not connected to the CAMPUS1 network, we see that A(MATH1, CAMPUS1) is false. However, because MATH1 is connected to the CAMPUS2 network, we see that A(MATH1, CAMPUS2) is true. ◂ Similarly, we can let R(x, y, z) denote the statement “x + y = z.” When values are assigned to the variables x, y, and z, this statement has a truth value. EXAMPLE 5 What are the truth values of the propositions R(1, 2, 3) and R(0, 0, 1)? Solution: The proposition R(1, 2, 3) is obtained by setting x = 1, y = 2, and z = 3 in the state- ment R(x, y, z). We see that R(1, 2, 3) is the statement “1 + 2 = 3,” which is true. Also note that R(0, 0, 1), which is the statement “0 + 0 = 1,” is false. ◂ In general, a statement involving the n variables x1, x2, … , xn can be denoted by P(x1, x2, … , xn). A statement of the form P(x1, x2, … , xn) is the value of the propositional function P at the n-tuple (x1, x2, … , xn), and P is also called an n-place predicate or an n-ary predicate. Propositional functions occur in computer programs, as Example 6 demonstrates. EXAMPLE 6 Consider the statement if x > 0 then x := x + 1. Links CHARLES SANDERS PEIRCE (1839–1914) Many consider Charles Peirce, born in Cambridge, Massachusetts, to be the most original and versatile American intellect. He made important contributions to an amazing number of disciplines, including mathematics, astronomy, chemistry, geodesy, metrology, engineering, psychology, philology, the history of science, and economics. Peirce was also an inventor, a lifelong student of medicine, a book reviewer, a dramatist and an actor, a short story writer, a phenomenologist, a logician, and a metaphysician. He is noted as the preeminent system-building philosopher competent and productive in logic, mathematics, and a wide range of sciences. He was encouraged by his father, Benjamin Peirce, a professor of mathematics and natural philosophy at Harvard, to pursue a career in science. Instead, he decided to study logic c Bettmann/Getty Images and scientific methodology. Peirce attended Harvard (1855–1859) and received a Harvard master of arts degree (1862) and an advanced degree in chemistry from the Lawrence Scientific School (1863). In 1861, Peirce became an aide in the U.S. Coast Survey, with the goal of better understanding scientific methodology. His service for the Survey exempted him from military service during the Civil War. While working for the Survey, Peirce did astronomical and geodesic work. He made fundamental contributions to the design of pendulums and to map projections, applying new mathematical developments in the theory of elliptic functions. He was the first person to use the wavelength of light as a unit of measurement. Peirce rose to the position of Assistant for the Survey, a position he held until forced to resign in 1891 when he disagreed with the direction taken by the Survey’s new administration. While making his living from work in the physical sciences, Peirce developed a hierarchy of sciences, with mathematics at the top rung, in which the methods of one science could be adapted for use by those sciences under it in the hierarchy. During this time, he also founded the American philosophical theory of pragmatism. The only academic position Peirce ever held was lecturer in logic at Johns Hopkins University in Baltimore (1879–1884). His mathematical work during this time included contributions to logic, set theory, abstract algebra, and the philosophy of mathematics. His work is still relevant today, with recent applications to artificial intelligence. Peirce believed that the study of mathematics could develop the mind’s powers of imagination, abstraction, and generalization. His diverse activities after retiring from the Survey included writing for periodicals, contributing to scholarly dictionaries, translating scientific papers, guest lecturing, and textbook writing. Unfortunately, his income from these pursuits was insufficient to protect him and his second wife from abject poverty. He was supported in his later years by a fund created by his many admirers and administered by the philosopher William James, his lifelong friend. Although Peirce wrote and published voluminously in a vast range of subjects, he left more than 100,000 pages of unpublished manuscripts. Because of the difficulty of studying his unpublished writings, scholars have only recently started to understand some of his varied contributions. A group of people is devoted to making his work available over the Internet to bring a better appreciation of Peirce’s accomplishments to the world. 1.4 Predicates and Quantifiers 43 When this statement is encountered in a program, the value of the variable x at that point in the execution of the program is inserted into P(x), which is “x > 0.” If P(x) is true for this value of x, the assignment statement x := x + 1 is executed, so the value of x is increased by 1. If P(x) is false for this value of x, the assignment statement is not executed, so the value of x is not changed. ◂ PRECONDITIONS AND POSTCONDITIONS Predicates are also used to establish the correctness of computer programs, that is, to show that computer programs always produce the desired output when given valid input. (Note that unless the correctness of a computer program is established, no amount of testing can show that it produces the desired output for all input values, unless every input value is tested.) The statements that describe valid input are known as preconditions and the conditions that the output should satisfy when the program has run are known as postconditions. As Example 7 illustrates, we use predicates to describe both preconditions and postconditions. We will study this process in greater detail in Section 5.5. EXAMPLE 7 Consider the following program, designed to interchange the values of two variables x and y. temp := x x := y y := temp Find predicates that we can use as the precondition and the postcondition to verify the correctness of this program. Then explain how to use them to verify that for all valid input the program does what is intended. Solution: For the precondition, we need to express that x and y have particular values before we run the program. So, for this precondition we can use the predicate P(x, y), where P(x, y) is the statement “x = a and y = b,” where a and b are the values of x and y before we run the program. Because we want to verify that the program swaps the values of x and y for all input values, for the postcondition we can use Q(x, y), where Q(x, y) is the statement “x = b and y = a.” To verify that the program always does what it is supposed to do, suppose that the pre- condition P(x, y) holds. That is, we suppose that the statement “x = a and y = b” is true. This means that x = a and y = b. The first step of the program, temp := x, assigns the value of x to the variable temp, so after this step we know that x = a, temp = a, and y = b. After the second step of the program, x := y, we know that x = b, temp = a, and y = b. Finally, after the third step, we know that x = b, temp = a, and y = a. Consequently, after this program is run, the postcondition Q(x, y) holds, that is, the statement “x = b and y = a” is true. ◂ Assessment 1.4.3 Quantifiers When the variables in a propositional function are assigned values, the resulting statement becomes a proposition with a certain truth value. However, there is another important way, called quantification, to create a proposition from a propositional function. Quantification expresses the extent to which a predicate is true over a range of elements. In English, the words all, some, many, none, and few are used in quantifications. We will focus on two types of quantification here: universal quantification, which tells us that a predicate is true for every element under consideration, and existential quantification, which tells us that there is one or more element under consideration for which the predicate is true. The area of logic that deals with predicates and quantifiers is called the predicate calculus. 44 1 / The Foundations: Logic and Proofs Assessment THE UNIVERSAL QUANTIFIER Many mathematical statements assert that a property is true for all values of a variable in a particular domain, called the domain of discourse (or the universe of discourse), often just referred to as the domain. Such a statement is expressed using universal quantification. The universal quantification of P(x) for a particular domain is the proposition that asserts that P(x) is true for all values of x in this domain. Note that the domain specifies the possible values of the variable x. The meaning of the universal quantification of P(x) changes when we change the domain. The domain must always be specified when a universal quantifier is used; without it, the universal quantification of a statement is not defined. Definition 1 The universal quantification of P(x) is the statement “P(x) for all values of x in the domain.” The notation ∀xP(x) denotes the universal quantification of P(x). Here ∀ is called the universal quantifier. We read ∀xP(x) as “for all xP(x)” or “for every xP(x).” An element for which P(x) is false is called a counterexample to ∀xP(x). The meaning of the universal quantifier is summarized in the first row of Table 1. We illustrate the use of the universal quantifier in Examples 8–12 and 15. EXAMPLE 8 Extra Examples Let P(x) be the statement “x + 1 > x.” What is the truth value of the quantification ∀xP(x), where the domain consists of all real numbers? Solution: Because P(x) is true for all real numbers x, the quantification ∀xP(x) is true. ◂ Remember that the truth value of ∀xP(x) depends on the domain! Remark: Generally, an implicit assumption is made that all domains of discourse for quantifiers are nonempty. Note that if the domain is empty, then ∀xP(x) is true for any propositional function P(x) because there are no elements x in the domain for which P(x) is false. Besides “for all” and “for every,” universal quantification can be expressed in many other ways, including “all of,” “for each,” “given any,” “for arbitrary,” “for each,” and “for any.” Remark: It is best to avoid using “for any x” because it is often ambiguous as to whether “any” means “every” or “some.” In some cases, “any” is unambiguous, such as when it is used in negatives: “There is not any reason to avoid studying.” A statement ∀xP(x) is false, where P(x) is a propositional function, if and only if P(x) is not always true when x is in the domain. One way to show that P(x) is not always true when x is in the domain is to find a counterexample to the statement ∀xP(x). Note that a single counterexample is all we need to establish that ∀xP(x) is false. Example 9 illustrates how counterexamples are used. TABLE 1 Quantifiers. Statement When True? ∀xP(x) ∃xP(x) P(x) is true for every x. There is an x for which P(x) is true. When False? There is an x for which P(x) is false. P(x) is false for every x. 1.4 Predicates and Quantifiers 45 EXAMPLE 9 Let Q(x) be the statement “x < 2.” What is the truth value of the quantification ∀xQ(x), where the domain consists of all real numbers? Solution: Q(x) is not true for every real number x, because, for instance, Q(3) is false. That is, x = 3 is a counterexample for the statement ∀xQ(x). Thus, ∀xQ(x) is false. ◂ EXAMPLE 10 Suppose that P(x) is “x2 > 0.” To show that the statement ∀xP(x) is false where the universe of discourse consists of all integers, we give a counterexample. We see that x = 0 is a counterex- ample because x2 = 0 when x = 0, so that x2 is not greater than 0 when x = 0. ◂ Looking for counterexamples to universally quantified statements is an important activity in the study of mathematics, as we will see in subsequent sections of this book. EXAMPLE 11 What does the statement ∀xN(x) mean if N(x) is “Computer x is connected to the network” and the domain consists of all computers on campus? Solution: The statement ∀xN(x) means that for every computer x on campus, that computer x is connected to the network. This statement can be expressed in English as “Every computer on campus is connected to the network.” ◂ EXAMPLE 12 As we have pointed out, specifying the domain is mandatory when quantifiers are used. The truth value of a quantified statement often depends on which elements are in this domain, as Example 12 shows. What is the truth value of ∀x(x2 ≥ x) if the domain consists of all real numbers? What is the truth value of this statement if the domain consists of all integers? Solution: The universal quantification ∀x(x2 ≥ x), where the domain consists of all real num- bers, is false. For example, ( 1 )2 ≱ 1 . Note that x2 ≥ x if and only if x2 − x = x(x − 1) ≥ 0. Con- 2 2 sequently, x2 ≥ x if and only if x ≤ 0 or x ≥ 1. It follows that ∀x(x2 ≥ x) is false if the domain consists of all real numbers (because the inequality is false for all real numbers x with 0 < x < 1). However, if the domain consists of the integers, ∀x(x2 ≥ x) is true, because there are no integers x with 0 < x < 1. ◂ THE EXISTENTIAL QUANTIFIER Many mathematical statements assert that there is an element with a certain property. Such statements are expressed using existential quantification. With existential quantification, we form a proposition that is true if and only if P(x) is true for at least one value of x in the domain. Definition 2 The existential quantification of P(x) is the proposition “There exists an element x in the domain such that P(x).” We use the notation ∃xP(x) for the existential quantification of P(x). Here ∃ is called the existential quantifier. 46 1 / The Foundations: Logic and Proofs A domain must always be specified when a statement ∃xP(x) is used. Furthermore, the meaning of ∃xP(x) changes when the domain changes. Without specifying the domain, the statement ∃xP(x) has no meaning. Besides the phrase “there exists,” we can also express existential quantification in many other ways, such as by using the words “for some,” “for at least one,” or “there is.” The existential quantification ∃xP(x) is read as “There is an x such that P(x),” “There is at least one x such that P(x),” or “For some xP(x).” The meaning of the existential quantifier is summarized in the second row of Table 1. We illustrate the use of the existential quantifier in Examples 13, 14, and 16. EXAMPLE 13 Extra Examples Let P(x) denote the statement “x > 3.” What is the truth value of the quantification ∃xP(x), where the domain consists of all real numbers? Solution: Because “x > 3” is sometimes true—for instance, when x = 4—the existential quan- tification of P(x), which is ∃xP(x), is true. ◂ Observe that the statement ∃xP(x) is false if and only if there is no element x in the domain for which P(x) is true. That is, ∃xP(x) is false if and only if P(x) is false for every element of the domain. We illustrate this observation in Example 14. EXAMPLE 14 Let Q(x) denote the statement “x = x + 1.” What is the truth value of the quantification ∃xQ(x), where the domain consists of all real numbers? Solution: Because Q(x) is false for every real number x, the existential quantification of Q(x), which is ∃xQ(x), is false. ◂ Remember that the truth value of ∃xP(x) depends on the domain! Remark: Generally, an implicit assumption is made that all domains of discourse for quantifiers are nonempty. If the domain is empty, then ∃xQ(x) is false whenever Q(x) is a propositional function because when the domain is empty, there can be no element x in the domain for which Q(x) is true. THE UNIQUENESS QUANTIFIER We have now introduced universal and existential quantifiers. These are the most important quantifiers in mathematics and computer science. However, there is no limitation on the number of different quantifiers we can define, such as “there are exactly two,” “there are no more than three,” “there are at least 100,” and so on. Of these other quantifiers, the one that is most often seen is the uniqueness quantifier, denoted by ∃! or ∃1. The notation ∃!xP(x) [or ∃1xP(x)] states “There exists a unique x such that P(x) is true.” (Other phrases for uniqueness quantification include “there is exactly one” and “there is one and only one.”) For instance, ∃!x(x − 1 = 0), where the domain is the set of real numbers, states that there is a unique real number x such that x − 1 = 0. This is a true statement, as x = 1 is the unique real number such that x − 1 = 0. Observe that we can use quantifiers and propositional logic to express uniqueness (see Exercise 52 in Section 1.5), so the uniqueness quantifier can be avoided. Generally, it is best to stick with existential and universal quantifiers so that rules of inference for these quantifiers can be used. 1.4 Predicates and Quantifiers 47 1.4.4 QUANTIFIERS OVER FINITE DOMAINS When the domain of a quantifier is finite, that is, when all its elements can be listed, quantified statements can be expressed using propositional logic. In particular, when the elements of the domain are x1, x2, …, xn, where n is a positive integer, the universal quantification ∀xP(x) is the same as the conjunction P(x1) ∧ P(x2) ∧ ⋯ ∧ P(xn), because this conjunction is true if and only if P(x1), P(x2), … , P(xn) are all true. EXAMPLE 15 What is the truth value of ∀xP(x), where P(x) is the statement “x2 < 10” and the domain consists of the positive integers not exceeding 4? Solution: The statement ∀xP(x) is the same as the conjunction P(1) ∧ P(2) ∧ P(3) ∧ P(4), because the domain consists of the integers 1, 2, 3, and 4. Because P(4), which is the statement “42 < 10,” is false, it follows that ∀xP(x) is false. ◂ Similarly, when the elements of the domain are x1, x2, … , xn, where n is a positive integer, the existential quantification ∃xP(x) is the same as the disjunction P(x1) ∨ P(x2) ∨ ⋯ ∨ P(xn), because this disjunction is true if and only if at least one of P(x1), P(x2), … , P(xn) is true. EXAMPLE 16 What is the truth value of ∃xP(x), where P(x) is the statement “x2 > 10” and the universe of discourse consists of the positive integers not exceeding 4? Solution: Because the domain is {1, 2, 3, 4}, the proposition ∃xP(x) is the same as the disjunction P(1) ∨ P(2) ∨ P(3) ∨ P(4). Because P(4), which is the statement “42 > 10,” is true, it follows that ∃xP(x) is true. ◂ CONNECTIONS BETWEEN QUANTIFICATION AND LOOPING It is sometimes helpful to think in terms of looping and searching when determining the truth value of a quantification. Suppose that there are n objects in the domain for the variable x. To determine whether ∀xP(x) is true, we can loop through all n values of x to see whether P(x) is always true. If we encounter a value x for which P(x) is false, then we have shown that ∀xP(x) is false. Otherwise, ∀xP(x) is true. To see whether ∃xP(x) is true, we loop through the n values of x searching for a value for which P(x) is true. If we find one, then ∃xP(x) is true. If we never find such an x, then we have determined that ∃xP(x) is false. (Note that this searching procedure does not apply if there are infinitely many values in the domain. However, it is still a useful way of thinking about the truth values of quantifications.) 48 1 / The Foundations: Logic and Proofs 1.4.5 Quantifiers with Restricted Domains An abbreviated notation is often used to restrict the domain of a quantifier. In this notation, a condition a variable must satisfy is included after the quantifier. This is illustrated in Example 17. We will also describe other forms of this notation involving set membership in Section 2.1. EXAMPLE 17 What do the statements ∀x < 0 (x2 > 0), ∀y ≠ 0 (y3 ≠ 0), and ∃z > 0 (z2 = 2) mean, where the domain in each case consists of the real numbers? Solution: The statement ∀x < 0 (x2 > 0) states that for every real number x with x < 0, x2 > 0. That is, it states “The square of a negative real number is positive.” This statement is the same as ∀x(x < 0 → x2 > 0). The statement ∀y ≠ 0 (y3 ≠ 0) states that for every real number y with y ≠ 0, we have y3 ≠ 0. That is, it states “The cube of every nonzero real number is nonzero.” This statement is equivalent to ∀y(y ≠ 0 → y3 ≠ 0). Finally, the statement ∃z > 0 (z2 = 2) states that there exists a real number z with z > 0 such that z2 = 2. That is, it states “There is a positive square root of 2.” This statement is equivalent to ∃z(z > 0 ∧ z2 = 2). ◂ Note that the restriction of a universal quantification is the same as the universal quantification of a conditional statement. For instance, ∀x < 0 (x2 > 0) is another way of expressing ∀x(x < 0 → x2 > 0). On the other hand, the restriction of an existential quantification is the same as the existential quantification of a conjunction. For instance, ∃z > 0 (z2 = 2) is another way of expressing ∃z(z > 0 ∧ z2 = 2). 1.4.6 Precedence of Quantifiers The quantifiers ∀ and ∃ have higher precedence than all logical operators from propositional calculus. For example, ∀xP(x) ∨ Q(x) is the disjunction of ∀xP(x) and Q(x). In other words, it means (∀xP(x)) ∨ Q(x) rather than ∀x(P(x) ∨ Q(x)). 1.4.7 Binding Variables When a quantifier is used on the variable x, we say that this occurrence of the variable is bound. An occurrence of a variable that is not bound by a quantifier or set equal to a particular value is said to be free. All the variables that occur in a propositional function must be bound or set equal to a particular value to turn it into a proposition. This can be done using a combination of universal quantifiers, existential quantifiers, and value assignments. The part of a logical expression to which a quantifier is applied is called the scope of this quantifier. Consequently, a variable is free if it is outside the scope of all quantifiers in the formula that specify this variable. EXAMPLE 18 In the statement ∃x(x + y = 1), the variable x is bound by the existential quantification ∃x, but the variable y is free because it is not bound by a quantifier and no value is assigned to this variable. This illustrates that in the statement ∃x(x + y = 1), x is bound, but y is free. In the statement ∃x(P(x) ∧ Q(x)) ∨ ∀xR(x), all variables are bound. The scope of the first quantifier, ∃x, is the expression P(x) ∧ Q(x), because ∃x is applied only to P(x) ∧ Q(x) and not to the rest of the statement. Similarly, the scope of the second quantifier, ∀x, is the expression R(x). That is, the existential quantifier binds the variable x in P(x) ∧ Q(x) and the universal quantifier ∀x binds the variable x in R(x). Observe that we could have written our statement using two different variables x and y, as ∃x(P(x) ∧ Q(x)) ∨ ∀yR(y), because the scopes of the two quantifiers do not overlap. The reader should be aware that in common usage, the same 1.4 Predicates and Quantifiers 49 letter is often used to represent variables bound by different quantifiers with scopes that do not overlap. ◂ 1.4.8 Logical Equivalences Involving Quantifiers In Section 1.3 we introduced the notion of logical equivalences of compound propositions. We can extend this notion to expressions involving predicates and quantifiers. Definition 3 Statements involving predicates and quantifiers are logically equivalent if and only if they have the same truth value no matter which predicates are substituted into these statements and which domain of discourse is used for the variables in these propositional functions. We use the notation S ≡ T to indicate that two statements S and T involving predicates and quantifiers are logically equivalent. Example 19 illustrates how to show that two statements involving predicates and quantifiers are logically equivalent. EXAMPLE 19 Show that ∀x(P(x) ∧ Q(x)) and ∀xP(x) ∧ ∀xQ(x) are logically equivalent (where the same domain is used throughout). This logical equivalence shows that we can distribute a universal quantifier over a conjunction. Furthermore, we can also distribute an existential quantifier over a disjunction. However, we cannot distribute a universal quantifier over a disjunction, nor can we distribute an existential quantifier over a conjunction. (See Exercises 52 and 53.) Solution: To show that these statements are logically equivalent, we must show that they always take the same truth value, no matter what the predicates P and Q are, and no matter which domain of discourse is used. Suppose we have particular predicates P and Q, with a common domain. We can show that ∀x(P(x) ∧ Q(x)) and ∀xP(x) ∧ ∀xQ(x) are logically equivalent by doing two things. First, we show that if ∀x(P(x) ∧ Q(x)) is true, then ∀xP(x) ∧ ∀xQ(x) is true. Second, we show that if ∀xP(x) ∧ ∀xQ(x) is true, then ∀x(P(x) ∧ Q(x)) is true. So, suppose that ∀x(P(x) ∧ Q(x)) is true. This means that if a is in the domain, then P(a) ∧ Q(a) is true. Hence, P(a) is true and Q(a) is true. Because P(a) is true and Q(a) is true for every element a in the domain, we can conclude that ∀xP(x) and ∀xQ(x) are both true. This means that ∀xP(x) ∧ ∀xQ(x) is true. Next, suppose that ∀xP(x) ∧ ∀xQ(x) is true. It follows that ∀xP(x) is true and ∀xQ(x) is true. Hence, if a is in the domain, then P(a) is true and Q(a) is true [because P(x) and Q(x) are both true for all elements in the domain, there is no conflict using the same value of a here]. It follows that for all a, P(a) ∧ Q(a) is true. It follows that ∀x(P(x) ∧ Q(x)) is true. We can now conclude that ∀x(P(x) ∧ Q(x)) ≡ ∀xP(x) ∧ ∀xQ(x). ◂ 1.4.9 Negating Quantified Expressions We will often want to consider the negation of a quantified expression. For instance, consider the negation of the statement “Every student in your class has taken a course in calculus.” This statement is a universal quantification, namely, ∀xP(x), 50 1 / The Foundations: Logic and Proofs Assessment where P(x) is the statement “x has taken a course in calculus” and the domain consists of the students in your class. The negation of this statement is “It is not the case that every student in your class has taken a course in calculus.” This is equivalent to “There is a student in your class who has not taken a course in calculus.” And this is simply the existential quantification of the negation of the original propositional function, namely, ∃x ¬P(x). This example illustrates the following logical equivalence: ¬∀xP(x) ≡ ∃x ¬P(x). To show that ¬∀xP(x) and ∃xP(x) are logically equivalent no matter what the propositional function P(x) is and what the domain is, first note that ¬∀xP(x) is true if and only if ∀xP(x) is false. Next, note that ∀xP(x) is false if and only if there is an element x in the domain for which P(x) is false. This holds if and only if there is an element x in the domain for which ¬P(x) is true. Finally, note that there is an element x in the domain for which ¬P(x) is true if and only if ∃x ¬P(x) is true. Putting these steps together, we can conclude that ¬∀xP(x) is true if and only if ∃x ¬P(x) is true. It follows that ¬∀xP(x) and ∃x ¬P(x) are logically equivalent. Suppose we wish to negate an existential quantification. For instance, consider the proposition “There is a student in this class who has taken a course in calculus.” This is the existential quantification ∃xQ(x), where Q(x) is the statement “x has taken a course in calculus.” The negation of this statement is the proposition “It is not the case that there is a student in this class who has taken a course in calculus.” This is equivalent to “Every student in this class has not taken calculus,” which is just the universal quantification of the negation of the original propositional function, or, phrased in the language of quantifiers, ∀x ¬Q(x). This example illustrates the equivalence ¬∃xQ(x) ≡ ∀x ¬Q(x). To show that ¬∃xQ(x) and ∀x ¬Q(x) are logically equivalent no matter what Q(x) is and what the domain is, first note that ¬∃xQ(x) is true if and only if ∃xQ(x) is false. This is true if and only if no x exists in the domain for which Q(x) is true. Next, note that no x exists in the domain for which Q(x) is true if and only if Q(x) is false for every x in the domain. Finally, note that Q(x) is false for every x in the domain if and only if ¬Q(x) is true for all x in the domain, which holds if and only if ∀x¬Q(x) is true. Putting these steps together, we see that ¬∃xQ(x) is true if and only if ∀x¬Q(x) is true. We conclude that ¬∃xQ(x) and ∀x ¬Q(x) are logically equivalent. The rules for negations for quantifiers are called De Morgan’s laws for quantifiers. These rules are summarized in Table 2. Remark: When the domain of a predicate P(x) consists of n elements, where n is a positive integer greater than one, the rules for negating quantified statements are exactly the same as De Morgan’s laws discussed in Section 1.3. This is why these rules are called De Morgan’s laws for quantifiers. When the domain has n elements x1, x2, … , xn, it follows that ¬∀xP(x) is the same as ¬(P(x1) ∧ P(x2) ∧ ⋯ ∧ P(xn)), which is equivalent to ¬P(x1) ∨ ¬P(x2) ∨ ⋯ ∨ ¬P(xn) by De Morgan’s laws, and this is the same as ∃x¬P(x). Similarly, ¬∃xP(x) is the same as ¬(P(x1) ∨ 1.4 Predicates and Quantifiers 51 TABLE 2 De Morgan’s Laws for Quantifiers. Negation Equivalent Statement When Is Negation True? ¬∃xP(x) ∀x¬P(x) For every x, P(x) is false. ¬∀xP(x) ∃x¬P(x) There is an x for which P(x) is false. When False? There is an x for which P(x) is true. P(x) is true for every x. P(x2) ∨ ⋯ ∨ P(xn)), which by De Morgan’s laws is equivalent to ¬P(x1) ∧ ¬P(x2) ∧ ⋯ ∧ ¬P(xn), and this is the same as ∀x¬P(x). We illustrate the negation of quantified statements in Examples 20 and 21. EXAMPLE 20 What are the negations of the statements “There is an honest politician” and “All Americans eat cheeseburgers”? Extra Examples Solution: Let H(x) denote “x is honest.” Then the statement “There is an honest politician” is rep- resented by ∃xH(x), where the domain consists of all politicians. The negation of this statement is ¬∃xH(x), which is equivalent to ∀x¬H(x). This negation can be expressed as “Every politician is dishonest.” (Note: In English, the statement “All politicians are not honest” is ambiguous. In common usage, this statement often means “Not all politicians are honest.” Consequently, we do not use this statement to express this negation.) Let C(x) denote “x eats cheeseburgers.” Then the statement “All Americans eat cheeseburg- ers” is represented by ∀xC(x), where the domain consists of all Americans. The negation of this statement is ¬∀xC(x), which is equivalent to ∃x¬C(x). This negation can be expressed in sev- eral different ways, including “Some American does not eat cheeseburgers” and “There is an American who does not eat cheeseburgers.” ◂ EXAMPLE 21 What are the negations of the statements ∀x(x2 > x) and ∃x(x2 = 2)? Solution: The negation of ∀x(x2 > x) is the statement ¬∀x(x2 > x), which is equivalent to ∃x¬(x2 > x). This can be rewritten as ∃x(x2 ≤ x). The negation of ∃x(x2 = 2) is the statement ¬∃x(x2 = 2), which is equivalent to ∀x¬(x2 = 2). This can be rewritten as ∀x(x2 ≠ 2). The truth values of these statements depend on the domain. ◂ We use De Morgan’s laws for quantifiers in Example 22. EXAMPLE 22 Show that ¬∀x(P(x) → Q(x)) and ∃x(P(x) ∧ ¬Q(x)) are logically equivalent. Solution: By De Morgan’s law for universal quantifiers, we know that ¬∀x(P(x) → Q(x)) and ∃x(¬(P(x) → Q(x))) are logically equivalent. By the fifth logical equivalence in Table 7 in Sec- tion 1.3, we know that ¬(P(x) → Q(x)) and P(x) ∧ ¬Q(x) are logically equivalent for every x. Because we can substitute one logically equivalent expression for another in a logical equiva- lence, it follows that ¬∀x(P(x) → Q(x)) and ∃x(P(x) ∧ ¬Q(x)) are logically equivalent. ◂ 1.4.10 Translating from English into Logical Expressions Translating sentences in English (or other natural languages) into logical expressions is a crucial task in mathematics, logic programming, artificial intelligence, software engineering, and many other disciplines. We began studying this topic in Section 1.1, where we used propositions 52 1 / The Foundations: Logic and Proofs to express sentences in logical expressions. In that discussion, we purposely avoided sentences whose translations required predicates and quantifiers. Translating from English to logical expressions becomes even more complex when quantifiers are needed. Furthermore, there can be many ways to translate a particular sentence. (As a consequence, there is no “cookbook” approach that can be followed step by step.) We will use some examples to illustrate how to translate sentences from English into logical expressions. The goal in this translation is to produce simple and useful logical expressions. In this section, we restrict ourselves to sentences that can be translated into logical expressions using a single quantifier; in the next section, we will look at more complicated sentences that require multiple quantifiers. EXAMPLE 23 Extra Examples Express the statement “Every student in this class has studied calculus” using predicates and quantifiers. Solution: First, we rewrite the statement so that we can clearly identify the appropriate quantifiers to use. Doing so, we obtain: “For every student in this class, that student has studied calculus.” Next, we introduce a variable x so that our statement becomes “For every student x in this class, x has studied calculus.” Continuing, we introduce C(x), which is the statement “x has studied calculus.” Consequently, if the domain for x consists of the students in the class, we can translate our statement as ∀xC(x). However, there are other correct approaches; different domains of discourse and other predicates can be used. The approach we select depends on the subsequent reasoning we want to carry out. For example, we may be interested in a wider group of people than only those in this class. If we change the domain to consist of all people, we will need to express our statement as “For every person x, if person x is a student in this class, then x has studied calculus.” If S(x) represents the statement that person x is in this class, we see that our statement can be expressed as ∀x(S(x) → C(x)). [Caution! Our statement cannot be expressed as ∀x(S(x) ∧ C(x)) because this statement says that all people are students in this class and have studied calculus!] Finally, when we are interested in the background of people in subjects besides calculus, we may prefer to use the two-variable quantifier Q(x, y) for the statement “Student x has stud- ied subject y.” Then we would replace C(x) by Q(x, calculus) in both approaches to obtain ∀xQ(x, calculus) or ∀x(S(x) → Q(x, calculus)). ◂ In Example 23 we displayed different approaches for expressing the same statement using predicates and quantifiers. However, we should always adopt the simplest approach that is adequate for use in subsequent reasoning. EXAMPLE 24 Express the statements “Some student in this class has visited Mexico” and “Every student in this class has visited either Canada or Mexico” using predicates and quantifiers. Solution: The statement “Some student in this class has visited Mexico” means that “There is a student in this class with the property that the student has visited Mexico.” We can introduce a variable x, so that our statement becomes “There is a student x in this class having the property that x has visited Mexico.” 1.4 Predicates and Quantifiers 53 We introduce M(x), which is the statement “x has visited Mexico.” If the domain for x consists of the students in this class, we can translate this first statement as ∃xM(x). However, if we are interested in people other than those in this class, we look at the statement a little differently. Our statement can be expressed as “There is a person x having the properties that x is a student in this class and x has visited Mexico.” In this case, the domain for the variable x consists of all people. We introduce S(x) to represent “x is a student in this class.” Our solution becomes ∃x(S(x) ∧ M(x)) because the statement is that there is a person x who is a student in this class and who has visited Mexico. [Caution! Our statement cannot be expressed as ∃x(S(x) → M(x)), which is true when there is someone not in the class because, in that case, for such a person x, S(x) → M(x) becomes either F → T or F → F, both of which are true.] Similarly, the second statement can be expressed as “For every x in this class, x has the property that x has visited Mexico or x has visited Canada.” (Note that we are assuming the inclusive, rather than the exclusive, or here.) We let C(x) be “x has visited Canada.” Following our earlier reasoning, we see that if the domain for x consists of the students in this class, this second statement can be expressed as ∀x(C(x) ∨ M(x)). However, if the domain for x consists of all people, our statement can be expressed as “For every person x, if x is a student in this class, then x has visited Mexico or x has visited Canada.” In this case, the statement can be expressed as ∀x(S(x) → (C(x) ∨ M(x))). Instead of using M(x) and C(x) to represent that x has visited Mexico and x has visited Canada, respectively, we could use a two-place predicate V(x, y) to represent “x has visited country y.” In this case, V(x, Mexico) and V(x, Canada) would have the same meaning as M(x) and C(x) and could replace them in our answers. If we are working with many state- ments that involve people visiting different countries, we might prefer to use this two-variable approach. Otherwise, for simplicity, we would stick with the one-variable predicates M(x) and C(x). ◂ 1.4.11 Using Quantifiers in System Specifications In Section 1.2 we used propositions to represent system specifications. However, many system specifications involve predicates and quantifications. This is illustrated in Example 25. EXAMPLE 25 Extra Examples Remember the rules of precedence for quantifiers and logical connectives! Use predicates and quantifiers to express the system specifications “Every mail message larger than one megabyte will be compressed” and “If a user is active, at least one network link will be available.” Solution: Let S(m, y) be “Mail message m is larger than y megabytes,” where the variable x has the domain of all mail messages and the variable y is a positive real number, and let C(m) denote “Mail message m will be compressed.” Then the specification “Every mail message larger than one megabyte will be compressed” can be represented as ∀m(S(m, 1) → C(m)). Let A(u) represent “User u is active,” where the variable u has the domain of all users, let S(n, x) denote “Network link n is in state x,” where n has the domain of all network links and x has the domain of all possible states for a network link. Then the specifica- tion “If a user is active, at least one network link will be available” can be represented by ∃uA(u) → ∃nS(n, available). ◂ 54 1 / The Foundations: Logic and Proofs 1.4.12 Examples from Lewis Carroll Lewis Carroll (really C. L. Dodgson writing under a pseudonym), the author of Alice in Wonderland, is also the author of several works on symbolic logic. His books contain many examples of reasoning using quantifiers. Examples 26 and 27 come from his book Symbolic Logic; other examples from that book are given in the exercises at the end of this section. These examples illustrate how quantifiers are used to express various types of statements. EXAMPLE 26 Consider these statements. The first two are called premises and the third is called the conclusion. The entire set is called an argument. “All lions are fierce.” “Some lions do not drink coffee.” “Some fierce creatures do not drink coffee.” (In Section 1.6 we will discuss the issue of determining whether the conclusion is a valid consequence of the premises. In this example, it is.) Let P(x), Q(x), and R(x) be the statements “x is a lion,” “x is fierce,” and “x drinks coffee,” respectively. Assuming that the domain consists of all creatures, express the statements in the argument using quantifiers and P(x), Q(x), and R(x). Solution: We can express these statements as ∀x(P(x) → Q(x)). ∃x(P(x) ∧ ¬R(x)). ∃x(Q(x) ∧ ¬R(x)). Notice that the second statement cannot be written as ∃x(P(x) → ¬R(x)). The reason is that P(x) → ¬R(x) is true whenever x is not a lion, so that ∃x(P(x) → ¬R(x)) is true as long as there is at least one creature that is not a lion, even if every lion drinks coffee. Similarly, the third statement cannot be written as ∃x(Q(x) → ¬R(x)). ◂ EXAMPLE 27 Consider these statements, of which the first three are premises and the fourth is a valid conclusion. “All hummingbirds are richly colored.” “No large birds live on honey.” “Birds that do not live on honey are dull in color.” “Hummingbirds are small.” Links c Oscar Gustav Rejlander/Hulton Archive/Getty Images CHARLES LUTWIDGE DODGSON (1832–1898) We know Charles Dodgson as Lewis Carroll—the pseudonym he used in his literary works. Dodgson, the son of a clergyman, was the third of 11 children, all of whom stuttered. He was uncomfortable in the company of adults and is said to have spoken without stuttering only to young girls, many of whom he entertained, corresponded with, and photographed (sometimes in poses that today would be considered inappropriate). Although attracted to young girls, he was extremely puritanical and religious. His friendship with the three young daughters of Dean Liddell led to his writing Alice in Wonderland, which brought him money and fame. Dodgson graduated from Oxford in 1854 and obtained his master of arts degree in 1857. He was appointed lecturer in mathematics at Christ Church College, Oxford, in 1855. He was ordained in the Church of England in 1861 but never practiced his ministry. His writings published under this real name include articles and books on geometry, determinants, and the mathematics of tournaments and elections. (He also used the pseudonym Lewis Carroll for his many works on recreational logic.) 1.4 Predicates and Quantifiers 55 Let P(x), Q(x), R(x), and S(x) be the statements “x is a hummingbird,” “x is large,” “x lives on honey,” and “x is richly colored,” respectively. Assuming that the domain consists of all birds, express the statements in the argument using quantifiers and P(x), Q(x), R(x), and S(x). Solution: We can express the statements in the argument as ∀x(P(x) → S(x)). ¬∃x(Q(x) ∧ R(x)). ∀x(¬R(x) → ¬S(x)). ∀x(P(x) → ¬Q(x)). (Note we have assumed that “small” is the same as “not large” and that “dull in color” is the same as “not richly colored.” To show that the fourth statement is a valid conclusion of the first three, we need to use rules of inference that will be discussed in Section 1.6.) ◂ 1.4.13 Logic Programming Links An important type of programming language is designed to reason using the rules of predicate logic. Prolog (from Programming in Logic), developed in the 1970s by computer scientists working in the area of artificial intelligence, is an example of such a language. Prolog programs include a set of declarations consisting of two types of statements, Prolog facts and Prolog rules. Prolog facts define predicates by specifying the elements that satisfy these predicates. Prolog rules are used to define new predicates using those already defined by Prolog facts. Example 28 illustrates these notions. EXAMPLE 28 Consider a Prolog program given facts telling it the instructor of each class and in which classes students are enrolled. The program uses these facts to answer queries concerning the professors who teach particular students. Such a program could use the predicates instructor(p, c) and enrolled(s, c) to represent that professor p is the instructor of course c and that student s is enrolled in course c, respectively. For example, the Prolog facts in such a program might include: instructor(chan,math273) instructor(patel,ee222) instructor(grossman,cs301) enrolled(kevin,math273) enrolled(juana,ee222) enrolled(juana,cs301) enrolled(kiko,math273) enrolled(kiko,cs301) (Lowercase letters have been used for entries because Prolog considers names beginning with an uppercase letter to be variables.) A new predicate teaches(p, s), representing that professor p teaches student s, can be defined using the Prolog rule teaches(P,S) :- instructor(P,C), enrolled(S,C) which means that teaches(p, s) is true if there exists a class c such that professor p is the instructor of class c and student s is enrolled in class c. (Note that a comma is used to represent a conjunction of predicates in Prolog. Similarly, a semicolon is used to represent a disjunction of predicates.) 56 1 / The Foundations: Logic and Proofs Exercises Prolog answers queries using the facts and rules it is given. For example, using the facts and rules listed, the query ?enrolled(kevin,math273) produces the response yes because the fact enrolled(kevin, math273) was provided as input. The query ?enrolled(X,math273) produces the response kevin kiko To produce this response, Prolog determines all possible values of X for which enrolled(X, math273) has been included as a Prolog fact. Similarly, to find all the professors who are instructors in classes being taken by Juana, we use the query ?teaches(X,juana) This query returns patel grossman ◂ 1. Let P(x) denote the statement “x ≤ 4.” What are these truth values? a) P(0) b) P(4) c) P(6) 2. Let P(x) be the statement “The word x contains the letter a.” What are these truth values? a) P(orange) c) P(true) b) P(lemon) d) P(false) 3. Let Q(x, y) denote the statement “x is the capital of y.” What are these truth values? a) Q(Denver, Colorado) b) Q(Detroit, Michigan) c) Q(Massachusetts, Boston) d) Q(New York, New York) 4. State the value of x after the statement if P(x) then x := 1 is executed, where P(x) is the statement “x > 1,” if the value of x when this statement is reached is a) x = 0. c) x = 2. b) x = 1. 5. Let P(x) be the statement “x spends more than five hours every weekday in class,” where the domain for x consists of all students. Express each of these quantifications in English. a) ∃xP(x) c) ∃x ¬P(x) b) ∀xP(x) d) ∀x ¬P(x) 6. Let N(x) be the statement “x has visited North Dakota,” where the domain consists of the students in your school. Express each of these quantifications in English. a) ∃xN(x) d) ∃x¬N(x) b) ∀xN(x) e) ¬∀xN(x) c) ¬∃xN(x) f ) ∀x¬N(x) 7. Translate these statements into English, where C(x) is “x is a comedian” and F(x) is “x is funny” and the domain consists of all people. a) ∀x(C(x) → F(x)) c) ∃x(C(x) → F(x)) b) ∀x(C(x) ∧ F(x)) d) ∃x(C(x) ∧ F(x)) 8. Translate these statements into English, where R(x) is “x is a rabbit” and H(x) is “x hops” and the domain consists of all animals. a) ∀x(R(x) → H(x)) c) ∃x(R(x) → H(x)) b) ∀x(R(x) ∧ H(x)) d) ∃x(R(x) ∧ H(x)) 9. Let P(x) be the statement “x can speak Russian” and let Q(x) be the statement “x knows the computer language C++.” Express each of these sentences in terms of P(x), Q(x), quantifiers, and logical connectives. The domain for quantifiers consists of all students at your school. a) There is a student at your school who can speak Russian and who knows C++. b) There is a student at your school who can speak Russian but who doesn’t know C++. c) Every student at your school either can speak Russian or knows C++. d) No student at your school can speak Russian or knows C++. 10. Let C(x) be the statement “x has a cat,” let D(x) be the statement “x has a dog,” and let F(x) be the statement “x has a ferret.” Express each of these statements in terms of C(x), D(x), F(x), quantifiers, and logical connectives. Let the domain consist of all students in your class. a) A student in your class has a cat, a dog, and a ferret. b) All students in your class have a cat, a dog, or a ferret. c) Some student in your class has a cat and a ferret, but not a dog. d) No student in your class has a cat, a dog, and a ferret. e) For each of the three animals, cats, dogs, and ferrets, there is a student in your class who has this animal as a pet. 11. Let P(x) be the statement “x = x2.” If the domain consists of the integers, what are these truth values? a) P(0) b) P(1) c) P(2) d) P(−1) e) ∃xP(x) f ) ∀xP(x) 12. Let Q(x) be the statement “x + 1 > 2x.” If the domain consists of all integers, what are these truth values? a) Q(0) b) Q(−1) c) Q(1) d) ∃xQ(x) e) ∀xQ(x) f ) ∃x¬Q(x) g) ∀x¬Q(x) 13. Determine the truth value of each of these statements if the domain consists of all integers. a) ∀n(n + 1 > n) b) ∃n(2n = 3n) c) ∃n(n = −n) d) ∀n(3n ≤ 4n) 14. Determine the truth value of each of these statements if the domain consists of all real numbers. a) ∃x(x3 = −1) b) ∃x(x4 < x2) c) ∀x((−x)2 = x2) d) ∀x(2x > x) 15. Determine the truth value of each of these statements if the domain for all variables consists of all integers. a) ∀n(n2 ≥ 0) b) ∃n(n2 = 2) c) ∀n(n2 ≥ n) d) ∃n(n2 < 0) 16. Determine the truth value of each of these statements if the domain of each variable consists of all real numbers. a) ∃x(x2 = 2) b) ∃x(x2 = −1) c) ∀x(x2 + 2 ≥ 1) d) ∀x(x2 ≠ x) 17. Suppose that the domain of the propositional function P(x) consists of the integers 0, 1, 2, 3, and 4. Write out each of these propositions using disjunctions, conjunctions, and negations. a) ∃xP(x) b) ∀xP(x) c) ∃x¬P(x) d) ∀x¬P(x) e) ¬∃xP(x) f ) ¬∀xP(x) 1.4 Predicates and Quantifiers 57 18. Suppose that the domain of the propositional function P(x) consists of the integers −2, −1, 0, 1, and 2. Write out each of these propositions using disjunctions, conjunctions, and negations. a) ∃xP(x) d) ∀x¬P(x) b) ∀xP(x) e) ¬∃xP(x) c) ∃x¬P(x) f ) ¬∀xP(x) 19. Suppose that the domain of the propositional function P(x) consists of the integers 1, 2, 3, 4, and 5. Express these statements without using quantifiers, instead using only negations, disjunctions, and conjunctions. a) ∃xP(x) b) ∀xP(x) c) ¬∃xP(x) d) ¬∀xP(x) e) ∀x((x ≠ 3) → P(x)) ∨ ∃x¬P(x) 20. Suppose that the domain of the propositional function P(x) consists of −5, −3, −1, 1, 3, and 5. Express these statements without using quantifiers, instead using only negations, disjunctions, and conjunctions. a) ∃xP(x) b) ∀xP(x) c) ∀x((x ≠ 1) → P(x)) d) ∃x((x ≥ 0) ∧ P(x)) e) ∃x(¬P(x)) ∧ ∀x((x < 0) → P(x)) 21. For each of these statements find a domain for which the statement is true and a domain for which the statement is false. a) Everyone is studying discrete mathematics. b) Everyone is older than 21 years. c) Every two people have the same mother. d) No two different people have the same grandmother. 22. For each of these statements find a domain for which the statement is true and a domain for which the statement is false. a) Everyone speaks Hindi. b) There is someone older than 21 years. c) Every two people have the same first name. d) Someone knows more than two other people. 23. Translate in two ways each of these statements into logical expressions using predicates, quantifiers, and logical connectives. First, let the domain consist of the students in your class and second, let it consist of all people. a) Someone in your class can speak Hindi. b) Everyone in your class is friendly. c) There is a person in your class who was not born in California. d) A student in your class has been in a movie. e) No student in your class has taken a course in logic programming. 24. Translate in two ways each of these statements into logical expressions using predicates, quantifiers, and logical connectives. First, let the domain consist of the students in your class and second, let it consist of all people. a) Everyone in your class has a cellular phone. b) Somebody in your class has seen a foreign movie. c) There is a person in your class who cannot swim. d) All students in your class can solve quadratic equa- tions. e) Some student in your class does not want to be rich. 25. Translate each of these statements into logical expressions using predicates, quantifiers, and logical connectives. 58 1 / The Foundations: Logic and Proofs a) No one is perfect. b) Not everyone is perfect. c) All your friends are perfect. d) At least one of your friends is perfect. e) Everyone is your friend and is perfect. f ) Not everybody is your friend or someone is not perfect. 26. Translate each of these statements into logical expressions in three different ways by varying the domain and by using predicates with one and with two variables. a) Someone in your school has visited Uzbekistan. b) Everyone in your class has studied calculus and C++. c) No one in your school owns both a bicycle and a motorcycle. d) There is a person in your school who is not happy. e) Everyone in your school was born in the twentieth century. 27. Translate each of these statements into logical expressions in three different ways by varying the domain and by using predicates with one and with two variables. a) A student in your school has lived in Vietnam. b) There is a student in your school who cannot speak Hindi. c) A student in your school knows Java, Prolog, and C++. d) Everyone in your class enjoys Thai food. e) Someone in your class does not play hockey. 28. Translate each of these statements into logical expres- sions using predicates, quantifiers, and logical connectives. a) Something is not in the correct place. b) All tools are in the correct place and are in excellent condition. c) Everything is in the correct place and in excellent condition. d) Nothing is in the correct place and is in excellent condition. e) One of your tools is not in the correct place, but it is in excellent condition. 29. Express each of these statements using logical operators, predicates, and quantifiers. a) Some propositions are tautologies. b) The negation of a contradiction is a tautology. c) The disjunction of two contingencies can be a tautology. d) The conjunction of two tautologies is a tautology. 30. Suppose the domain of the propositional function P(x, y) consists of pairs x and y, where x is 1, 2, or 3 and y is 1, 2, or 3. Write out these propositions using disjunctions and conjunctions. a) ∃x P(x, 3) c) ∃y¬P(2, y) b) ∀y P(1, y) d) ∀x ¬P(x, 2) 31. Suppose that the domain of Q(x, y, z) consists of triples x, y, z, where x = 0, 1, or 2, y = 0 or 1, and z = 0 or 1. Write out these propositions using disjunctions and conjunctions. a) ∀yQ(0, y, 0) c) ∃z¬Q(0, 0, z) b) ∃xQ(x, 1, 1) d) ∃x¬Q(x, 0, 1) 32. Express each of these statements using quantifiers. Then form the negation of the statement so that no negation is to the left of a quantifier. Next, express the negation in simple English. (Do not simply use the phrase “It is not the case that.”) a) All dogs have fleas. b) There is a horse that can add. c) Every koala can climb. d) No monkey can speak French. e) There exists a pig that can swim and catch fish. 33. Express each of these statements using quantifiers. Then form the negation of the statement, so that no negation is to the left of a quantifier. Next, express the negation in simple English. (Do not simply use the phrase “It is not the case that.”) a) Some old dogs can learn new tricks. b) No rabbit knows calculus. c) Every bird can fly. d) There is no dog that can talk. e) There is no one in this class who knows French and Russian. 34. Express the negation of these propositions using quantifiers, and then express the negation in English. a) Some drivers do not obey the speed limit. b) All Swedish movies are serious. c) No one can keep a secret. d) There is someone in this class who does not have a good attitude. 35. Express the negation of each of these statements in terms of quantifiers without using the negation symbol. a) ∀x(x > 1) b) ∀x(x ≤ 2) c) ∃x(x ≥ 4) d) ∃x(x < 0) e) ∀x((x < −1) ∨ (x > 2)) f ) ∃x((x < 4) ∨ (x > 7)) 36. Express the negation of each of these statements in terms of quantifiers without using the negation symbol. a) ∀x(−2 < x < 3) b) ∀x(0 ≤ x < 5) c) ∃x(−4 ≤ x ≤ 1) d) ∃x(−5 < x < −1) 37. Find a counterexample, if possible, to these universally quantified statements, where the domain for all variables consists of all integers. a) ∀x(x2 ≥ x) b) ∀x(x > 0 ∨ x < 0) c) ∀x(x = 1) 38. Find a counterexample, if possible, to these universally quantified statements, where the domain for all variables consists of all real numbers. a) ∀x(x2 ≠ x) c) ∀x(|x| > 0) b) ∀x(x2 ≠ 2) 39. Express each of these statements using predicates and quantifiers. a) A passenger on an airline qualifies as an elite flyer if the passenger flies more than 25,000 miles in a year or takes more than 25 flights during that year. b) A man qualifies for the marathon if his best previous time is less than 3 hours and a woman qualifies for the marathon if her best previous time is less than 3.5 hours. c) A student must take at least 60 course hours, or at least 45 course hours and write a master’s thesis, and receive a grade no lower than a B in all required courses, to receive a master’s degree. d) There is a student who has taken more than 21 credit hours in a semester and received all A’s. Exercises 40–44 deal with the translation between system specification and logical expressions involving quantifiers. 40. Translate these system specifications into English, where the predicate S(x, y) is “x is in state y” and where the domain for x and y consists of all systems and all possible states, respectively. a) ∃xS(x, open) b) ∀x(S(x, malfunctioning) ∨ S(x, diagnostic)) c) ∃xS(x, open) ∨ ∃xS(x, diagnostic) d) ∃x¬S(x, available) e) ∀x¬S(x, working) 41. Translate these specifications into English, where F(p) is “Printer p is out of service,” B(p) is “Printer p is busy,” L(j) is “Print job j is lost,” and Q(j) is “Print job j is queued.” a) ∃p(F(p) ∧ B(p)) → ∃jL(j) b) ∀pB(p) → ∃jQ(j) c) ∃j(Q(j) ∧ L(j)) → ∃pF(p) d) (∀pB(p) ∧ ∀jQ(j)) → ∃jL(j) 42. Express each of these system specifications using predicates, quantifiers, and logical connectives. a) When there is less than 30 megabytes free on the hard disk, a warning message is sent to all users. b) No directories in the file system can be opened and no files can be closed when system errors have been detected. c) The file system cannot be backed up if there is a user currently logged on. d) Video on demand can be delivered when there are at least 8 megabytes of memory available and the connection speed is at least 56 kilobits per second. 43. Express each of these system specifications using predicates, quantifiers, and logical connectives. a) At least one mail message, among the nonempty set of messages, can be saved if there is a disk with more than 10 kilobytes of free space. 1.4 Predicates and Quantifiers 59 b) Whenever there is an active alert, all queued messages are transmitted. c) The diagnostic monitor tracks the status of all systems except the main console. d) Each participant on the conference call whom the host of the call did not put on a special list was billed. 44. Express each of these system specifications using predi- cates, quantifiers, and logical connectives. a) Every user has access to an electronic mailbox. b) The system mailbox can be accessed by everyone in the group if the file system is locked. c) The firewall is in a diagnostic state only if the proxy server is in a diagnostic state. d) At least one router is functioning normally if the throughput is between 100 kbps and 500 kbps and the proxy server is not in diagnostic mode. 45. Determine whether ∀x(P(x) → Q(x)) and ∀xP(x) → ∀xQ(x) are logically equivalent. Justify your answer. 46. Determine whether ∀x(P(x) ↔ Q(x)) and ∀x P(x) ↔ ∀xQ(x) are logically equivalent. Justify your answer. 47. Show that ∃x(P(x) ∨ Q(x)) and ∃xP(x) ∨ ∃xQ(x) are logically equivalent. Exercises 48–51 establish rules for null quantification that we can use when a quantified variable does not appear in part of a statement. 48. Establish these logical equivalences, where x does not occur as a free variable in A. Assume that the domain is nonempty. a) (∀xP(x)) ∨ A ≡ ∀x(P(x) ∨ A) b) (∃xP(x)) ∨ A ≡ ∃x(P(x) ∨ A) 49. Establish these logical equivalences, where x does not occur as a free variable in A. Assume that the domain is nonempty. a) (∀xP(x)) ∧ A ≡ ∀x(P(x) ∧ A) b) (∃xP(x)) ∧ A ≡ ∃x(P(x) ∧ A) 50. Establish these logical equivalences, where x does not oc- cur as a free variable in A. Assume that the domain is nonempty. a) ∀x(A → P(x)) ≡ A → ∀xP(x) b) ∃x(A → P(x)) ≡ A → ∃xP(x) 51. Establish these logical equivalences, where x does not oc- cur as a free variable in A. Assume that the domain is nonempty. a) ∀x(P(x) → A) ≡ ∃xP(x) → A b) ∃x(P(x) → A) ≡ ∀xP(x) → A 52. Show that ∀xP(x) ∨ ∀xQ(x) and ∀x(P(x) ∨ Q(x)) are not logically equivalent. 53. Show that ∃xP(x) ∧ ∃xQ(x) and ∃x(P(x) ∧ Q(x)) are not logically equivalent. 54. As mentioned in the text, the notation ∃!xP(x) denotes “There exists a unique x such that P(x) is true.” If the domain consists of all integers, what are the truth values of these statements? a) ∃!x(x > 1) c) ∃!x(x + 3 = 2x) b) ∃!x(x2 = 1) d) ∃!x(x = x + 1) 60 1 / The Foundations: Logic and Proofs 55. What are the truth values of these statements? a) ∃!xP(x) → ∃xP(x) b) ∀xP(x) → ∃!xP(x) c) ∃!x¬P(x) → ¬∀xP(x) 56. Write out ∃!xP(x), where the domain consists of the integers 1, 2, and 3, in terms of negations, conjunctions, and disjunctions. 57. Given the Prolog facts in Example 28, what would Prolog return given these queries? a) ?instructor(chan,math273) b) ?instructor(patel,cs301) c) ?enrolled(X,cs301) d) ?enrolled(kiko,Y) e) ?teaches(grossman,Y) 58. Given the Prolog facts in Example 28, what would Prolog return when given these queries? a) ?enrolled(kevin,ee222) b) ?enrolled(kiko,math273) c) ?instructor(grossman,X) d) ?instructor(X,cs301) e) ?teaches(X,kevin) 59. Suppose that Prolog facts are used to define the predicates mother(M, Y) and father(F, X), which represent that M is the mother of Y and F is the father of X, respectively. Give a Prolog rule to define the predicate sibling(X, Y), which represents that X and Y are siblings (that is, have the same mother and the same father). 60. Suppose that Prolog facts are used to define the predicates mother(M, Y) and father(F, X), which represent that M is the mother of Y and F is the father of X, respectively. Give a Prolog rule to define the predicate grandfather(X, Y), which represents that X is the grandfather of Y. [Hint: You can write a disjunction in Prolog either by using a semicolon to separate predicates or by putting these predicates on separate lines.] Exercises 61–64 are based on questions found in the book Symbolic Logic by Lewis Carroll. 61. Let P(x), Q(x), and R(x) be the statements “x is a profes- sor,” “x is ignorant,” and “x is vain,” respectively. Express each of these statements using quantifiers; logical connectives; and P(x), Q(x), and R(x), where the domain consists of all people. a) No professors are ignorant. b) All ignorant people are vain. c) No professors are vain. d) Does (c) follow from (a) and (b)? 62. Let P(x), Q(x), and R(x) be the statements “x is a clear explanation,” “x is satisfactory,” and “x is an excuse,” respectively. Suppose that the domain for x consists of all English text. Express each of these statements using quantifiers, logical connectives, and P(x), Q(x), and R(x). a) All clear explanations are satisfactory. b) Some excuses are unsatisfactory. c) Some excuses are not clear explanations. ∗ d) Does (c) follow from (a) and (b)? 63. Let P(x), Q(x), R(x), and S(x) be the statements “x is a baby,” “x is logical,” “x is able to manage a crocodile,” and “x is despised,” respectively. Suppose that the domain consists of all people. Express each of these statements using quantifiers; logical connectives; and P(x), Q(x), R(x), and S(x). a) Babies are illogical. b) Nobody is despised who can manage a crocodile. c) Illogical persons are despised. d) Babies cannot manage crocodiles. ∗ e) Does (d) follow from (a), (b), and (c)? If not, is there a correct conclusion? 64. Let P(x), Q(x), R(x), and S(x) be the statements “x is a duck,” “x is one of my poultry,” “x is an officer,” and “x is willing to waltz,” respectively. Express each of these statements using quantifiers; logical connectives; and P(x), Q(x), R(x), and S(x). a) No ducks are willing to waltz. b) No officers ever decline to waltz. c) All my poultry are ducks. d) My poultry are not officers. ∗ e) Does (d) follow from (a), (b), and (c)? If not, is there a correct conclusion? 1.5 Nested Quantifiers 1.5.1 Introduction In Section 1.4 we defined the existential and universal quantifiers and showed how they can be used to represent mathematical statements. We also explained how they can be used to translate English sentences into logical expressions. However, in Section 1.4 we avoided nested quantifiers, where one quantifier is within the scope of another, such as ∀x∃y(x + y = 0). 1.5 Nested Quantifiers 61 Note that everything within the scope of a quantifier can be thought of as a propositional function. For example, ∀x∃y(x + y = 0) is the same thing as ∀xQ(x), where Q(x) is ∃yP(x, y), where P(x, y) is x + y = 0. Nested quantifiers commonly occur in mathematics and computer science. Although nested quantifiers can sometimes be difficult to understand, the rules we have already studied in Section 1.4 can help us use them. In this section we will gain experience working with nested quantifiers. We will see how to use nested quantifiers to express mathematical statements such as “The sum of two positive integers is always positive.” We will show how nested quantifiers can be used to translate English sentences such as “Everyone has exactly one best friend” into logical statements. Moreover, we will gain experience working with the negations of statements involving nested quantifiers. 1.5.2 Understanding Statements Involving Nested Quantifiers To understand statements involving nested quantifiers, we need to unravel what the quantifiers and predicates that appear mean. This is illustrated in Examples 1 and 2. EXAMPLE 1 Assume that the domain for the variables x and y consists of all real numbers. The statement ∀x∀y(x + y = y + x) Extra Examples says that x + y = y + x for all real numbers x and y. This is the commutative law for addition of real numbers. Likewise, the statement ∀x∃y(x + y = 0) says that for every real number x there is a real number y such that x + y = 0. This states that every real number has an additive inverse. Similarly, the statement ∀x∀y∀z(x + (y + z) = (x + y) + z) is the associative law for addition of real numbers. ◂ EXAMPLE 2 Translate into English the statement ∀x∀y((x > 0) ∧ (y < 0) → (xy < 0)), where the domain for both variables consists of all real numbers. Solution: This statement says that for every real number x and for every real number y, if x > 0 and y < 0, then xy < 0. That is, this statement says that for real numbers x and y, if x is positive and y is negative, then xy is negative. This can be stated more succinctly as “The product of a positive real number and a negative real number is always a negative real number.” ◂ THINKING OF QUANTIFICATION AS LOOPS In working with quantifications of more than one variable, it is sometimes helpful to think in terms of nested loops. (If there are infinitely many elements in the domain of some variable, we cannot actually loop through all values. Nevertheless, this way of thinking is helpful in understanding nested quantifiers.) For example, to see whether ∀x∀yP(x, y) is true, we loop through the values for x, and for each x we loop through the values for y. If we find that for all values of x that P(x, y) is true for all values of y, 62 1 / The Foundations: Logic and Proofs we have determined that ∀x∀yP(x, y) is true. If we ever hit a value x for which we hit a value y for which P(x, y) is false, we have shown that ∀x∀yP(x, y) is false. Similarly, to determine whether ∀x∃yP(x, y) is true, we loop through the values for x. For each x we loop through the values for y until we find a y for which P(x, y) is true. If for every x we hit such a y, then ∀x∃yP(x, y) is true; if for some x we never hit such a y, then ∀x∃yP(x, y) is false. To see whether ∃x∀yP(x, y) is true, we loop through the values for x until we find an x for which P(x, y) is always true when we loop through all values for y. Once we find such an x, we know that ∃x∀yP(x, y) is true. If we never hit such an x, then we know that ∃x∀yP(x, y) is false. Finally, to see whether ∃x∃yP(x, y) is true, we loop through the values for x, where for each x we loop through the values for y until we hit an x for which we hit a y for which P(x, y) is true. The statement ∃x∃yP(x, y) is false only if we never hit an x for which we hit a y such that P(x, y) is true. 1.5.3 The Order of Quantifiers Many mathematical statements involve multiple quantifications of propositional functions involving more than one variable. It is important to note that the order of the quantifiers is important, unless all the quantifiers are universal quantifiers or all are existential quantifiers. These remarks are illustrated by Examples 3–5. EXAMPLE 3 Extra Examples Let P(x, y) be the statement “x + y = y + x.” What are the truth values of the quantifications ∀x∀yP(x, y) and ∀y∀xP(x, y), where the domain for all variables consists of all real numbers? Solution: The quantification ∀x∀yP(x, y) denotes the proposition “For all real numbers x, for all real numbers y, x + y = y + x.” Because P(x, y) is true for all real numbers x and y (it is the commutative law for addition, which is an axiom for the real numbers—see Appendix 1), the proposition ∀x∀yP(x, y) is true. Note that the statement ∀y∀xP(x, y) says “For all real numbers y, for all real numbers x, x + y = y + x.” This has the same meaning as the statement “For all real numbers x, for all real numbers y, x + y = y + x.” That is, ∀x∀yP(x, y) and ∀y∀xP(x, y) have the same meaning, and both are true. This illustrates the principle that the order of nested universal quantifiers in a statement without other quantifiers can be changed without changing the meaning of the quantified statement. ◂ EXAMPLE 4 Let Q(x, y) denote “x + y = 0.” What are the truth values of the quantifications ∃y∀xQ(x, y) and ∀x∃yQ(x, y), where the domain for all variables consists of all real numbers? Solution: The quantification ∃y∀xQ(x, y) denotes the proposition “There is a real number y such that for every real number x, Q(x, y).” No matter what value of y is chosen, there is only one value of x for which x + y = 0. Because there is no real number y such that x + y = 0 for all real numbers x, the statement ∃y∀xQ(x, y) is false. 1.5 Nested Quantifiers 63 The quantification ∀x∃yQ(x, y) denotes the proposition “For every real number x there is a real number y such that Q(x, y).” Be careful with the order of existential and universal quantifiers! EXAMPLE 5 Given a real number x, there is a real number y such that x + y = 0; namely, y = −x. Hence, the statement ∀x∃yQ(x, y) is true. ◂ Example 4 illustrates that the order in which quantifiers appear makes a difference. The statements ∃y∀xP(x, y) and ∀x∃yP(x, y) are not logically equivalent. The statement ∃y∀xP(x, y) is true if and only if there is a y that makes P(x, y) true for every x. So, for this statement to be true, there must be a particular value of y for which P(x, y) is true regardless of the choice of x. On the other hand, ∀x∃yP(x, y) is true if and only if for every value of x there is a value of y for which P(x, y) is true. So, for this statement to be true, no matter which x you choose, there must be a value of y (possibly depending on the x you choose) for which P(x, y) is true. In other words, in the second case, y can depend on x, whereas in the first case, y is a constant independent of x. From these observations, it follows that if ∃y∀xP(x, y) is true, then ∀x∃yP(x, y) must also be true. However, if ∀x∃yP(x, y) is true, it is not necessary for ∃y∀xP(x, y) to be true. (See Supplementary Exercises 30 and 31.) Table 1 summarizes the meanings of the different possible quantifications involving two variables. Quantifications of more than two variables are also common, as Example 5 illustrates. Let Q(x, y, z) be the statement “x + y = z.” What are the truth values of the statements ∀x∀y∃zQ(x, y, z) and ∃z∀x∀yQ(x, y, z), where the domain of all variables consists of all real numbers? Solution: Suppose that x and y are assigned values. Then, there exists a real number z such that x + y = z. Consequently, the quantification ∀x∀y∃zQ(x, y, z), which is the statement “For all real numbers x and for all real numbers y there is a real number z such that x + y = z,” TABLE 1 Quantifications of Two Variables. Statement When True? ∀x∀yP(x, y) ∀y∀xP(x, y) P(x, y) is true for every pair x, y. ∀x∃yP(x, y) For every x there is a y for which P(x, y) is true. ∃x∀yP(x, y) There is an x for which P(x, y) is true for every y. ∃x∃yP(x, y) ∃y∃xP(x, y) There is a pair x, y for which P(x, y) is true. When False? There is a pair x, y for which P(x, y) is false. There is an x such that P(x, y) is false for every y. For every x there is a y for which P(x, y) is false. P(x, y) is false for every pair x, y. 64 1 / The Foundations: Logic and Proofs is true. The order of the quantification here is important, because the quantification ∃z∀x∀yQ(x, y, z), which is the statement “There is a real number z such that for all real numbers x and for all real numbers y it is true that x + y = z,” is false, because there is no value of z that satisfies the equation x + y = z for all values of x and y. ◂ 1.5.4 Translating Mathematical Statements into Statements Involving Nested Quantifiers Mathematical statements expressed in English can be translated into logical expressions, as Examples 6–8 show. EXAMPLE 6 Extra Examples Translate the statement “The sum of two positive integers is always positive” into a logical expression. Solution: To translate this statement into a logical expression, we first rewrite it so that the implied quantifiers and a domain are shown: “For every two integers, if these integers are both positive, then the sum of these integers is positive.” Next, we introduce the variables x and y to obtain “For all positive integers x and y, x + y is positive.” Consequently, we can express this statement as ∀x∀y((x > 0) ∧ (y > 0) → (x + y > 0)), where the domain for both variables consists of all integers. Note that we could also translate this using the positive integers as the domain. Then the statement “The sum of two positive integers is always positive” becomes “For every two positive integers, the sum of these integers is positive.” We can express this as ∀x∀y(x + y > 0), where the domain for both variables consists of all positive integers. ◂ EXAMPLE 7 Translate the statement “Every real number except zero has a multiplicative inverse.” (A multiplicative inverse of a real number x is a real number y such that xy = 1.) Solution: We first rewrite this as “For every real number x except zero, x has a multiplicative inverse.” We can rewrite this as “For every real number x, if x ≠ 0, then there exists a real number y such that xy = 1.” This can be rewritten as ∀x((x ≠ 0) → ∃y(xy = 1)). ◂ One example that you may be familiar with is the concept of limit, which is important in calculus. 1.5 Nested Quantifiers 65 EXAMPLE 8 (Requires calculus) Use quantifiers to express the definition of the limit of a real-valued function f (x) of a real variable x at a point a in its domain. Solution: Recall that the definition of the statement lim f (x) = L x→a is: For every real number 𝜖 > 0 there exists a real number 𝛿 > 0 such that |f (x) − L| < 𝜖 whenever 0 < |x − a| < 𝛿. This definition of a limit can be phrased in terms of quantifiers by ∀𝜖∃𝛿∀x(0 < |x − a| < 𝛿 → |f (x) − L| < 𝜖), where the domain for the variables 𝛿 and 𝜖 consists of all positive real numbers and for x consists of all real numbers. This definition can also be expressed as ∀𝜖 > 0 ∃𝛿 >0 ∀x(0 < |x − a| < 𝛿 → |f (x) − L| < 𝜖) when the domain for the variables 𝜖 and 𝛿 consists of all real numbers, rather than just the positive real numbers. [Here, restricted quantifiers have been used. Recall that ∀x > 0 P(x) means that for all x with x > 0, P(x) is true.] ◂ 1.5.5 Translating from Nested Quantifiers into English Expressions with nested quantifiers expressing statements in English can be quite complicated. The first step in translating such an expression is to write out what the quantifiers and predicates in the expression mean. The next step is to express this meaning in a simpler sentence. This process is illustrated in Examples 9 and 10. EXAMPLE 9 Translate the statement ∀x(C(x) ∨ ∃y(C(y) ∧ F(x, y))) into English, where C(x) is “x has a computer,” F(x, y) is “x and y are friends,” and the domain for both x and y consists of all students in your school. Solution: The statement says that for every student x in your school, x has a computer or there is a student y such that y has a computer and x and y are friends. In other words, every student in your school has a computer or has a friend who has a computer. ◂ EXAMPLE 10 Translate the statement ∃x∀y∀z((F(x, y) ∧ F(x, z) ∧ (y ≠ z)) → ¬F(y, z)) into English, where F(a, b) means a and b are friends and the domain for x, y, and z consists of all students in your school. Solution: We first examine the expression (F(x, y) ∧ F(x, z) ∧ (y ≠ z)) → ¬F(y, z). This expression says that if students x and y are friends, and students x and z are friends, and furthermore, if y and z are not the same student, then y and z are not friends. It follows that the original statement, which is triply quantified, says that there is a student x such that for all students y and all students z other than y, if x and y are friends and x and z are friends, then y and z are not friends. In other words, there is a student none of whose friends are also friends with each other. ◂ 66 1 / The Foundations: Logic and Proofs 1.5.6 Translating English Sentences into Logical Expressions In Section 1.4 we showed how quantifiers can be used to translate sentences into logical expressions. However, we avoided sentences whose translation into logical expressions required the use of nested quantifiers. We now address the translation of such sentences. EXAMPLE 11 Express the statement “If a person is female and is a parent, then this person is someone’s mother” as a logical expression involving predicates, quantifiers with a domain consisting of all people, and logical connectives. Solution: The statement “If a person is female and is a parent, then this person is someone’s mother” can be expressed as “For every person x, if person x is female and person x is a parent, then there exists a person y such that person x is the mother of person y.” We introduce the propositional functions F(x) to represent “x is female,” P(x) to represent “x is a parent,” and M(x, y) to represent “x is the mother of y.” The original statement can be represented as ∀x((F(x) ∧ P(x)) → ∃yM(x, y)). Using the null quantification rule in part (b) of Exercise 49 in Section 1.4, we can move ∃y to the left so that it appears just after ∀x, because y does not appear in F(x) ∧ P(x). We obtain the logically equivalent expression ∀x∃y((F(x) ∧ P(x)) → M(x, y)). ◂ EXAMPLE 12 Express the statement “Everyone has exactly one best friend” as a logical expression involving predicates, quantifiers with a domain consisting of all people, and logical connectives. Solution: The statement “Everyone has exactly one best friend” can be expressed as “For every person x, person x has exactly one best friend.” Introducing the universal quantifier, we see that this statement is the same as “∀x(person x has exactly one best friend),” where the domain consists of all people. To say that x has exactly one best friend means that there is a person y who is the best friend of x, and furthermore, that for every person z, if person z is not person y, then z is not the best friend of x. When we introduce the predicate B(x, y) to be the statement “y is the best friend of x,” the statement that x has exactly one best friend can be represented as ∃y(B(x, y) ∧ ∀z((z ≠ y) → ¬B(x, z))). Consequently, our original statement can be expressed as ∀x∃y(B(x, y) ∧ ∀z((z ≠ y) → ¬B(x, z))). [Note that we can write this statement as ∀x∃!yB(x, y), where ∃! is the “uniqueness quantifier” defined in Section 1.4.] ◂ EXAMPLE 13 Use quantifiers to express the statement “There is a woman who has taken a flight on every airline in the world.” Solution: Let P(w, f ) be “w has taken f ” and Q(f, a) be “f is a flight on a.” We can express the statement as ∃w∀a∃f (P(w, f ) ∧ Q(f, a)), 1.5 Nested Quantifiers 67 where the domains of discourse for w, f , and a consist of all the women in the world, all airplane flights, and all airlines, respectively. The statement could also be expressed as ∃w∀a∃fR(w, f, a), where R(w, f, a) is “w has taken f on a.” Although this is more compact, it somewhat obscures the relationships among the variables. Consequently, the first solution is usually preferable. ◂ Assessment 1.5.7 Negating Nested Quantifiers Statements involving nested quantifiers can be negated by successively applying the rules for negating statements involving a single quantifier. This is illustrated in Examples 14–16. EXAMPLE 14 Extra Examples Express the negation of the statement ∀x∃y(xy = 1) so that no negation precedes a quantifier. Solution: By successively applying De Morgan’s laws for quantifiers in Table 2 of Section 1.4, we can move the negation in ¬∀x∃y(xy = 1) inside all the quantifiers. We find that ¬∀x∃y(xy = 1) is equivalent to ∃x¬∃y(xy = 1), which is equivalent to ∃x∀y¬(xy = 1). Because ¬(xy = 1) can be expressed more simply as xy ≠ 1, we conclude that our negated statement can be expressed as ∃x∀y(xy ≠ 1). ◂ EXAMPLE 15 Use quantifiers to express the statement that “There does not exist a woman who has taken a flight on every airline in the world.” Solution: This statement is the negation of the statement “There is a woman who has taken a flight on every airline in the world” from Example 13. By Example 13, our statement can be expressed as ¬∃w∀a∃f (P(w, f ) ∧ Q( f, a)), where P(w, f ) is “w has taken f ” and Q( f, a) is “f is a flight on a.” By successively applying De Morgan’s laws for quantifiers in Table 2 of Section 1.4 to move the negation inside successive quantifiers and by applying De Morgan’s law for negating a conjunction in the last step, we find that our statement is equivalent to each of this sequence of statements: ∀w¬∀a∃f (P(w, f ) ∧ Q( f, a)) ≡ ∀w∃a¬∃f (P(w, f ) ∧ Q( f, a)) ≡ ∀w∃a∀f ¬(P(w, f ) ∧ Q( f, a)) ≡ ∀w∃a∀f (¬P(w, f ) ∨ ¬Q( f, a)). This last statement states “For every woman there is an airline such that for all flights, this woman has not taken that flight or that flight is not on this airline.” ◂ EXAMPLE 16 (Requires calculus) Use quantifiers and predicates to express the fact that limx→a f (x) does not exist where f (x) is a real-valued function of a real variable x and a belongs to the domain of f. Solution: To say that limx→a f (x) does not exist means that for all real numbers L, limx→a f (x) ≠ L. By using Example 8, the statement limx→a f (x) ≠ L can be expressed as ¬∀𝜖 > 0 ∃𝛿 >0 ∀x(0 < |x − a| < 𝛿 → |f (x) − L| < 𝜖). 68 1 / The Foundations: Logic and Proofs Successively applying the rules for negating quantified expressions, we construct this sequence of equivalent statements: ¬∀𝜖 >0 ∃𝛿 >0 ∀x(0<|x − a|<𝛿 → |f (x) − L|<𝜖) ≡ ∃𝜖 >0 ¬∃𝛿 >0 ∀x(0<|x − a|<𝛿 → |f (x) − L|<𝜖) ≡ ∃𝜖 >0 ∀𝛿 >0 ¬∀x(0<|x − a|<𝛿 → |f (x) − L|<𝜖) ≡ ∃𝜖 >0 ∀𝛿 >0 ∃x ¬(0<|x − a|<𝛿 → |f (x) − L|<𝜖) ≡ ∃𝜖 >0 ∀𝛿 >0 ∃x(0<|x − a|<𝛿 ∧ |f (x) − L| ≥ 𝜖). In the last step we used the equivalence ¬(p → q) ≡ p ∧ ¬q, which follows from the fifth equivalence in Table 7 of Section 1.3. Because the statement “limx→a f (x) does not exist” means for all real numbers L, limx→a f (x) ≠ L, this can be expressed as ∀L∃𝜖 >0 ∀𝛿 >0 ∃x(0 < |x − a| < 𝛿 ∧ |f (x) − L| ≥ 𝜖). This last statement says that for every real number L there is a real number 𝜖 > 0 such that for every real number 𝛿 > 0, there exists a real number x such that 0 < |x − a| < 𝛿 and |f (x) − L| ≥ 𝜖. ◂ Exercises 1. Translate these statements into English, where the domain for each variable consists of all real numbers. a) ∀x∃y(x < y) b) ∀x∀y(((x ≥ 0) ∧ (y ≥ 0)) → (xy ≥ 0)) c) ∀x∀y∃z(xy = z) 2. Translate these statements into English, where the domain for each variable consists of all real numbers. a) ∃x∀y(xy = y) b) ∀x∀y(((x ≥ 0) ∧ (y < 0)) → (x − y > 0)) c) ∀x∀y∃z(x = y + z) 3. Let Q(x, y) be the statement “x has sent an e-mail message to y,” where the domain for both x and y consists of all students in your class. Express each of these quantifications in English. a) ∃x∃yQ(x, y) b) ∃x∀yQ(x, y) c) ∀x∃yQ(x, y) d) ∃y∀xQ(x, y) e) ∀y∃xQ(x, y) f ) ∀x∀yQ(x, y) 4. Let P(x, y) be the statement “Student x has taken class y,” where the domain for x consists of all students in your class and for y consists of all computer science courses at your school. Express each of these quantifications in English. a) ∃x∃yP(x, y) b) ∃x∀yP(x, y) c) ∀x∃yP(x, y) d) ∃y∀xP(x, y) e) ∀y∃xP(x, y) f ) ∀x∀yP(x, y) 5. Let W(x, y) mean that student x has visited website y, where the domain for x consists of all students in your school and the domain for y consists of all websites. Express each of these statements by a simple English sentence. a) W(Sarah Smith, www.att.com) b) ∃xW(x, www.imdb.org) c) ∃yW(Jose´ Orez, y) d) ∃y(W(Ashok Puri, y) ∧ W(Cindy Yoon, y)) e) ∃y∀z(y ≠ (David Belcher) ∧ (W(David Belcher, z) → W (y,z))) f ) ∃x∃y∀z((x ≠ y) ∧ (W(x, z) ↔ W(y, z))) 6. Let C(x, y) mean that student x is enrolled in class y, where the domain for x consists of all students in your school and the domain for y consists of all classes being given at your school. Express each of these statements by a simple English sentence. a) C(Randy Goldberg, CS 252) b) ∃xC(x, Math 695) c) ∃yC(Carol Sitea, y) d) ∃x(C(x, Math 222) ∧ C(x, CS 252)) e) ∃x∃y∀z((x ≠ y) ∧ (C(x, z) → C(y, z))) f ) ∃x∃y∀z((x ≠ y) ∧ (C(x, z) ↔ C(y, z))) 7. Let T(x, y) mean that student x likes cuisine y, where the domain for x consists of all students at your school and the domain for y consists of all cuisines. Express each of these statements by a simple English sentence. a) ¬T(Abdallah Hussein, Japanese) b) ∃xT(x, Korean) ∧ ∀xT(x, Mexican) c) ∃y(T(Monique Arsenault, y) ∨ T(Jay Johnson, y)) d) ∀x∀z∃y((x ≠ z) → ¬(T(x, y) ∧ T(z, y))) e) ∃x∃z∀y(T(x, y) ↔ T(z, y)) f ) ∀x∀z∃y(T(x, y) ↔ T(z, y)) 8. Let Q(x, y) be the statement “Student x has been a contestant on quiz show y.” Express each of these sentences in terms of Q(x, y), quantifiers, and logical connectives, where the domain for x consists of all students at your school and for y consists of all quiz shows on television. a) There is a student at your school who has been a contestant on a television quiz show. b) No student at your school has ever been a contestant on a television quiz show. c) There is a student at your school who has been a contestant on Jeopardy! and on Wheel of Fortune. d) Every television quiz show has had a student from your school as a contestant. e) At least two students from your school have been contestants on Jeopardy!. 9. Let L(x, y) be the statement “x loves y,” where the domain for both x and y consists of all people in the world. Use quantifiers to express each of these statements. a) Everybody loves Jerry. b) Everybody loves somebody. c) There is somebody whom everybody loves. d) Nobody loves everybody. e) There is somebody whom Lydia does not love. f ) There is somebody whom no one loves. g) There is exactly one person whom everybody loves. h) There are exactly two people whom Lynn loves. i) Everyone loves himself or herself. j) There is someone who loves no one besides himself or herself. 10. Let F(x, y) be the statement “x can fool y,” where the domain consists of all people in the world. Use quantifiers to express each of these statements. a) Everybody can fool Fred. b) Evelyn can fool everybody. c) Everybody can fool somebody. d) There is no one who can fool everybody. e) Everyone can be fooled by somebody. f ) No one can fool both Fred and Jerry. g) Nancy can fool exactly two people. h) There is exactly one person whom everybody can fool. i) No one can fool himself or herself. j) There is someone who can fool exactly one person besides himself or herself. 11. Let S(x) be the predicate “x is a student,” F(x) the predicate “x is a faculty member,” and A(x, y) the predicate “x has asked y a question,” where the domain consists of all people associated with your school. Use quantifiers to express each of these statements. a) Lois has asked Professor Michaels a question. b) Every student has asked Professor Gross a question. 1.5 Nested Quantifiers 69 c) Every faculty member has either asked Professor Miller a question or been asked a question by Professor Miller. d) Some student has not asked any faculty member a question. e) There is a faculty member who has never been asked a question by a student. f ) Some student has asked every faculty member a question. g) There is a faculty member who has asked every other faculty member a question. h) Some student has never been asked a question by a faculty member. 12. Let I(x) be the statement “x has an Internet connection” and C(x, y) be the statement “x and y have chatted over the Internet,” where the domain for the variables x and y consists of all students in your class. Use quantifiers to express each of these statements. a) Jerry does not have an Internet connection. b) Rachel has not chatted over the Internet with Chelsea. c) Jan and Sharon have never chatted over the Internet. d) No one in the class has chatted with Bob. e) Sanjay has chatted with everyone except Joseph. f ) Someone in your class does not have an Internet con- nection. g) Not everyone in your class has an Internet connec- tion. h) Exactly one student in your class has an Internet con- nection. i) Everyone except one student in your class has an In- ternet connection. j) Everyone in your class with an Internet connection has chatted over the Internet with at least one other student in your class. k) Someone in your class has an Internet connection but has not chatted with anyone else in your class. l) There are two students in your class who have not chatted with each other over the Internet. m) There is a student in your class who has chatted with everyone in your class over the Internet. n) There are at least two students in your class who have not chatted with the same person in your class. o) There are two students in the class who between them have chatted with everyone else in the class. 13. Let M(x, y) be “x has sent y an e-mail message” and T(x, y) be “x has telephoned y,” where the domain consists of all students in your class. Use quantifiers to express each of these statements. (Assume that all e-mail messages that were sent are received, which is not the way things often work.) a) Chou has never sent an e-mail message to Koko. b) Arlene has never sent an e-mail message to or tele- phoned Sarah. c) Jose´ has never received an e-mail message from Deb- orah. d) Every student in your class has sent an e-mail mes- sage to Ken. e) No one in your class has telephoned Nina. 70 1 / The Foundations: Logic and Proofs f ) Everyone in your class has either telephoned Avi or sent him an e-mail message. g) There is a student in your class who has sent everyone else in your class an e-mail message. h) There is someone in your class who has either sent an e-mail message or telephoned everyone else in your class. i) There are two different students in your class who have sent each other e-mail messages. j) There is a student who has sent himself or herself an e-mail message. k) There is a student in your class who has not received an e-mail message from anyone else in the class and who has not been called by any other student in the class. l) Every student in the class has either received an email message or received a telephone call from another student in the class. m) There are at least two students in your class such that one student has sent the other e-mail and the second student has telephoned the first student. n) There are two different students in your class who between them have sent an e-mail message to or telephoned everyone else in the class. 14. Use quantifiers and predicates with more than one variable to express these statements. a) There is a student in this class who can speak Hindi. b) Every student in this class plays some sport. c) Some student in this class has visited Alaska but has not visited Hawaii. d) All students in this class have learned at least one programming language. e) There is a student in this class who has taken every course offered by one of the departments in this school. f ) Some student in this class grew up in the same town as exactly one other student in this class. g) Every student in this class has chatted with at least one other student in at least one chat group. 15. Use quantifiers and predicates with more than one variable to express these statements. a) Every computer science student needs a course in discrete mathematics. b) There is a student in this class who owns a personal computer. c) Every student in this class has taken at least one computer science course. d) There is a student in this class who has taken at least one course in computer science. e) Every student in this class has been in every building on campus. f ) There is a student in this class who has been in every room of at least one building on campus. g) Every student in this class has been in at least one room of every building on campus. 16. A discrete mathematics class contains 1 mathematics major who is a freshman, 12 mathematics majors who are sophomores, 15 computer science majors who are sophomores, 2 mathematics majors who are juniors, 2 computer science majors who are juniors, and 1 computer science major who is a senior. Express each of these statements in terms of quantifiers and then determine its truth value. a) There is a student in the class who is a junior. b) Every student in the class is a computer science ma- jor. c) There is a student in the class who is neither a math- ematics major nor a junior. d) Every student in the class is either a sophomore or a computer science major. e) There is a major such that there is a student in the class in every year of study with that major. 17. Express each of these system specifications using predicates, quantifiers, and logical connectives, if necessary. a) Every user has access to exactly one mailbox. b) There is a process that continues to run during all er- ror conditions only if the kernel is working correctly. c) All users on the campus network can access all web- sites whose url has a .edu extension. ∗ d) There are exactly two systems that monitor every re- mote server. 18. Express each of these system specifications using predicates, quantifiers, and logical connectives, if necessary. a) At least one console must be accessible during every fault condition. b) The e-mail address of every user can be retrieved whenever the archive contains at least one message sent by every user on the system. c) For every security breach there is at least one mechanism that can detect that breach if and only if there is a process that has not been compromised. d) There are at least two paths connecting every two distinct endpoints on the network. e) No one knows the password of every user on the system except for the system administrator, who knows all passwords. 19. Express each of these statements using mathematical and logical operators, predicates, and quantifiers, where the domain consists of all integers. a) The sum of two negative integers is negative. b) The difference of two positive integers is not neces- sarily positive. c) The sum of the squares of two integers is greater than or equal to the square of their sum. d) The absolute value of the product of two integers is the product of their absolute values. 20. Express each of these statements using predicates, quantifiers, logical connectives, and mathematical operators where the domain consists of all integers. a) The product of two negative integers is positive. b) The average of two positive integers is positive. c) The difference of two negative integers is not necessarily negative. d) The absolute value of the sum of two integers does not exceed the sum of the absolute values of these integers. 21. Use predicates, quantifiers, logical connectives, and mathematical operators to express the statement that every positive integer is the sum of the squares of four integers. 22. Use predicates, quantifiers, logical connectives, and mathematical operators to express the statement that there is a positive integer that is not the sum of three squares. 23. Express each of these mathematical statements using predicates, quantifiers, logical connectives, and mathematical operators. a) The product of two negative real numbers is positive. b) The difference of a real number and itself is zero. c) Every positive real number has exactly two square roots. d) A negative real number does not have a square root that is a real number. 24. Translate each of these nested quantifications into an English statement that expresses a mathematical fact. The domain in each case consists of all real numbers. a) ∃x∀y(x + y = y) b) ∀x∀y(((x ≥ 0) ∧ (y < 0)) → (x − y > 0)) c) ∃x∃y(((x ≤ 0) ∧ (y ≤ 0)) ∧ (x − y > 0)) d) ∀x∀y((x ≠ 0) ∧ (y ≠ 0) ↔ (xy ≠ 0)) 25. Translate each of these nested quantifications into an English statement that expresses a mathematical fact. The domain in each case consists of all real numbers. a) ∃x∀y(xy = y) b) ∀x∀y(((x < 0) ∧ (y < 0)) → (xy > 0)) c) ∃x∃y((x2 > y) ∧ (x < y)) d) ∀x∀y∃z(x + y = z) 26. Let Q(x, y) be the statement “x + y = x − y.” If the domain for both variables consists of all integers, what are the truth values? a) Q(1, 1) c) ∀yQ(1, y) e) ∃x∃yQ(x, y) g) ∃y∀xQ(x, y) i) ∀x∀yQ(x, y) b) Q(2, 0) d) ∃xQ(x, 2) f ) ∀x∃yQ(x, y) h) ∀y∃xQ(x, y) 27. Determine the truth value of each of these statements if the domain for all variables consists of all integers. a) ∀n∃m(n2 < m) b) ∃n∀m(n < m2) c) ∀n∃m(n + m = 0) d) ∃n∀m(nm = m) e) ∃n∃m(n2 + m2 = 5) f ) ∃n∃m(n2 + m2 = 6) g) ∃n∃m(n + m = 4 ∧ n − m = 1) h) ∃n∃m(n + m = 4 ∧ n − m = 2) i) ∀n∀m∃p(p = (m + n)∕2) 28. Determine the truth value of each of these statements if the domain of each variable consists of all real numbers. a) ∀x∃y(x2 = y) c) ∃x∀y(xy = 0) b) ∀x∃y(x = y2) d) ∃x∃y(x + y ≠ y + x) 1.5 Nested Quantifiers 71 e) ∀x(x ≠ 0 → ∃y(xy = 1)) f ) ∃x∀y(y ≠ 0 → xy = 1) g) ∀x∃y(x + y = 1) h) ∃x∃y(x + 2y = 2 ∧ 2x + 4y = 5) i) ∀x∃y(x + y = 2 ∧ 2x − y = 1) j) ∀x∀y∃z(z = (x + y)∕2) 29. Suppose the domain of the propositional function P(x, y) consists of pairs x and y, where x is 1, 2, or 3 and y is 1, 2, or 3. Write out these propositions using disjunctions and conjunctions. a) ∀x∀yP(x, y) c) ∃x∀yP(x, y) b) ∃x∃yP(x, y) d) ∀y∃xP(x, y) 30. Rewrite each of these statements so that negations appear only within predicates (that is, so that no negation is outside a quantifier or an expression involving logical connectives). a) ¬∃y∃xP(x, y) b) ¬∀x∃yP(x, y) c) ¬∃y(Q(y) ∧ ∀x¬R(x, y)) d) ¬∃y(∃xR(x, y) ∨ ∀xS(x, y)) e) ¬∃y(∀x∃zT(x, y, z) ∨ ∃x∀zU(x, y, z)) 31. Express the negations of each of these statements so that all negation symbols immediately precede predicates. a) ∀x∃y∀zT(x, y, z) b) ∀x∃yP(x, y) ∨ ∀x∃yQ(x, y) c) ∀x∃y(P(x, y) ∧ ∃zR(x, y, z)) d) ∀x∃y(P(x, y) → Q(x, y)) 32. Express the negations of each of these statements so that all negation symbols immediately precede predicates. a) ∃z∀y∀xT(x, y, z) b) ∃x∃yP(x, y) ∧ ∀x∀yQ(x, y) c) ∃x∃y(Q(x, y) ↔ Q(y, x)) d) ∀y∃x∃z(T(x, y, z) ∨ Q(x, y)) 33. Rewrite each of these statements so that negations appear only within predicates (that is, so that no negation is outside a quantifier or an expression involving logical connectives). a) ¬∀x∀yP(x, y) b) ¬∀y∃xP(x, y) c) ¬∀y∀x(P(x, y) ∨ Q(x, y)) d) ¬(∃x∃y¬P(x, y) ∧ ∀x∀yQ(x, y)) e) ¬∀x(∃y∀zP(x, y, z) ∧ ∃z∀yP(x, y, z)) 34. Find a common domain for the variables x, y, and z for which the statement ∀x∀y((x ≠ y) → ∀z((z = x) ∨ (z = y))) is true and another domain for which it is false. 35. Find a common domain for the variables x, y, z, and w for which the statement ∀x∀y∀z∃w((w ≠ x) ∧ (w ≠ y) ∧ (w ≠ z)) is true and another common domain for these variables for which it is false. 36. Express each of these statements using quantifiers. Then form the negation of the statement so that no negation is to the left of a quantifier. Next, express the negation in simple English. (Do not simply use the phrase “It is not the case that.”) a) No one has lost more than one thousand dollars playing the lottery. b) There is a student in this class who has chatted with exactly one other student. 72 1 / The Foundations: Logic and Proofs c) No student in this class has sent e-mail to exactly two other students in this class. d) Some student has solved every exercise in this book. e) No student has solved at least one exercise in every section of this book. 37. Express each of these statements using quantifiers. Then form the negation of the statement so that no negation is to the left of a quantifier. Next, express the negation in simple English. (Do not simply use the phrase “It is not the case that.”) a) Every student in this class has taken exactly two mathematics classes at this school. b) Someone has visited every country in the world except Libya. c) No one has climbed every mountain in the Himalayas. d) Every movie actor has either been in a movie with Kevin Bacon or has been in a movie with someone who has been in a movie with Kevin Bacon. 38. Express the negations of these propositions using quantifiers, and in English. a) Every student in this class likes mathematics. b) There is a student in this class who has never seen a computer. c) There is a student in this class who has taken every mathematics course offered at this school. d) There is a student in this class who has been in at least one room of every building on campus. 39. Find a counterexample, if possible, to these universally quantified statements, where the domain for all variables consists of all integers. a) ∀x∀y(x2 = y2 → x = y) b) ∀x∃y(y2 = x) c) ∀x∀y(xy ≥ x) 40. Find a counterexample, if possible, to these universally quantified statements, where the domain for all variables consists of all integers. a) ∀x∃y(x = 1∕y) b) ∀x∃y(y2 − x < 100) c) ∀x∀y(x2 ≠ y3) 41. Use quantifiers to express the associative law for multiplication of real numbers. 42. Use quantifiers to express the distributive laws of multiplication over addition for real numbers. 43. Use quantifiers and logical connectives to express the fact that every linear polynomial (that is, polynomial of degree 1) with real coefficients and where the coefficient of x is nonzero, has exactly one real root. 44. Use quantifiers and logical connectives to express the fact that a quadratic polynomial with real number coefficients has at most two real roots. 45. Determine the truth value of the statement ∀x∃y(xy = 1) if the domain for the variables consists of a) the nonzero real numbers. b) the nonzero integers. c) the positive real numbers. 46. Determine the truth value of the statement ∃x∀y(x ≤ y2) if the domain for the variables consists of a) the positive real numbers. b) the integers. c) the nonzero real numbers. 47. Show that the two statements ¬∃x∀yP(x, y) and ∀x∃y¬P(x, y), where both quantifiers over the first variable in P(x, y) have the same domain, and both quantifiers over the second variable in P(x, y) have the same domain, are logically equivalent. ∗ 48. Show that ∀xP(x) ∨ ∀xQ(x) and ∀x∀y(P(x) ∨ Q(y)), where all quantifiers have the same nonempty domain, are logically equivalent. (The new variable y is used to combine the quantifications correctly.) ∗ 49. a) Show that ∀xP(x) ∧ ∃xQ(x) is logically equivalent to ∀x∃y (P(x) ∧ Q(y)), where all quantifiers have the same nonempty domain. b) Show that ∀xP(x) ∨ ∃xQ(x) is equivalent to ∀x∃y (P(x) ∨ Q(y)), where all quantifiers have the same nonempty domain. A statement is in prenex normal form (PNF) if and only if it is of the form Q1x1Q2x2 ⋯ QkxkP(x1, x2, … , xk), where each Qi, i = 1, 2, … , k, is either the existential quantifier or the universal quantifier, and P(x1, … , xk) is a predicate involving no quantifiers. For example, ∃x∀y(P(x, y) ∧ Q(y)) is in prenex normal form, whereas ∃xP(x) ∨ ∀xQ(x) is not (because the quantifiers do not all occur first). Every statement formed from propositional variables, predicates, T, and F using logical connectives and quantifiers is equivalent to a statement in prenex normal form. Exercise 51 asks for a proof of this fact. ∗ 50. Put these statements in prenex normal form. [Hint: Use logical equivalence from Tables 6 and 7 in Section 1.3, Table 2 in Section 1.4, Example 19 in Section 1.4, Exercises 47 and 48 in Section 1.4, and Exercises 48 and 49.] a) ∃xP(x) ∨ ∃xQ(x) ∨ A, where A is a proposition not involving any quantifiers b) ¬(∀xP(x) ∨ ∀xQ(x)) c) ∃xP(x) → ∃xQ(x) ∗∗ 51. Show how to transform an arbitrary statement to a statement in prenex normal form that is equivalent to the given statement. (Note: A formal solution of this exercise requires use of structural induction, covered in Section 5.3.) ∗ 52. Express the quantification ∃!xP(x), introduced in Section 1.4, using universal quantifications, existential quantifications, and logical operators. 1.6 Rules of Inference 73 1.6 Rules of Inference 1.6.1 Introduction Later in this chapter we will study proofs. Proofs in mathematics are valid arguments that establish the truth of mathematical statements. By an argument, we mean a sequence of statements that end with a conclusion. By valid, we mean that the conclusion, or final statement of the argument, must follow from the truth of the preceding statements, or premises, of the argument. That is, an argument is valid if and only if it is impossible for all the premises to be true and the conclusion to be false. To deduce new statements from statements we already have, we use rules of inference which are templates for constructing valid arguments. Rules of inference are our basic tools for establishing the truth of statements. Before we study mathematical proofs, we will look at arguments that involve only compound propositions. We will define what it means for an argument involving compound propositions to be valid. Then we will introduce a collection of rules of inference in propositional logic. These rules of inference are among the most important ingredients in producing valid arguments. After we illustrate how rules of inference are used to produce valid arguments, we will describe some common forms of incorrect reasoning, called fallacies, which lead to invalid arguments. After studying rules of inference in propositional logic, we will introduce rules of inference for quantified statements. We will describe how these rules of inference can be used to produce valid arguments. These rules of inference for statements involving existential and universal quantifiers play an important role in proofs in computer science and mathematics, although they are often used without being explicitly mentioned. Finally, we will show how rules of inference for propositions and for quantified statements can be combined. These combinations of rule of inference are often used together in complicated arguments. 1.6.2 Valid Arguments in Propositional Logic Consider the following argument involving propositions (which, by definition, is a sequence of propositions): “If you have a current password, then you can log onto the network.” “You have a current password.” Therefore, “You can log onto the network.” We would like to determine whether this is a valid argument. That is, we would like to determine whether the conclusion “You can log onto the network” must be true when the premises “If you have a current password, then you can log onto the network” and “You have a current password” are both true. Before we discuss the validity of this particular argument, we will look at its form. Use p to represent “You have a current password” and q to represent “You can log onto the network.” Then, the argument has the form p→q p ∴q where ∴ is the symbol that denotes “therefore.” 74 1 / The Foundations: Logic and Proofs We know that when p and q are propositional variables, the statement ((p → q) ∧ p) → q is a tautology (see Exercise 12(c) in Section 1.3). In particular, when both p → q and p are true, we know that q must also be true. We say this form of argument is valid because whenever all its premises (all statements in the argument other than the final one, the conclusion) are true, the conclusion must also be true. Now suppose that both “If you have a current password, then you can log onto the network” and “You have a current password” are true statements. When we replace p by “You have a current password” and q by “You can log onto the network,” it necessarily follows that the conclusion “You can log onto the network” is true. This argument is valid because its form is valid. Note that whenever we replace p and q by propositions where p → q and p are both true, then q must also be true. What happens when we replace p and q in this argument form by propositions where not both p and p → q are true? For example, suppose that p represents “You have access to the network” and q represents “You can change your grade” and that p is true, but p → q is false. The argument we obtain by substituting these values of p and q into the argument form is “If you have access to the network, then you can change your grade.” “You have access to the network.” ∴ “You can change your grade.” The argument we obtained is a valid argument, but because one of the premises, namely the first premise, is false, we cannot conclude that the conclusion is true. (Most likely, this conclusion is false.) In our discussion, to analyze an argument, we replaced propositions by propositional variables. This changed an argument to an argument form. We saw that the validity of an argument follows from the validity of the form of the argument. We summarize the terminology used to discuss the validity of arguments with our definition of the key notions. Definition 1 An argument in propositional logic is a sequence of propositions. All but the final proposition in the argument are called premises and the final proposition is called the conclusion. An argument is valid if the truth of all its premises implies that the conclusion is true. An argument form in propositional logic is a sequence of compound propositions involving propositional variables. An argument form is valid if no matter which particular propositions are substituted for the propositional variables in its premises, the conclusion is true if the premises are all true. Remark: From the definition of a valid argument form we see that the argument form with premises p1, p2, … , pn and conclusion q is valid exactly when (p1 ∧ p2 ∧ ⋯ ∧ pn) → q is a tautology. The key to showing that an argument in propositional logic is valid is to show that its argument form is valid. Consequently, we would like techniques to show that argument forms are valid. We will now develop methods for accomplishing this task. 1.6.3 Rules of Inference for Propositional Logic We can always use a truth table to show that an argument form is valid. We do this by showing that whenever the premises are true, the conclusion must also be true. However, this can be a tedious approach. For example, when an argument form involves 10 different propositional variables, to use a truth table to show this argument form is valid requires 210 = 1024 different rows. Fortunately, we do not have to resort to truth tables. Instead, we can first establish the 1.6 Rules of Inference 75 validity of some relatively simple argument forms, called rules of inference. These rules of inference can be used as building blocks to construct more complicated valid argument forms. We will now introduce the most important rules of inference in propositional logic. The tautology (p ∧ (p → q)) → q is the basis of the rule of inference called modus ponens, or the law of detachment. (Modus ponens is Latin for mode that affirms.) This tautology leads to the following valid argument form, which we have already seen in our initial discussion about arguments (where, as before, the symbol ∴ denotes “therefore”): p p→q ∴q Using this notation, the hypotheses are written in a column, followed by a horizontal bar, followed by a line that begins with the therefore symbol and ends with the conclusion. In particular, modus ponens tells us that if a conditional statement and the hypothesis of this conditional statement are both true, then the conclusion must also be true. Example 1 illustrates the use of modus ponens. EXAMPLE 1 Suppose that the conditional statement “If it snows today, then we will go skiing” and its hy- pothesis, “It is snowing today,” are true. Then, by modus ponens, it follows that the conclusion of the conditional statement, “We will go skiing,” is true. ◂ As we mentioned earlier, a valid argument can lead to an incorrect conclusion if one or more of its premises is false. We illustrate this again in Example 2. EXAMPLE 2 Determine whether the argument given here is valid and determine whether its conclusion must be true because of the validity of the argument. “If √ 2 > 3, then (√2)2 > ( 3 )2. We know that √ 2 > 3. Consequently, (√2)2 = 2 2 > ( 3 )2 = 9 .” 2 2 2 4 √ Solution: Let p be the proposition “ 2 > 3 ” and q the proposition “2 > ( 3 )2.” The premises 2 2 of the argument are p → q and p, and q is its conclusion. This argument is valid because it i√s constructed by using modus ponens, a valid argument form. However, one of its premises, 2 > 3 , is false. Consequently, we cannot conclude that the conclusion is true. Furthermore, 2 note that the conclusion of this argument is false, because 2 < 9 . 4 ◂ There are many useful rules of inference for propositional logic. Perhaps the most widely used of these are listed in Table 1. Exercises 13–16, 25, 33, and 34 in Section 1.3 ask for the verifications that these rules of inference are valid argument forms. We now give examples of arguments that use these rules of inference. In each argument, we first use propositional variables to express the propositions in the argument. We then show that the resulting argument form is a rule of inference from Table 1. EXAMPLE 3 State which rule of inference is the basis of the following argument: “It is below freezing now. Therefore, it is below freezing or raining now.” Solution: Let p be the proposition “It is below freezing now,” and let q be the proposition “It is raining now.” Then this argument is of the form p ∴p∨q 76 1 / The Foundations: Logic and Proofs TABLE 1 Rules of Inference. Rule of Inference Tautology p p→q ∴q (p ∧ (p → q)) → q ¬q p→q ∴ ¬p (¬q ∧ (p → q)) → ¬p p→q q→r ∴ p→r ((p → q) ∧ (q → r)) → (p → r) p∨q ¬p ∴q ((p ∨ q) ∧ ¬p) → q p ∴ p∨q p → (p ∨ q) p∧q ∴p (p ∧ q) → p p q ∴ p∧q ((p) ∧ (q)) → (p ∧ q) p∨q ¬p ∨ r ∴ q∨r ((p ∨ q) ∧ (¬p ∨ r)) → (q ∨ r) Name Modus ponens Modus tollens Hypothetical syllogism Disjunctive syllogism Addition Simplification Conjunction Resolution This is an argument that uses the addition rule. ◂ EXAMPLE 4 State which rule of inference is the basis of the following argument: “It is below freezing and raining now. Therefore, it is below freezing now.” Solution: Let p be the proposition “It is below freezing now,” and let q be the proposition “It is raining now.” This argument is of the form p∧q ∴p This argument uses the simplification rule. ◂ EXAMPLE 5 State which rule of inference is used in the argument: If it rains today, then we will not have a barbecue today. If we do not have a barbecue today, then we will have a barbecue tomorrow. Therefore, if it rains today, then we will have a barbecue tomorrow. 1.6 Rules of Inference 77 Solution: Let p be the proposition “It is raining today,” let q be the proposition “We will not have a barbecue today,” and let r be the proposition “We will have a barbecue tomorrow.” Then this argument is of the form p→q q→r ∴ p→r Hence, this argument is a hypothetical syllogism. ◂ 1.6.4 Using Rules of Inference to Build Arguments When there are many premises, several rules of inference are often needed to show that an argument is valid. This is illustrated by Examples 6 and 7, where the steps of arguments are displayed on separate lines, with the reason for each step explicitly stated. These examples also show how arguments in English can be analyzed using rules of inference. EXAMPLE 6 Extra Examples Show that the premises “It is not sunny this afternoon and it is colder than yesterday,” “We will go swimming only if it is sunny,” “If we do not go swimming, then we will take a canoe trip,” and “If we take a canoe trip, then we will be home by sunset” lead to the conclusion “We will be home by sunset.” Solution: Let p be the proposition “It is sunny this afternoon,” q the proposition “It is colder than yesterday,” r the proposition “We will go swimming,” s the proposition “We will take a canoe trip,” and t the proposition “We will be home by sunset.” Then the premises become ¬p ∧ q, r → p, ¬r → s, and s → t. The conclusion is simply t. We need to give a valid argument with premises ¬p ∧ q, r → p, ¬r → s, and s → t and conclusion t. We construct an argument to show that our premises lead to the desired conclusion as follows. Step 1. ¬p ∧ q 2. ¬p 3. r → p 4. ¬r 5. ¬r → s 6. s 7. s → t 8. t Reason Premise Simplification using (1) Premise Modus tollens using (2) and (3) Premise Modus ponens using (4) and (5) Premise Modus ponens using (6) and (7) Note that we could have used a truth table to show that whenever each of the four hypotheses is true, the conclusion is also true. However, because we are working with five propositional variables, p, q, r, s, and t, such a truth table would have 32 rows. ◂ EXAMPLE 7 Show that the premises “If you send me an e-mail message, then I will finish writing the program,” “If you do not send me an e-mail message, then I will go to sleep early,” and “If I go to sleep early, then I will wake up feeling refreshed” lead to the conclusion “If I do not finish writing the program, then I will wake up feeling refreshed.” Solution: Let p be the proposition “You send me an e-mail message,” q the proposition “I will finish writing the program,” r the proposition “I will go to sleep early,” and s the proposition “I