every element in the truth set for P(x) is in the truth set for Q(x)
84
P(x) <> Q (x
P(x) and Q(x) have identical truth sets
84
V
for all
78
A
there exists
79
NOT-gate
46
AND-gate
46
ROR-gate
46
NAND-gate
54
NOR-gate
54
Sheffer stroke
54
4
Peirce arrow
54
r2
number written in binary notation
58
Applications of Logic
N
NAND
8
nOo
number written in decimal notation
58
n16
number written in hexadecimal notation
71
Number Theory and
d In d%n
d divides n d does not divide n
148 149
Applications
n div d
the integer quotient of n divided by d
158
n mod d
the remainder of n divided by d
158
[xj
the floor of x
165
Fxl
the ceiling of x
165
W gcd(a, b)
the absolute value of x the greatest common divisor of a and b
164 192
x := e
x is assigned the value e
186
Page
Subject
Symbol
Meaning
Sequences
...
and so forth
199
the summation from k equals m to n of ak
202
the product from k equals m to n of a,
205
n&
n factorial
206
aE A
a is an element of A
76
a0A
a is not an element of A
76
(a,, a2 , ... , a.)
the set with elements a,, a2 , . . ., an
76
Ix E D I Plx)}
the set of all x in D for which P(x) is true the sets of all real numbers, negative real numbers, positive real numbers, and nonnegative real numbers
n
E
ak
k=m
n
fl -k k=m
Set Theory
R, R-, R+, Ronneg
77 76, 77
Z' Z-' Z+ znonneg
the sets of all integers, negative integers, positive integers, and nonnegative integers
76, 77
Q, Q- Q+, Qnonneg
the sets of all rational numbers, negative rational numbers, positive rational numbers, and nonnegative rational numbers
76, 77
N
the set of natural numbers
A C B
A is a subset of B
256
A g B A=B A =B
A is not a subset of B
257
A equals B
A UB
A union B
258 260
A n B
A intersect B
260
the difference of B minus A
260
the complement of A ordered pair
260
(xby) (XI,
ordered n-tuple
264
the Cartesian product of A and B
265
A'
X29 * * * , Xn)
A x B A, x A 2 x..
X An
the Cartesian product of Al, A 2
77
264
.
A,
265
0
the empty set
262
97(A)
the power set of A
264
List of Symbols Subject
Symbol
Meaning
Counting and Probability
N (A) P(A)
the number of elements in a set A the probability of a set A
299 299
P(n, r)
the number of r-permutations of a set of n elements
315
(n)
n choose r, the number of r-combinations of a set of n elements, the number of r-element subsets of a set of n elements
334
multiset of size r
349
the probability of A given B
376
f is a function from X to Y
390
the value of f at x
390
x-f|y
f sends x to y
390
f (A)
the image of A
402
f 1(C) ix
the inverse image of C the identity function on X
402 394
r [x,1, Xi2 ....
X iI
P(A IB) Functions
f: X f (x)
-+
Y
bx
b raised to the power x
411
expb (x)
b raised to the power x
411
1ogb (x)
logarithm with base b of x the inverse function of F
395 415
the composition of g and f
432
x is approximately equal to y big-0 of f of x
206 519
(f (x))
big-Omega of f of x
519
J(f(x))
big-Theta of f of x
519
xRy
x is related to y by R
572
F-1 f og Algorithm Efficiency
Relations
Page
x - y
O(f(x))
R
the inverse relation of R
578
m = n (mod d)
m is congruent to n modulo d
597
[a] x -< y
the equivalence class of a x is related to y by a partial order relation
<
599 635
Continuedonfirst page of back endpapers.
DISCRETE MATHEMATICS WITH APPLICATIONS THIRD EDITION
SUSANNI k S. EPP DePaul Uuniversity
TF-IcHIVIScON BROOKS/COLE
Australia * Canada * Mexico * Singapore * Spain
United Kingdom
*
United States
THCOlVISCON BROOKS/COLE
Cover Photo: The stones are discrete objects placed one on top of anotherlike a chain of careful reasoning. A person who decides to build such a tower aspires to the heights and enjoys playing with a challengingproblem. Choosing the stones takes both a scientific and an aesthetic sense. Getting them to balance requires patient effort and careful thought. And the tower that results is beautiful. A perfect metaphorfor discrete mathematics! Publisher: Bob Pirtle Assistant Editor: Stacy Green Project Manager, Editorial Production: Janet Hill Marketing Manager: Tom Ziolkowski Marketing Assistant: Jennifer Gee Print/Media Buyer: Doreen Suruki Production Service: Martha Emry ProductionServices
Text Designer: Kathleen Cunningham Art Editor: Martha Emry Illustrator: Techsetters, Inc. Cover Designer: JeanneCalabrese Cover Image: Getty Images Cover/Interior Printer: Quebecor World/Versailles Compositor: Techsetters, Inc.
Brooks/Cole-Thomson Learning 10 Davis Drive Belmont, CA 94002 USA
ALL RIGHTS RESERVED. No part of this work covered by the copyright hereon may be reproduced or used in any form or by any means-graphic, electronic, or mechanical, including but not limited to photocopying, recording, taping, Web distribution, information networks, or information storage and retrieval systems-without the written permission of the publisher.
Asia Thomson Learning 5 Shenton Way #01 -01 UIC Building Singapore 068808
Printed in the United States of America 1 2 3 4 5 6 7 06 05 04 03 02 For more information about our products, contact us at: Thomson Learning Academic Resource Center 1-800-423-0563 For permission to use material from this text, contact us by: Phone: 1-800-730-2214 Fax: 1-800-730-2215 Web: http://www.thomsonrights.com
COPYRIGHT 2004 Thomson Learning, Inc. All Rights Reserved. Thomson Learning WebTutorTM is a trademark of Thomson Learning, Inc. Library of Congress Control Number: 2003107333
Australia/New Zealand Thomson Learning 102 Dodds Street Southbank, Victoria 3006 Australia Canada Nelson 1120 Birchmount Road Toronto, Ontario MI K 5G4 Canada Europe/Middle East/Africa Thomson Learning High Holborn House 50/51 Bedford Row London WC I R 4LR United Kingdom
ISBN 0-534-35945-0 International Student Edition ISBN: 0-534-49096-4 (Not for sale in the United States)
,oo I',,
p ~'w
9~
Latin America Thomson Learning Seneca, 53 Colonia Polanco 11560 Mexico D.F. Mexico Spain/Portugal Paraninfo Calle Magallanes, 25 28015 Madrid, Spain
To Jayne and Ernest
CONTENTS Chapter 1 The Logic of Compound Statements
1
1.1 Logical Form and Logical Equivalence
1
Statements; Compound Statements; Truth Values; Evaluating the Truth of More General Compound Statements; Logical Equivalence; Tautologies and Contradictions; Summary of Logical Equivalences
of a Conditional Statement; The Contrapositive of a Conditional Statement; The Converse and Inverse of a Conditional Statement; Only If and the Biconditional; Necessary and Sufficient Conditions; Remarks
1.3 Valid and Invalid Arguments
29
Modus Ponens and Modus Tollens; Additional Valid Argument Forms: Rules of Inference; Fallacies; Contradictions and Valid Arguments; Summary of Rules of Inference
1.4 Application: Digital Logic Circuits
43
Black Boxes and Gates; The Input/Output for a Circuit; The Boolean Expression Corresponding to a Circuit; The Circuit Corresponding to a Boolean Expression; Finding a Circuit That Corresponds to a Given Input/Output Table; Simplifying Combinational Circuits; NAND and NOR Gates
1.5 Application: Number Systems and Circuits for Addition
57
Binary Representation of Numbers; Binary Addition and Subtraction; Circuits for Computer Addition; Two's Complements and the Computer Representation of Negative Integers; 8-Bit Representation of a Number; Computer Addition with Negative Integers; Hexadecimal Notation
Chapter 2 The Logic of Quantified Statements
75
2.1 Introduction to Predicates and Quantified Statements I
75
The Universal Quantifier: V; The Existential Quantifier: B; Formal Versus Informal Language; Universal Conditional Statements; Equivalent Forms of the Universal and Existential Statements; Implicit Quantification; Tarski's World
2.2 Introduction to Predicates and Quantified Statements II
88
Negations of Quantified Statements; Negations of Universal Conditional Statements; The Relation among V, 3, A, and v; Vacuous Truth of Universal Statements; Variants of Universal Conditional Statements; Necessary and Sufficient Conditions, Only If iv
Contents
2.3 Statements Containing Multiple Quantifiers
V
97
Translating from Informal to Formal Language; Ambiguous Language; Negations of Multiply-Quantified Statements; Order of Quantifiers; Formal Logical Notation; Prolog
2.4 Arguments with Quantified Statements
111
Universal Modus Ponens; Use of Universal Modus Ponens in a Proof; Universal Modus Tollens; Proving Validity of Arguments with Quantified Statements; Using Diagrams to Test for Validity; Creating Additional Forms of Argument; Remark on the Converse and Inverse Errors
Chapter 3 Elementary Number Theory and Methods of Proof
125
3.1 Direct Proof and Counterexample I: Introduction
126
Definitions; Proving Existential Statements; Disproving Universal Statements by Counterexample; Proving Universal Statements; Directions for Writing Proofs of Universal Statements; Common Mistakes; Getting Proofs Started; Showing That an Existential Statement Is False; Conjecture, Proof, and Disproof
3.2 Direct Proof and Counterexample II: Rational Numbers
141
More on Generalizing from the Generic Particular; Proving Properties of Rational Numbers; Deriving New Mathematics from Old
3.3 Direct Proof and Counterexample Ill: Divisibility
148
Proving Properties of Divisibility; Counterexamples and Divisibility; The Unique Factorization Theorem
3.4 Direct Proof and Counterexample IV,Division into Cases and the Quotient-Remainder Theorem 156 Discussion of the Quotient-Remainder Theorem and Examples; div and mod; Alternative Representations of Integers and Applications to Number Theory
3.5 Direct Proof and Counterexample V Floor and Ceiling
164
Definition and Basic Properties; The Floor of n/2
3.6 Indirect Argument: Contradiction and Contraposition
171
Proof by Contradiction; Argument by Contraposition; Relation between Proof by Contradiction and Proof by Contraposition; Proof as a Problem-Solving Tool
3.7 Two Classical Theorems
179
The Irrationality of vf2; The Infinitude of the Set of Prime Numbers; When to Use Indirect Proof; Open Questions in Number Theory
vi
Contents
186
3.8 Application: Algorithms
An Algorithmic Language; A Notation for Algorithms; Trace Tables; The Division Algorithm; The Euclidean Algorithm
Chapter 4 Sequences and Mathematical Induction 4.1 Sequences
199
199
Explicit Formulas for Sequences; Summation Notation; Product Notation; Factorial Notation; Properties of Summations and Products; Change of Variable; Sequences in Computer Programming; Application: Algorithm to Convert from Base 10 to Base 2 Using Repeated Division by 2
4.2 Mathematical Induction I
215
Principle of Mathematical Induction; Sum of the First n Integers; Sum of a Geometric Sequence
4.3 Mathematical Induction II
227
Comparison of Mathematical Induction and Inductive Reasoning; Proving Divisibility Properties; Proving Inequalities
4.4 Strong Mathematical Induction and the Well-Ordering Principle
235
The Principle of Strong Mathematical Induction; Binary Representation of Integers; The Well-Ordering Principle for the Integers
4.5 Application: Correctness of Algorithms
244
Assertions; Loop Invariants; Correctness of the Division Algorithm; Correctness of the Euclidean Algorithm
Chapter 5 Set Theory
255
5.1 Basic Definitions of Set Theory
255
Subsets; Set Equality; Operations on Sets; Venn Diagrams; The Empty Set; Partitions of Sets; Power Sets; Cartesian Products; An Algorithm to Check Whether One Set Is a Subset of Another (Optional)
5.2 Properties of Sets
269
Set Identities; Proving Set Identities; Proving That a Set Is the Empty Set
5.3 Disproofs, Algebraic Proofs, and Boolean Algebras
282
Disproving an Alleged Set Property; Problem-Solving Strategy; The Number of Subsets of a Set; "Algebraic" Proofs of Set Identities; Boolean Algebras
Contents
5.4 Russell's Paradox and the Halting Problem
vii
293
Description of Russell's Paradox; The Halting Problem
Chapter 6 Counting and Probability 6.1 Introduction
297
298
Definition of Sample Space and Event; Probability in the Equally Likely Case; Counting the Elements of Lists, Sublists, and One-Dimensional Arrays
6.2 Possibility Trees and the Multiplication Rule
306
Possibility Trees; The Multiplication Rule; When the Multiplication Rule Is Difficult or Impossible to Apply; Permutations; Permutations of Selected Elements
6.3 Counting Elements of Disjoint Sets: The Addition Rule
321
The Addition Rule; The Difference Rule; The Inclusion/Exclusion Rule
6.4 Counting Subsets of a Set: Combinations
334
r-Combinations; Ordered and Unordered Selections; Relation between Permutations and Combinations; Permutation of a Set with Repeated Elements; Some Advice about Counting
6.5 r-Combinations with Repetition Allowed
349
Multisets and I-low to Count Them; Which Formula to Use?
6.6 The Algebra of Combinations
356
Combinatorial Formulas; Pascal's Triangle; Algebraic and Combinatorial Proofs of Pascal's Formula
6.7 The Binomial Theorem
362
Statement of the Theorem; Algebraic and Combinatorial Proofs; Applications
6.8 Probability Axioms and Expected Value
370
Probability Axioms; Deriving Additional Probability Formulas; Expected Value
Definition of Function; Arrow Diagrams; Function Machines; Examples of Functions; Boolean Functions; Checking Whether a Function Is Well Defined
viii
Contents
7.2 One-to-One and Onto, Inverse Functions
402
One-to-One Functions; One-to-One Functions on Infinite Sets; Application: Hash Functions; Onto Functions; Onto Functions on Infinite Sets; Properties of Exponential and Logarithmic Functions; One-to-One Correspondences; Inverse Functions
420
7.3 Application: The Pigeonhole Principle
Statement and Discussion of the Principle; Applications; Decimal Expansions of Fractions; Generalized Pigeonhole Principle; Proof of the Pigeonhole Principle
7.4 Composition of Functions
431
Definition and Examples; Composition of One-to-One Functions; Composition of Onto Functions
7.5 Cardinality with Applications to Computability
443
Definition of Cardinal Equivalence; Countable Sets; The Search for Larger Infinities: The Cantor Diagonalization Process; Application: Cardinality and Computability
Chapter 8 Recursion
457
8.1 Recursively Defined Sequences
457
Definition of Recurrence Relation; Examples of Recursively Defined Sequences; The Number of Partitions of a Set Into r Subsets
8.2 Solving Recurrence Relations by Iteration
475
The Method of Iteration; Using Formulas to Simplify Solutions Obtained by Iteration; Checking the Correctness of a Formula by Mathematical Induction; Discovering That an Explicit Formula Is Incorrect
8.3 Second-Order Linear Homogenous Recurrence Relations 487 with Constant Coefficients Derivation of Technique for Solving These Relations; The Distinct-Roots Case; The Single-Root Case
8.4 General Recursive Definitions
499
Recursively Defined Sets; Proving Properties about Recursively Defined Sets; Recursive Definitions of Sum, Product, Union, and Intersection; Recursive Functions
Chapter 9 The Efficiency of Algorithms
510
9.1 Real-Valued Functions of a Real Variable and Their Graphs
510
Graph of a Function; Power Functions; The Floor Function; Graphing Functions Defined on Sets of Integers; Graph of a Multiple of a Function; Increasing and Decreasing Functions
Contents
9.2 0, Q, andO Notations
ix
518
Definition and General Properties of 0-, Q-, and 0-Notations; Orders of Power Functions; Orders of Polynomial Functions; Orders of Functions of Integer Variables; Extension to Functions Composed of Rational Power Functions
9.3 Application: Efficiency of Algorithms /
531
Time Efficiency of an Algorithm; Computing Orders of Simple Algorithms; The Sequential Search Algorithm; The Insertion Sort Algorithm
9.4 Exponential and Logarithmic Functions: Graphs and Orders 543 Graphs of Exponential and Logarithmic Functions; Application: Number of Bits Needed to Represent an Integer in Binary Notation; Application: Using Logarithms to Solve Recurrence Relations; Exponential and Logarithmic Orders
9.5 Application: Efficiency of Algorithms II
557
Divide-and-Conquer Algorithms; The Efficiency of the Binary Search Algorithm; Merge Sort; Tractable and Intractable Problems; A Final Remark on Algorithm Efficiency
Chapter 10 Relations
571
10.1 Relations on Sets
571
Definition of Binary Relation; Arrow Diagram of a Relation; Relations and Functions; The Inverse of a Relation; Directed Graph of a Relation; N-ary Relations and Relational Databases
10.2 Reflexivity, Symmetry, and Transitivity
584
Reflexive, Symmetric, and Transitive Properties; TheTransitive Closure of aRelation; Properties of Relations on Infinite Sets
10.3 Equivalence Relations
594
The Relation Induced by a Partition; Definition of an Equivalence Relation; Equivalence Classes of an Equivalence Relation
10.4 Modular Arithmetic with Applications to Cryptography
611
Properties of Congruence Modulo n; Modular Arithmetic; Finding an Inverse Modulo n; Euclid's Lemma; Fermat's Little Theorem and the Chinese Remainder Theorem; Why Does the RSA Cipher Work?
10.5 Partial Order Relations
632
Antisymmetry; Partial Order Relations; Lexicographic Order; Hasse Diagrams; Partially and Totally Ordered Sets; Topological Sorting; An Application; PERT and CPM
x
Contents
Chapter 11 Graphs and Trees
649
11.1 Graphs: An Introduction
649
Basic Terminology and Examples; Special Graphs; The Concept of Degree
11.2 Paths and Circuits
665
Definitions; Euler Circuits; Hamiltonian Circuits
11.3 Matrix Representations of Graphs
683
Matrices; Matrices and Directed Graphs; Matrices and (Undirected) Graphs; Matrices and Connected Components; Matrix Multiplication; Counting Walks of Length N
11.4 Isomorphisms of Graphs
697
Definition of Graph Isomorphism and Examples; Isomorphic Invariants; Graph Isomorphism for Simple Graphs
11.5 Trees
705
Definition and Examples of Trees; Characterizing Trees; Rooted Trees; Binary Trees
11.6 Spanning Trees
723
Definition of a Spanning Tree; Minimum Spanning Trees; Kruskal's Algorithm; Prim's Algorithm
Chapter 12 Regular Expressions and Finite-State Automata 12.1 Formal Languages and Regular Expressions
734
735
Definitions and Examples of Formal Languages and Regular Expressions; Practical Uses of Regular Expressions
12.2 Finite-State Automata
745
Definition of a Finite-State Automaton; The Language Accepted by an Automaton; The Eventual-State Function; Designing a Finite-State Automaton; Simulating a Finite-State Automaton Using Software; Finite-State Automata and Regular Expressions; Regular Languages
12.3 Simplifying Finite-State Automata
763
*-Equivalence of States; k-Equivalence of States; Finding the *-Equivalence Classes; The Quotient Automaton; Constructing the Quotient Automaton; Equivalent Automata
Appendix A Properties of the Real Numbers
A-i
Appendix B Solutions and Hints to Selected Exercises Index
1-1
A-4
PREFACE My purpose in writing this book was to provide a clear, accessible treatment of discrete mathematics for students majoring or minoring in computer science, mathematics, mathematics education, and engineering. The goal of the book is to lay the mathematical foundation for computer science courses such as data structures, algorithms, relational database theory, automata theory and formal languages, compiler design, and cryptography, and for mathematics courses such as linear and abstract algebra, combinatorics, probability, logic and set theory, and number theory. By combining discussion of theory and practice, I have tried to show that mathematics has engaging and important applications as well as being interesting and beautiful in its own right. A good background in algebra is the only prerequisite; the course may be taken by students either before or after a course in calculus. Previous editions of the book have been used successfully by students at hundreds of institutions in North and South America, Europe, the Middle East, Asia, and Australia. Recent curricular recommendations from the Institute for Electrical and Electronic Engineers Computer Society (IEEE-CS) and the Association for Computing Machinery (ACM) include discrete mathematics as the largest portion of "core knowledge" for computer science students and state that students should take at least a one-semester course in the subject as part of their first-year studies, with a two-semester course preferred when possible. This book includes all the topics recommended by those organizations and can be used effectively for either a one-semester or a two-semester course. At one time, most of the topics in discrete mathematics were taught only to upper-level undergraduates. Discovering how to present these topics in ways that can be understood by first- and second-year students was the major and most interesting challenge of writing this book. The presentation was developed over a long period of experimentation during which my students were in many ways my teachers. Their questions, comments, and written work showed me what concepts and techniques caused them difficulty, and their reaction to my exposition showed me what worked to build their understanding and to encourage their interest. Many of the changes in this edition have resulted from continuing interaction with students.
Themes of a Discrete Mathematics Course Discrete mathematics describes processes that consist of a sequence of individual steps. This contrasts with calculus, which describes processes that change in a continuous fashion. Whereas the ideas of calculus were fundamental to the science and technology of the industrial revolution, the ideas of discrete mathematics underlie the science and technology of the computer age. The main themes of a first course in discrete mathematics are logic and proof, induction and recursion, combinatorics and discrete probability, algorithms and their analysis, discrete structures, and applications and modeling. Logic and Proof Probably the most important goal of a first course in discrete mathematics is to help students develop the ability to think abstractly. This means learning to use logically valid forms of argument and avoid common logical errors, appreciating what it means to reason from definitions, knowing how to use both direct and indirect argument to derive new results from those already known to be true, and being able to work with symbolic representations as if they were concrete objects. xi
xii Preface
Induction and Recursion An exciting development of recent years has been the increased appreciation for the power and beauty of "recursive thinking." To think recursively means to address a problem by assuming that similar problems of a smaller nature have already been solved and figuring out how to put those solutions together to solve the larger problem. Such thinking is widely used in the analysis of algorithms, where recurrence relations that result from recursive thinking often give rise to formulas that are verified by mathematical induction. Combinatorics and Discrete Probability Combinatorics is the mathematics of counting and arranging objects, and probability is the study of laws concerning the measurement of random or chance events. Discrete probability focuses on situations involving discrete sets of objects, such as finding the likelihood of obtaining a certain number of heads when an unbiased coin is tossed a certain number of times. Skill in using combinatorics and probability is needed in almost every discipline where mathematics is applied, from economics to biology, to computer science, to chemistry and physics, to business management. Algorithms and Their Analysis The word algorithm was largely unknown in the middle of the twentieth century, yet now it is one of the first words encountered in the study of computer science. To solve a problem on a computer, it is necessary to find an algorithm or step-by-step sequence of instructions for the computer to follow. Designing an algorithm requires an understanding of the mathematics underlying the problem to be solved. Determining whether or not an algorithm is correct requires a sophisticated use of mathematical induction. Calculating the amount of time or memory space the algorithm will need in order to compare it to other algorithms that produce the same output requires knowledge of combinatorics, recurrence relations, functions, and 0-, Q-, and (t-notations. Discrete Structures Discrete mathematical structures are the abstract structures that describe, categorize, and reveal the underlying relationships among discrete mathematical objects. Those studied in this book are the sets of integers and rational numbers, general sets, Boolean algebras, functions, relations, graphs and trees, formal languages and regular expressions, and finite-state automata. Applications and Modeling Mathematical topics are best understood when they are seen in a variety of contexts and used to solve problems in a broad range of applied situations. One of the profound lessons of mathematics is that the same mathematical model can be used to solve problems in situations that appear superficially to be totally dissimilar. A goal of this book is to show students the extraordinary practical utility of some very abstract mathematical ideas.
Special Features of This Book Mathematical Reasoning The feature that most distinguishes this book from other discrete mathematics texts is that it teaches-explicitly but in a way that is accessible to first- and second-year college and university students-the unspoken logic and reasoning that underlie mathematical thought. For many years I taught an intensively interactive transition-to-abstract-mathematics course to mathematics and computer science majors. This experience showed me that while it is possible to teach the majority of students to understand and construct straightforward mathematical arguments, the obstacles to doing so cannot be passed over lightly. To be successful, a text for such a course must address students' difficulties with logic and language directly and at some length. It must also include enough concrete examples and exercises to enable students to develop the mental
Preface
xiii
models needed to conceptualize more abstract problems. The treatment of logic and proof in this book blends common sense and rigor in a way that explains the essentials, yet avoids overloading students with formal detail.
Spiral Approach to Concept Development A number of concepts in this book appear in increasingly more sophisticated forms in successive chapters to help students develop the ability to deal effectively with increasing levels of abstraction. For example, by the time students encounter the relatively advanced mathematics of Fermat's little theorem and the Chinese remainder theorem in the Section 10.4, they have been introduced to the logic of mathematical discourse in Chapters 1 and 2, learned the basic methods of proof and the concepts of mod and div in Chapter 3, studied partitions of the integers in Chapter 5, considered mod and div as functions in Chapter 7, and become familiar with equivalence relations in Sections 10.2 and 10.3. This approach builds in useful review and develops mathematical maturity in natural stages. Support for the Student Students at colleges and universities inevitably have to learn a great deal on their own. Though it is often frustrating, learning to learn through self-study is a crucial step toward eventual success in a professional career. This book has a number of features to facilitate students' transition to independent learning. Worked Examples The book contains over 500 worked examples, which are written using a problemsolution format and are keyed in type and in difficulty to the exercises. Many solutions for the proof problems are developed in two stages: first a discussion of how one might come to think of the proof or disproof and then a summary of the solution, which is enclosed in a box. This format allows students to read the problem and skip immediately to the summary, if they wish, only going back to the discussion if they have trouble understanding the summary. The format also saves time for students who are rereading the text in preparation for an examination. Exercises The book contains almost 2,500 exercises. The sets at the end of each section have been designed so that students with widely varying backgrounds and ability levels will find some exercises they can be sure to do successfully and also some exercises that will challenge them. Solutions for Exercises To provide adequate feedback for students between class sessions, Appendix B contains a large number of complete solutions to exercises. Students are strongly urged not to consult solutions until they have tried their best to answer the questions on their own. Once they have done so, however, comparing their answers with those given can lead to significantly improved understanding. In addition, many problems, including some of the most challenging, have partial solutions or hints so that students can determine whether they are on the right track and make adjustments if necessary. There are also plenty of exercises without solutions to help students learn to grapple with mathematical problems in a realistic environment. Figures and Tables Figures and tables are included in every case where it seemed that doing so would help readers to a better understanding. In most, a second color is used to add meaning. Reference Features Many students have written me to say that the book helped them succeed in their advanced courses. One even wrote that he had used the first edition so extensively that it had fallen apart and he actually went out and bought a copy of the second edition,
xiv
Preface
which he was continuing to use in a master's program. My rationale for screening statements of definitions and theorems, for putting titles on exercises, and for giving the meaning of symbols and a list of reference formulas in the endpapers is to make it easier for students to use this book for review in a current course and as a reference in later ones.
Support for the Instructor I have received a great deal of valuable feedback from instructors who have used previous editions of this book. Many aspects of the book have been improved through their suggestions. Exercises The large variety of exercises at all levels of difficulty allows instructors great freedom to tailor a course to the abilities of their students. Exercises with solutions in the back of the book have numbers in blue and those whose solutions are given in a separate Student Solutions Manual/Study Guide have numbers that are a multiple of three. There are exercises of every type that are represented in this book which have no answer in either location to enable instructors to assign whatever mixture they prefer of exercises with and without answers. The ample number of exercises of all kinds gives instructors a significant choice of problems to use for review assignments and exams. Instructors are invited to use the many exercises stated as questions rather than in "prove that" form to stimulate class discussion on the role of proof and counterexample in problem solving. Flexible Sections Most sections are divided into subsections so that an instructor who is pressed for time can choose to cover certain subsections only and either omit the rest or leave them for the students to study on their own. The division into subsections also makes it easier for instructors to break up sections if they wish to spend more then one day on them. Presentation of Proof Methods It is inevitable that the proofs and disproofs in this book will seem easy to instructors. Many students, however, find them difficult. In showing students how to discover and construct proof and disproofs, I have tried to describe the kinds of approaches that mathematicians use when confronting challenging problems in their own research. Instructor's Manual An instructor's manual is available to anyone teaching a course from this book. It contains suggestions about how to approach the material of each chapter, solutions for all exercises not fully solved in Appendix B, transparency masters, review sheets, ideas for projects and writing assignments, and additional exercises.
Highlights of the Third Edition The changes that have been made for this edition are based on suggestions from colleagues and other long-time users of the first and second editions, on continuing interactions with my students, and on developments within the evolving fields of computer science and mathematics. Improved Pedagogy * The number of exercises has been increased to almost 2,500. Approximately 980 new exercises have been added. * Exercises have been added for topics where students seemed to need additional practice, and they have been modified, as needed, to address student difficulties. * Additional full answers have been incorporated into Appendix B to give students more help for difficult topics.
Preface
xv
* The exposition has been reexamined throughout and revised where needed. * Careful work has been done to improve format and presentation. * Discussion of historical background and recent results has been expanded and the number of photographs of mathematicians and computer scientists whose contributions are discussed in the book has been increased. Logic * The treatment of quantification has been significantly expanded, with a new section entirely devoted to multiple quantifiers. * Exercises have been added using Tarski's World, an excellent pedagogical tool developed by Jon Barwise and John Etchemendy at Stanford University. * Applications related to Internet searching are now included. * Terms for various forms of argument have been simplified. Introduction to Proof * The directions for writing proofs have been expanded. * The descriptions of methods of proof have been made clearer. * Exercises have been revised and/or relocated to promote the development of student understanding. Induction and Recursion * The format for outlining proofs by mathematical induction has been improved. * The subsections in the section on sequences have been reorganized. * The sets of exercises for the sections on strong mathematical induction and the wellordering principle and on recursive definitions have been significantly expanded. Number Theory * A subsection on open problems in number theory has been incorporated, and the discussion of recent mathematical discoveries in number theory has been expanded. * A new section on modular arithmetic and cryptography has been added. It includes a discussion of RSA cryptography, Fermat's little theorem, and the Chinese remainder theorem. * The discussion of testing for primality has been moved to later in Chapter 3 to make clear its dependence on indirect argument. Set Theory * The properties of the empty set are now introduced in the first section of Chapter 5. * The second section of Chapter 5 is now entirely devoted to element proofs. * Algebraic proofs of set properties and the use of counterexamples to disprove set properties have been moved to the third section of Chapter 5. * The treatment of Boolean algebras has been expanded, and the relationship among logical equivalences, set properties, and Boolean algebras has been highlighted. Combinatorics and Discrete Probability * Exercises for the section on the binomial theorem has been significantly expanded. * Two new sections have been added on probability, including expected value, conditional probability and independence, and Bayes' theorem. * Combinatorial aspects of Internet protocol (IP) addresses are explained.
xvi
Preface
Functions * Exercises about one-to-one and onto functions have been refined and improved. * The set of exercises on cardinality with applications to computability has been significantly expanded. Efficiency of Algorithms * Sections 9.2 and 9.4 have been reworked to add 0- and Q-notations. * Sections 9.3 and 9.5 have been revised correspondingly, with a clearer explanation of the meaning of order for an algorithm. * The treatment of insertion sort and selection sort has been improved and expanded. Regular Expressions and Finite-State Automata * The previous disparate sections on formal languages and finite-state automata have been reassembled into a chapter of their own. * A new section on regular expressions has been added, as well as discussion of the relationship between regular expressions and finite-state automata.
Website A website has been developed for this book that contains information and materials for both students and instructors. It includes * descriptions and links to many sites on the Internet with accessible information about discrete mathematical topics, * links to applets that illustrate or provide practice in the concepts of discrete mathematics, * additional examples and exercises with solutions, * review guides for the chapters of the book. A special section for instructors contains * transparency masters and PowerPoint slides, * additional exercises for quizzes and exams.
Student Solutions Manual/Study Guide In writing this book, I strove to give sufficient help to students through the exposition in the text, the worked examples, and the exercise solutions, so that the book itself would provide all that a student would need to successfully master the material of the course. I believe that students who finish the study of this book with the ability to solve, on their own, all the exercises with full solutions in Appendix B will have developed an excellent command of the subject. Nonetheless, I have become aware that some students want the opportunity to obtain additional helpful materials. In response, I have developed a Student Solutions Manual/Study Guide, available separately from this book, which contains complete solutions to every exercise that is not completely answered in Appendix B and whose number is divisible by 3. The guide also includes alternative explanations for some of the concepts, and review questions for each chapter.
Preface
xvii
Organization This book may be used effectively for a one- or two-semester course. Each chapter contains core sections, sections covering optional mathematical material, and sections covering optional applications. Instructors have the flexibility to choose whatever mixture will best serve the needs of their students. The following table shows a division of the sections into categories.
Chapter
Core Sections
1
1.1-1.3
2
2.1-2.4
3 4
Sections Containing Optional Mathematical Material
The following tree diagram shows, approximately, how the chapters of this book depend on each other. Chapters on different branches of the tree are sufficiently independent that instructors need to make at most minor adjustments if they skip chapters but follow paths along branches of the tree.
*Instructors who wish to define a function as a binary relation can cover Section 10.1 before Section 7.1. tSection 10.3 is needed for Section 12.3 but not for Sections 12.1 and 12.2.
xviii
Preface
Acknowlegments I owe a debt of gratitude to many people at DePaul University for their support and encouragement throughout the years I worked on editions of this book. A number of my colleagues used early versions and previous editions and provided many excellent suggestions for improvement. For this, I am thankful to Louis Aquila, J. Marshall Ash, Allan Berele, Jeffrey Bergen, William Chin, Barbara Cortzen, Constantine Georgakis, Sigrun Goes, Jerry Goldman, Lawrence Gluck, Leonid Krop, Carolyn Narasimhan, Walter Pranger, Eric Rieders, Ayse Sahin, Yuen-Fat Wong, and, most especially, Jeanne LaDuke. The thousands of students to whom I have taught discrete mathematics have had a profound influence on the book's form. By sharing their thoughts and thought processes with me, they taught me how to teach them better. I am very grateful for their help. I owe the DePaul University administration, especially my dean, Michael Mezey, and my former dean, Richard Meister, a special word of thanks for considering the writing of this book a worthwhile scholarly endeavor. My thanks to the reviewers for their valuable suggestions for this edition of the book: Pablo Echeverria, Camden County College; William Gasarch, University of Maryland; Joseph Kolibal, University of Southern Mississippi; Benny Lo, International Technological University; George Luger, University of New Mexico; Norman Richert, University of Houston-Clear Lake; Peter Williams, California State University at San Bernardino; and Jay Zimmerman, Towson University. For their help with the first and second editions of the book, I am grateful to Itshak Borosh, Texas A & M University; Douglas M. Campbell, Brigham Young University; David G. Cantor, University of California at Los Angeles; C. Patrick Collier, University of Wisconsin-Oshkosh; Kevan H. Croteau, Francis Marion University; Irinel Drogan, University of Texas at Arlington; Henry A. Etlinger, Rochester Institute of Technology; Melvin J. Friske, Wisconsin Lutheran College; Ladnor Geissinger, University of North Carolina; Jerrold R. Griggs, University of South Carolina; Nancy Baxter Hastings, Dickinson College; Lillian Hupert, Loyola University Chicago; Leonard T. Malinowski, Finger Lakes Community College; John F. Morrison, Towson State Unviersity; Paul Pederson, University of Denver; George Peck, Arizona State University; Roxy Peck, California Polytechnic State University, San Luis Obispo; Dix Pettey, University of Missouri; Anthony Ralston, State University of New York at Buffalo; John Roberts, University of Louisville; and George Schultz, St. Petersburg Junior College, Clearwater. Special thanks are due John Carroll, San Diego State University; Dr. Joseph S. Fulda; and Porter G. Webster, University of Southern Mississippi for their unusual thoroughness and their encouragement. I have also benefitted greatly from the suggestions of the many instructors who have generously offered me their ideas for improvement based on their experiences with previous editions of the book. I am especially grateful to Jonathan Goldstine, Pennsylvania State University; David Hecker, St. Joseph's University; Tom Jenkyns, Brock University; Robert Messer, Albion College; Piotr Rudnicki, University of Alberta; Anwar Shiek, Din6 College; and Norton Starr, Amherst College. I also received excellent assistance from John Banks; Christopher Novak, DePaul University; and Ian Crewe, Ascension Collegiate School during the production of the book. I am grateful to many people at the Wadsworth and Brooks/Cole Publishing Companies, especially my editor, Robert Pirtle, for his ability to make good things happen as if by magic, my previous editors, Heather Bennett and Barbara Holland, for their encouragement and enthusiasm, and my production supervisor, Janet Hill, for her understanding and her willingness to let me play an active role in all aspects of the production process. I cannot imagine a better production editor than Martha Emry, whose high standards and attention to detail were an inspiration. The design by Kathleen Cunningham and composition by Techsetters, Inc. will be appreciated by all readers of this book.
Preface
xix
The older I get the more I realize the profound debt I owe my own mathematics teachers for shaping the way I perceive the subject. My first thanks must go to my husband, Helmut Epp, who, on a high school date (!), introduced me to the power and beauty of the field axioms and the view that mathematics is a subject with ideas as well as formulas and techniques. In my formal education, I am most grateful to Daniel Zelinsky and Ky Fan at Northwestern University and Izaak Wirszup, I. N. Herstein, and Irving Kaplansky at the University of Chicago, all of whom, in their own ways, helped lead me to appreciate the elegance, rigor, and excitement of mathematics. To my family, I owe thanks beyond measure. I am grateful to my mother, whose keen interest in the workings of the human intellect started me many years ago on the track that led ultimately to this book, and to my late father, whose devotion to the written word has been a constant source of inspiration. I thank my children and grandchildren for their affection and cheerful acceptance of the demands this book has placed on my life. And, most of all, I am grateful to my husband, who for many years has encouraged me with his faith in the value of this project and supported me with his love and his wise advice. Susanna Epp
1 CHAPTER 1
THE LOGIC OF COMPOUND THE STATEM ENTS
The first great treatises on logic were written by the Greek philosopher Aristotle. They were a collection of rules for deductive reasoning that were intended to serve as a basis for the study of every branch of knowledge. In the seventeenth century, the German philosopher and mathematician Gottfried Leibniz conceived the idea of using symbols to mechanize the process of deductive reasoning in much the same way that algebraic notation had mechanized the process of reasoning about numbers and their relationships. Leibniz's idea was realized in the nineteenth century by the English mathematicians George Boole and Augustus De Morgan, who founded the modem subject of symbolic logic. With research continuing to the present day, symbolic logic has provided, among other things, the theoretical basis for many areas of computer science such as digital logic circuit design (see Sections 1.4 and 1.5), relational database theory (see Section 10.1), automata theory and computability (see Chapter 12), and artificial intelligence (see Sections 2.3, 11.1, and 11.5). Aristotle (384 B.c.-322 B.C.)
A o1
Form and and Logical Logical Equivalence Logical Form Logical Equivalence
Logic Logic is a science of the necessary laws of thought, thought, without which no employment of the understanding understanding and the reason takes place. place.-- Immanuel Kant, 1785
The central concept of deductive logic is the concept of argument form. An argument is aa sequence of statements aimed at demonstrating the truth of of an assertion. The assertion at the end of the sequence is called the conclusion, conclusion, and and the preceding statements are called premises. To premises. To have confidence in the conclusion that you draw from an argument, you must be sure that the premises are acceptable on on their their own merits or follow from other statements that are known to be true. In logic, the form of an argument is distinguished from its content. Logical analysis won't help you deternfine determine the intrinsic merit of an argument's content, but it will help you analyze an argument's form to determine whether the truth of the conclusion follows necessarily from the truth of the the premises. For this this reason logic is sometimes defined as the science of of necessary inference or or the the science science of of reasoning. reasoning. the necessary inference for example. Although their content is very Consider the following two arguments, for if their different, their logical form is the same. same. Both arguments are are valid in the the sense that if premises are true, then their their conclusions must also be true. (In Section 1.3 you will will learn learn how to test whether an argument is valid.) 1
2 Chapter 1 The Logic of Compound Statements
Argument 1 If the program syntax is faulty or if program execution results in division by zero, then the computer will generate an error message. Therefore, if the computer does not generate an error message, then the program syntax is correct and program execution does not result in division by zero. Argument 2 If x is a real number such that x < -2 or x > 2, then x2 x2 4 4, then x It-2 and x 4 2.
>
4. Therefore, if
To illustrate the logical form of these arguments, we use letters of the alphabet (such as p, q, and r) to represent the component sentences and the expression "not p" to refer to the sentence "It is not the case that p." Then the common logicalform of both the arguments above is as follows: If p or q, then r. Therefore, if not r, then not p and not q.
Example 1.1.1 Identifying Logical Form Fill in the blanks below so that argument (b) has the same form as argument (a). Then represent the common form of the arguments using letters to stand for component sentences. a. If Jane is a math major or Jane is a computer science major, then Jane will take Math 150. Jane is a computer science major. Therefore, Jane will take Math 150. b. If logic is easy or (1) , then (2) I will study hard. Therefore, I will get an A in this course. Solution 1. I (will) study hard. 2. I will get an A in this course. Common form: If p or q, then r. qTherefore, r.
a
Statements Most of the definitions of formal logic have been developed so that they agree with the natural or intuitive logic used by people who have been educated to think clearly and use language carefully. The differences that exist between formal and intuitive logic are necessary to avoid ambiguity and obtain consistency. In any mathematical theory, new terms are defined by using those that have been previously defined. However, this process has to start somewhere. A few initial terms necessarily remain undefined. In logic, the words sentence, true, andfalse are the initial undefined terms. I. !.
.il
A statement (or proposition) is a sentence that is true or false but not both.
1.1
Logical Form and Logical Equivalence
3
For example, "Two plus two equals four" and "Two plus two equals five" are both statements, the first because it is true and the second because it is false. On the other hand, the truth or falsity of "He is a college student" depends on the reference for the pronoun he. For some values of he the sentence is true; for others it is false. If the sentence were preceded by other sentences that made the pronoun's reference clear, then the sentence would be a statement. Considered on its own, however, the sentence is neither true nor false, and so it is not a statement. We will discuss ways of transforming sentences of this form into statements in Section 2.1. Similarly, "x + y > 0" is not a statement because for some values of x and y the sentence is true, whereas for others it is false. For instance, if x = 1 and y = 2, the sentence is true; if x = -1 and y = 0, the sentence is false.
Compound Statements We now introduce three symbols that are used to build more complicated logical expressions out of simpler ones. The symbol - denotes not, A denotes and, and V denotes or. Given a statement p, the sentence "-p" is read "not p" or "It is not the case that p" and is called the negation of p. In some computer languages the symbol - is used in place of -. Given another statement q, the sentence "p A q" is read "p and q" and is called conjunction of p and q. The sentence "p V q" is read "p or q" and is called the
disjunction of p and q. In expressions that include the symbol - as well as A or v, the order of operations is that - is performed first. For instance, -p A q = (-p) A q. In logical expressions, as in ordinary algebraic expressions, the order of operations can be overridden through the use of parentheses. Thus -(p A q) represents the negation of the conjunction of p and q. In this, as in most treatments of logic, the symbols A and V are considered coequal in order of operation, and an expression such as p A q v r is considered ambiguous. This expression must be written as either (p A q) v r or p A (q v r) to have meaning. A variety of English words translate into logic as A, V, or -. For instance, the word but translates the same as and when it links two independent clauses, as in "Jim is tall but he is not heavy." Generally, the word but is used in place of and when the part of the sentence that follows is, in some way, unexpected. Another example involves the words neither-nor When Shakespeare wrote, "Neither a borrower nor a lender be," he meant, "Do not be a borrower and do not be a lender." So if p and q are statements, then p but q
means
p and q
neither p nor q
means
-p and -q.
Example 1.1.2 Translating from English to Symbols: But and Neither-Nor Write each of the following sentences symbolically, letting h = "It is hot" and s = "It is sunny." a. It is not hot but it is sunny. b. It is neither hot nor sunny. Solution a. The given sentence is equivalent to "It is not hot and it is sunny," which can be written symbolically as -h A S.
4
Chapter 1 The Logic of Compound Statements
b. To say it is neither hot nor sunny means that it is not hot and it is not sunny. Therefore, the given sentence can be written symbolically as -h A -s. U
Example 1.1.3 Searching on the Internet Advanced versions of many Internet search engines allow you to use some form of and, or and not to refine the search process. For instance, imagine that you want to find web pages about careers in mathematics or computer science but not finance or marketing. With a search engine that uses quotation marks to enclose exact phrases and expresses and as AND, or as OR, and not as NOT, you would write Careers AND (mathematics OR "computer science") AND NOT (finance OR marketing). The notation for inequalities involves and and or statements. For instance, if x, a, and b are particular real numbers, then